fix: new posts were not rendering css properly

This commit is contained in:
venus
2026-09-14 23:25:16 -05:00
parent 6f3bf4bf89
commit 31f93f559d
4 changed files with 28 additions and 0 deletions
+5
View File
@@ -5,6 +5,11 @@ if [ "$#" -gt 0 ]; then
exec "$@" exec "$@"
fi 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 # Build static site from mounted or packaged markdown posts
echo "[blog-engine] Compiling static site with Eleventy..." echo "[blog-engine] Compiling static site with Eleventy..."
npm run build || exit 1 npm run build || exit 1
+19
View File
@@ -42,6 +42,12 @@ export function normalizeObsidianMarkdown(content) {
normalized = normalized.replace(/^(---\r?\n)/, `$1date: ${createdMatch[1].trim()}\n`); 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]] // 1. Convert internal attachments: ![[image.png|alt]] or ![[image.png]]
normalized = normalized.replace(/!\[\[([^|\]]+)(?:\|([^\]]+))?\]\]/g, (match, filename, alt) => { normalized = normalized.replace(/!\[\[([^|\]]+)(?:\|([^\]]+))?\]\]/g, (match, filename, alt) => {
const cleanFilename = path.basename(filename.trim()); 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 assetsDir = path.resolve(customAssetsDir || path.join(process.cwd(), "src/assets/images/posts"));
const isCustomEnv = Boolean(customSiteDir || customPostsDir || customAssetsDir); 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) => { return http.createServer(async (req, res) => {
// Standard security headers // Standard security headers
res.setHeader("X-Content-Type-Options", "nosniff"); res.setHeader("X-Content-Type-Options", "nosniff");
+3
View File
@@ -0,0 +1,3 @@
{
"layout": "layouts/post.njk"
}
+1
View File
@@ -165,6 +165,7 @@ Here is an image: ![[camera-board.png]]
assert.ok(fs.existsSync(writtenPath), "Post markdown file must be written to disk"); assert.ok(fs.existsSync(writtenPath), "Post markdown file must be written to disk");
const writtenContent = fs.readFileSync(writtenPath, "utf-8"); 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, /\[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, /\[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"); assert.match(writtenContent, /!\[camera-board\.png\]\(\/assets\/images\/posts\/camera-board\.png\)/, "Attachment wikilink must be translated");