add this fancy recent changes module
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
24
index.js
24
index.js
@@ -1,7 +1,29 @@
|
||||
import { load } from "cheerio";
|
||||
import { readFile, writeFile } from "fs";
|
||||
import process from "child_process";
|
||||
import stores from "./stores.json" assert { type: "json" };
|
||||
|
||||
function GetRecentChanges() {
|
||||
const res = process
|
||||
.execSync('git log -4 --pretty=format:"%ct %s"')
|
||||
.toString();
|
||||
return res.split("\n");
|
||||
}
|
||||
|
||||
function ChangeLog(logs) {
|
||||
let res = "\n";
|
||||
logs.forEach((l, i) => {
|
||||
const s = l.split(" ");
|
||||
const date = new Date(s[0] * 1000).toLocaleDateString("en-US", {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
});
|
||||
res = res + `<li>${date} - ${s.slice(1).join(" ")}</li>\n`;
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
function TableViewTemplate(rows) {
|
||||
let table = "<table>";
|
||||
rows.forEach((row, key) => {
|
||||
@@ -20,6 +42,7 @@ function TableRowTemplate({ rowNumber, name, address, city }) {
|
||||
}
|
||||
|
||||
readFile("./index.html", function (err, data) {
|
||||
const changeList = GetRecentChanges();
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
@@ -40,6 +63,7 @@ readFile("./index.html", function (err, data) {
|
||||
day: "numeric",
|
||||
})
|
||||
);
|
||||
$("#changesList").html(ChangeLog(changeList));
|
||||
const cssurl = $("link[type='text/css']").attr("href").split("?")[0];
|
||||
$("link[type='text/css']").attr("href", cssurl + "?" + new Date().getTime());
|
||||
writeFile("./index.html", $.html(), (err) => {
|
||||
|
Reference in New Issue
Block a user