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
+19
View File
@@ -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");