diff options
Diffstat (limited to 'scripts')
| -rw-r--r-- | scripts/build.ts | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/scripts/build.ts b/scripts/build.ts index 76d88a0..4908532 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -14,10 +14,22 @@ const root = path.join(import.meta.dirname, ".."); const viewsDir = path.join(root, "views"); const eta = new Eta({ views: viewsDir }); -const names = fs - .readdirSync(viewsDir) - .filter((name) => name.endsWith(".eta")) - .sort(); +// Names are the templates' paths under views/, e.g. "layouts/base.eta", which +// is how the templates address each other (see src/worker.ts). +function templateNames(dir: string, prefix = ""): string[] { + const names: string[] = []; + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + const name = prefix + entry.name; + if (entry.isDirectory()) { + names.push(...templateNames(path.join(dir, entry.name), `${name}/`)); + } else if (entry.name.endsWith(".eta")) { + names.push(name); + } + } + return names.sort(); +} + +const names = templateNames(viewsDir); let out = `// @ts-nocheck // Generated by scripts/build.ts -- do not edit. |
