1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-11-12 21:30:10 +00:00

Compare commits

..

No commits in common. "3294b27029088ea126d34b9a52b09f255140ff29" and "7e5bfd4b10ae668d235883c48bf2246ba442bd0d" have entirely different histories.

4 changed files with 19 additions and 81 deletions

View File

@ -15,8 +15,8 @@
window.linkResetEnabled = {{ .linkResetEnabled }};
window.language = "{{ .langName }}";
</script>
<title>Admin - jfa-go</title>
{{ template "header.html" . }}
<title>Admin - jfa-go</title>
</head>
<body class="max-w-full overflow-x-hidden section">
<div id="modal-login" class="modal">

38
package-lock.json generated
View File

@ -13,15 +13,12 @@
"@types/node": "^15.0.1",
"a17t": "^0.10.1",
"browserslist": "^4.16.6",
"cheerio": "^1.0.0-rc.10",
"esbuild": "^0.8.57",
"fs-cheerio": "^3.0.0",
"inline-source": "^7.2.0",
"jsdom": "^19.0.0",
"lodash": "^4.17.21",
"mjml": "^4.8.0",
"nightwind": "github:yonson2/nightwind",
"perl-regex": "^1.0.4",
"remixicon": "^2.5.0",
"remove-markdown": "^0.3.0",
"typescript": "^4.0.3",
@ -2061,14 +2058,6 @@
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=",
"dev": true
},
"node_modules/fs-cheerio": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fs-cheerio/-/fs-cheerio-3.0.0.tgz",
"integrity": "sha512-pOlWiRDIX8bc2aGVmAX2e3dH514IUEmXoM9WOZnraYEzC9uXelSCJdKo0s4+7US0rYgNTHLw4765J5ZWsKTzqA==",
"dependencies": {
"cheerio": "^1.0.0-rc.2"
}
},
"node_modules/fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -4495,17 +4484,6 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"node_modules/perl-regex": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/perl-regex/-/perl-regex-1.0.4.tgz",
"integrity": "sha1-cQvC7fh23qd+TQQ951CsdAv0Z9I=",
"dependencies": {
"sprintf-js": "^1.0.3"
},
"engines": {
"node": ">=4.5.0"
}
},
"node_modules/picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",
@ -8619,14 +8597,6 @@
"integrity": "sha1-g8YK/Fi5xWmXAH7Rp2izqzA6RP4=",
"dev": true
},
"fs-cheerio": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/fs-cheerio/-/fs-cheerio-3.0.0.tgz",
"integrity": "sha512-pOlWiRDIX8bc2aGVmAX2e3dH514IUEmXoM9WOZnraYEzC9uXelSCJdKo0s4+7US0rYgNTHLw4765J5ZWsKTzqA==",
"requires": {
"cheerio": "^1.0.0-rc.2"
}
},
"fs.realpath": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
@ -10552,14 +10522,6 @@
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
"integrity": "sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns="
},
"perl-regex": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/perl-regex/-/perl-regex-1.0.4.tgz",
"integrity": "sha1-cQvC7fh23qd+TQQ951CsdAv0Z9I=",
"requires": {
"sprintf-js": "^1.0.3"
}
},
"picocolors": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz",

View File

@ -21,15 +21,12 @@
"@types/node": "^15.0.1",
"a17t": "^0.10.1",
"browserslist": "^4.16.6",
"cheerio": "^1.0.0-rc.10",
"esbuild": "^0.8.57",
"fs-cheerio": "^3.0.0",
"inline-source": "^7.2.0",
"jsdom": "^19.0.0",
"lodash": "^4.17.21",
"mjml": "^4.8.0",
"nightwind": "github:yonson2/nightwind",
"perl-regex": "^1.0.4",
"remixicon": "^2.5.0",
"remove-markdown": "^0.3.0",
"typescript": "^4.0.3",

View File

@ -1,69 +1,48 @@
let parser = require("cheerio");
let parser = require("jsdom");
let fs = require("fs");
let path = require("path");
let pre = require("perl-regex");
const hasDark = (item) => {
let list = item.attr("class").split(/\s+/);
for (let i = 0; i < list.length; i++) {
if (list[i].substring(0,5) == "dark:") {
for (let i = 0; i < item.classList.length; i++) {
if (item.classList[i].substring(0,5) == "dark:") {
return true;
}
}
return false;
};
if (typeof String.prototype.replaceAll === "undefined") {
String.prototype.replaceAll = function(match, replace) {
return this.replace(new RegExp(match, 'g'), () => replace);
}
}
function fixHTML(infile, outfile) {
let f = fs.readFileSync(infile).toString();
// Find all go template strings ({{ example }})
let templateStrings = pre.exec(f, "(?s){{(?:(?!{{).)*?}}", "gi");
for (let i = 0; i < templateStrings.length; i++) {
let s = templateStrings[i].replace(/\\/g, '');
// let s = templateStrings[i];
f = f.replaceAll(s, "<!--" + s.slice(3).slice(0, -3) + "-->");
}
let doc = new parser.load(f);
const fixHTML = (infile, outfile) => {
console.log(infile, outfile)
let doc = new parser.JSDOM(fs.readFileSync(infile));
for (let item of ["badge", "chip", "shield", "input", "table", "button", "portal", "select", "aside", "card", "field", "textarea"]) {
let items = doc("."+item);
items.each((i, elem) => {
let items = doc.window.document.body.querySelectorAll("."+item);
for (let i = 0; i < items.length; i++) {
let hasColor = false;
for (let color of ["neutral", "positive", "urge", "warning", "info", "critical"]) {
//console.log(color);
if (doc(elem).hasClass("~"+color)) {
if (items[i].classList.contains("~"+color)) {
hasColor = true;
// console.log("adding to", items[i].classList)
if (!hasDark(doc(elem))) {
doc(elem).addClass("dark:~d_"+color);
if (!hasDark(items[i])) {
items[i].classList.add("dark:~d_"+color);
}
break;
}
}
if (!hasColor) {
if (!hasDark(doc(elem))) {
if (!hasDark(items[i])) {
// card without ~neutral look different than with.
if (item != "card") doc(elem).addClass("~neutral");
doc(elem).addClass("dark:~d_neutral");
if (item != "card") items[i].classList.add("~neutral");
items[i].classList.add("dark:~d_neutral");
}
}
if (!doc(elem).hasClass("@low") && !doc(elem).hasClass("@high")) {
doc(elem).addClass("@low");
if (!items[i].classList.contains("@low") && !items[i].classList.contains("@high")) {
items[i].classList.add("@low");
}
});
}
}
let out = doc.html();
// let out = f
for (let i = 0; i < templateStrings.length; i++) {
let s = templateStrings[i].replace(/\\/g, '');
out = out.replaceAll("<!--" + s.slice(3).slice(0, -3) + "-->", s);
}
fs.writeFileSync(outfile, out);
console.log(infile, outfile);
fs.writeFileSync(outfile, doc.window.document.documentElement.outerHTML);
};
let inpath = process.argv[process.argv.length-2];