fix: new posts were not rendering css properly
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"layout": "layouts/post.njk"
|
||||||
|
}
|
||||||
@@ -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");
|
||||||
|
|||||||
Reference in New Issue
Block a user