From 31f93f559d301a6d35a1fc3e83807a347f713403 Mon Sep 17 00:00:00 2001 From: venus Date: Mon, 14 Sep 2026 23:25:16 -0500 Subject: [PATCH] fix: new posts were not rendering css properly --- entrypoint.sh | 5 +++++ server.js | 19 +++++++++++++++++++ src/posts/posts.json | 3 +++ test/ingestion-api.test.js | 1 + 4 files changed, 28 insertions(+) create mode 100644 src/posts/posts.json diff --git a/entrypoint.sh b/entrypoint.sh index f360da8..188b8cd 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -5,6 +5,11 @@ if [ "$#" -gt 0 ]; then exec "$@" fi +# Ensure posts directory data file exists for layout inheritance +if [ ! -f src/posts/posts.json ]; then + echo '{"layout": "layouts/post.njk"}' > src/posts/posts.json +fi + # Build static site from mounted or packaged markdown posts echo "[blog-engine] Compiling static site with Eleventy..." npm run build || exit 1 diff --git a/server.js b/server.js index 2c73133..1fdc76b 100644 --- a/server.js +++ b/server.js @@ -42,6 +42,12 @@ export function normalizeObsidianMarkdown(content) { normalized = normalized.replace(/^(---\r?\n)/, `$1date: ${createdMatch[1].trim()}\n`); } + // Bridge layout -> layouts/post.njk so Obsidian notes render with the blog theme and CSS + const hasLayout = /^layout:\s*.+$/m.test(normalized); + if (!hasLayout) { + normalized = normalized.replace(/^(---\r?\n)/, "$1layout: layouts/post.njk\n"); + } + // 1. Convert internal attachments: ![[image.png|alt]] or ![[image.png]] normalized = normalized.replace(/!\[\[([^|\]]+)(?:\|([^\]]+))?\]\]/g, (match, filename, alt) => { const cleanFilename = path.basename(filename.trim()); @@ -130,6 +136,19 @@ export function createServer(customSiteDir, customPostsDir, customAssetsDir) { const assetsDir = path.resolve(customAssetsDir || path.join(process.cwd(), "src/assets/images/posts")); const isCustomEnv = Boolean(customSiteDir || customPostsDir || customAssetsDir); + // Ensure default directory data file exists for layout inheritance + try { + if (!fs.existsSync(postsDir)) { + fs.mkdirSync(postsDir, { recursive: true }); + } + const postsJsonPath = path.join(postsDir, "posts.json"); + if (!fs.existsSync(postsJsonPath)) { + fs.writeFileSync(postsJsonPath, JSON.stringify({ layout: "layouts/post.njk" }, null, 2)); + } + } catch (err) { + console.warn("[Server] Could not initialize posts.json directory data file:", err.message); + } + return http.createServer(async (req, res) => { // Standard security headers res.setHeader("X-Content-Type-Options", "nosniff"); diff --git a/src/posts/posts.json b/src/posts/posts.json new file mode 100644 index 0000000..d0428c4 --- /dev/null +++ b/src/posts/posts.json @@ -0,0 +1,3 @@ +{ + "layout": "layouts/post.njk" +} diff --git a/test/ingestion-api.test.js b/test/ingestion-api.test.js index 554d578..b8608f8 100644 --- a/test/ingestion-api.test.js +++ b/test/ingestion-api.test.js @@ -165,6 +165,7 @@ Here is an image: ![[camera-board.png]] assert.ok(fs.existsSync(writtenPath), "Post markdown file must be written to disk"); const writtenContent = fs.readFileSync(writtenPath, "utf-8"); + assert.match(writtenContent, /^layout:\s*layouts\/post\.njk$/m, "Layout must be injected into frontmatter when missing"); assert.match(writtenContent, /\[Other Post\]\(\/posts\/other-post\/\)/, "Wikilink with alias must be translated"); assert.match(writtenContent, /\[simple-link\]\(\/posts\/simple-link\/\)/, "Simple wikilink must be translated"); assert.match(writtenContent, /!\[camera-board\.png\]\(\/assets\/images\/posts\/camera-board\.png\)/, "Attachment wikilink must be translated");