mirror of https://github.com/jpanther/congo.git
feat: make the script offline
parent
a19dc47b6a
commit
7475198f86
|
@ -1,14 +1,17 @@
|
|||
{
|
||||
"name": "hugo-congo-theme",
|
||||
"version": "2.7.6",
|
||||
"version": "2.8.0",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "hugo-congo-theme",
|
||||
"version": "2.7.6",
|
||||
"version": "2.8.0",
|
||||
"hasInstallScript": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/typography": "^0.5.10",
|
||||
"chart.js": "^4.4.1",
|
||||
|
@ -46,6 +49,15 @@
|
|||
"integrity": "sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@fortawesome/fontawesome-free": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.5.1.tgz",
|
||||
"integrity": "sha512-CNy5vSwN3fsUStPRLX7fUYojyuzoEMSXPl7zSLJ8TgtRfjv24LOnOWKT2zYwaHZCJGkdyRnTmstR0P+Ah503Gw==",
|
||||
"hasInstallScript": true,
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@isaacs/cliui": {
|
||||
"version": "8.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||
|
@ -3621,6 +3633,11 @@
|
|||
"integrity": "sha512-Tbsj02wXCbqGmzdnXNk0SOF19ChhRU70BsroIi4Pm6Ehp56in6vch94mfbdQ17DozxkL3BAVjbZ4Qc1a0HFRAg==",
|
||||
"dev": true
|
||||
},
|
||||
"@fortawesome/fontawesome-free": {
|
||||
"version": "6.5.1",
|
||||
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-6.5.1.tgz",
|
||||
"integrity": "sha512-CNy5vSwN3fsUStPRLX7fUYojyuzoEMSXPl7zSLJ8TgtRfjv24LOnOWKT2zYwaHZCJGkdyRnTmstR0P+Ah503Gw=="
|
||||
},
|
||||
"@isaacs/cliui": {
|
||||
"version": "8.0.2",
|
||||
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
|
||||
|
|
|
@ -78,5 +78,8 @@
|
|||
"from": "node_modules/quicklink/dist/quicklink.umd.js",
|
||||
"to": "assets/lib/quicklink/quicklink.umd.js"
|
||||
}
|
||||
]
|
||||
],
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": "^6.5.1"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
const jsdom = require("jsdom");
|
||||
const fs = require("fs");
|
||||
|
||||
const SVG_FILE_DIR = 'node_modules/@fortawesome/fontawesome-free/svgs/brands';
|
||||
const DOC_DIR = "./exampleSite/content/samples/icons";
|
||||
const FONTAWESOME_VERSION = "v6.5.1";
|
||||
const DEFAULT_TABLE_DELIMITER = "| -------------------- | --------------------------------- |";
|
||||
|
||||
/**
|
||||
|
@ -12,8 +12,7 @@ const DEFAULT_TABLE_DELIMITER = "| -------------------- | ----------------------
|
|||
*/
|
||||
const add_icon_to_congo = async (icon_name) => {
|
||||
try {
|
||||
const icon_url = create_icon_url(icon_name, FONTAWESOME_VERSION);
|
||||
const file = await get_file(icon_url);
|
||||
const file = await get_file(icon_name);
|
||||
const final_svg = modify_svg_string(file);
|
||||
const icon_download_path = create_icon_download_path(icon_name);
|
||||
save_file(icon_download_path, final_svg);
|
||||
|
@ -31,26 +30,16 @@ const modify_svg_string = (svg_string) => {
|
|||
svg.querySelector("path").setAttribute("fill", "currentColor");
|
||||
return svg.outerHTML;
|
||||
} catch (e) {
|
||||
throw new Error("Invalid SVG file");
|
||||
throw new Error("Invalid SVG file" + e);
|
||||
}
|
||||
};
|
||||
|
||||
const create_icon_url = (icon_name, fontawesome_version) => {
|
||||
return `https://site-assets.fontawesome.com/releases/${fontawesome_version}/svgs/brands/${icon_name}.svg`;
|
||||
};
|
||||
|
||||
const create_icon_download_path = (icon_name) => {
|
||||
return `./assets/icons/${icon_name}.svg`;
|
||||
};
|
||||
|
||||
const get_file = async (url) => {
|
||||
console.log("Getting file at " + url + "...");
|
||||
const response = await fetch(url);
|
||||
if (response.status >= 400) {
|
||||
throw new Error("Could not download icon / icon not found");
|
||||
}
|
||||
console.log("File retrieved!");
|
||||
return response.text();
|
||||
return fs.readFileSync(SVG_FILE_DIR + `/${url}.svg`, "utf8");
|
||||
};
|
||||
|
||||
const save_file = (file_path, file) => {
|
||||
|
@ -84,12 +73,16 @@ const add_documentation = async (icon_name) => {
|
|||
const process_file = (file_contents, icon_name) => {
|
||||
const [headers, table] = file_contents.split(DEFAULT_TABLE_DELIMITER);
|
||||
const table_rows = table.split("\n").map((x) => x.trim()).filter((row) => row !== "");
|
||||
table_rows.push(table_rows[0].replace("amazon", icon_name));
|
||||
table_rows.push(create_table_row(icon_name));
|
||||
table_rows.sort();
|
||||
const new_table = table_rows.join("\n");
|
||||
return `${headers.trimEnd()}\n${DEFAULT_TABLE_DELIMITER}\n${new_table}\n`;
|
||||
};
|
||||
|
||||
const create_table_row = (name) => {
|
||||
return `| ${name} | {{< icon ${name} >}} |`
|
||||
}
|
||||
|
||||
const get_md_docs = () => {
|
||||
return fs.readdirSync(DOC_DIR).filter((file) => file.endsWith(".md"));
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue