« get me outta code hell

copy favicon from media directory if present - hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
author(quasar) nebula <qznebula@protonmail.com>2022-05-19 18:58:20 -0300
committer(quasar) nebula <qznebula@protonmail.com>2022-05-19 18:58:20 -0300
commita7751244b674083a6dd09cfb523df8ffe1a81a26 (patch)
tree452a471a0d560aa5f128862ee1cd0543f6a5328a /src
parent474704fac9104cf3ec5425cb84dad7203555dd96 (diff)
copy favicon from media directory if present
Diffstat (limited to 'src')
-rwxr-xr-xsrc/upd8.js27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/upd8.js b/src/upd8.js
index 406e0b3d..f60c57a9 100755
--- a/src/upd8.js
+++ b/src/upd8.js
@@ -45,9 +45,10 @@ import fixWS from 'fix-whitespace';
 import he from 'he';
 
 import {
-    access,
+    copyFile,
     mkdir,
     readFile,
+    stat,
     symlink,
     writeFile,
     unlink,
@@ -197,6 +198,9 @@ const STATIC_DIRECTORY = 'static';
 // This exists adjacent to index.html for any page with oEmbed metadata.
 const OEMBED_JSON_FILE = 'oembed.json';
 
+// Automatically copied (if present) from media directory to site root.
+const FAVICON_FILE = 'favicon.ico';
+
 function inspect(value) {
     return nodeInspect(value, {colors: ENABLE_COLOR});
 }
@@ -1190,6 +1194,26 @@ writePage.paths = (baseDirectory, fullKey, directory = '', {
     };
 };
 
+async function writeFavicon() {
+    try {
+        await stat(path.join(mediaPath, FAVICON_FILE));
+    } catch (error) {
+        return;
+    }
+
+    try {
+        await copyFile(
+            path.join(mediaPath, FAVICON_FILE),
+            path.join(outputPath, FAVICON_FILE)
+        );
+    } catch (error) {
+        logWarn`Failed to copy favicon! ${error.message}`;
+        return;
+    }
+
+    logInfo`Copied favicon to site root.`;
+}
+
 function writeSymlinks() {
     return progressPromiseAll('Writing site symlinks.', [
         link(path.join(__dirname, UTILITY_DIRECTORY), 'shared.utilityRoot'),
@@ -1774,6 +1798,7 @@ async function main() {
 
     logInfo`Writing site pages: ${writeAll ? 'all' : Object.keys(writeFlags).join(', ')}`;
 
+    await writeFavicon();
     await writeSymlinks();
     await writeSharedFilesAndPages({language: finalDefaultLanguage, wikiData});