From c096067687c4067e9f2f599da94510a4fca09e6a Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 15 Jul 2022 11:51:54 +0200 Subject: [PATCH] Another iterations --- .gitignore | 3 ++- scripts/build_website.sh | 4 +++- scripts/generate_fs_list.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 scripts/generate_fs_list.js diff --git a/.gitignore b/.gitignore index d5af006a..aad3401e 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,5 @@ generated *.test.js *.js.map .vscode -website \ No newline at end of file +website +data.db \ No newline at end of file diff --git a/scripts/build_website.sh b/scripts/build_website.sh index ec06717f..a2bcd024 100755 --- a/scripts/build_website.sh +++ b/scripts/build_website.sh @@ -4,4 +4,6 @@ npm run clean-build rm -rf website mkdir -p website/fs cp -r packages/web/dist/* website/ -cp -r docs/* website/fs/ \ No newline at end of file +cp _redirects website/ +cp -r docs/* website/fs/ +node scripts/generate_fs_list.js > website/fs/index.json \ No newline at end of file diff --git a/scripts/generate_fs_list.js b/scripts/generate_fs_list.js new file mode 100644 index 00000000..805c31f9 --- /dev/null +++ b/scripts/generate_fs_list.js @@ -0,0 +1,29 @@ +const { resolve } = require("path"); +const { readdir } = require("fs").promises; + +async function getFiles(dir) { + const dirents = await readdir(dir, { withFileTypes: true }); + const files = await Promise.all( + dirents.map((dirent) => { + const res = resolve(dir, dirent.name); + return dirent.isDirectory() ? getFiles(res) : res; + }) + ); + return Array.prototype.concat(...files); +} + +const rootDir = resolve("docs"); + +getFiles(rootDir).then((files) => { + files = files + .map((file) => ({ + name: file.substring(rootDir.length + 1).replace(/\.md$/, ""), + lastModified: 0, + perm: "ro", + })) + .filter( + (pageMeta) => + !pageMeta.name.startsWith("_") && !pageMeta.name.startsWith(".") + ); + console.log(JSON.stringify(files, null, 2)); +});