Update generate-index.mjs

This commit is contained in:
Mark Randall Havens △ The Empathic Technologist ⟁ Doctor Who 42 2025-11-08 19:08:52 -06:00 committed by GitHub
parent 80efd46e42
commit 02144a9afe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -75,6 +75,8 @@ async function collectFiles(relBase = "", flat = []) {
title = parseTitle(raw, ext) || e.name.replace(new RegExp(`\\${ext}$`), "").trim(); title = parseTitle(raw, ext) || e.name.replace(new RegExp(`\\${ext}$`), "").trim();
} }
// Use birthtimeMs (creation time), fallback to mtimeMs
const ctime = st.birthtimeMs || st.mtimeMs;
const mtime = dateFromName(e.name) ?? st.mtimeMs; const mtime = dateFromName(e.name) ?? st.mtimeMs;
const baseName = e.name.slice(0, e.name.lastIndexOf('.')).toLowerCase(); const baseName = e.name.slice(0, e.name.lastIndexOf('.')).toLowerCase();
@ -84,7 +86,8 @@ async function collectFiles(relBase = "", flat = []) {
title, title,
path: rel, path: rel,
ext, ext,
mtime, ctime, // Creation timestamp
mtime, // For sorting
excerpt: extractExcerpt(raw, ext), excerpt: extractExcerpt(raw, ext),
tags: extractTags(raw, ext, pdfData), tags: extractTags(raw, ext, pdfData),
isIndex: baseName === "index", isIndex: baseName === "index",
@ -97,7 +100,7 @@ async function collectFiles(relBase = "", flat = []) {
(async () => { (async () => {
try { try {
const flat = await collectFiles(); const flat = await collectFiles();
// Sections = dirs with non-index files // Only include sections with non-index files in dropdown
const sections = [...new Set(flat.filter(f => !f.isIndex).map(f => f.path.split("/")[0]))].sort(); const sections = [...new Set(flat.filter(f => !f.isIndex).map(f => f.path.split("/")[0]))].sort();
const allTags = [...new Set(flat.flatMap(f => f.tags))].sort(); const allTags = [...new Set(flat.flatMap(f => f.tags))].sort();
await fs.writeFile(OUT, JSON.stringify({ flat, sections, tags: allTags }, null, 2)); await fs.writeFile(OUT, JSON.stringify({ flat, sections, tags: allTags }, null, 2));