fix: new posts were not rendering css properly
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user