Skip to content

Commit 2936ff4

Browse files
committed
Use first title from the file content as HTML title
1 parent 7ac1d19 commit 2936ff4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/dev-server.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ app.use(async (req, res, next) => {
6262
const md = readFileSync(file, { encoding: "utf-8" });
6363
const bodyContent = await convertMarkdown(md);
6464
const templateFn = await getTemplate();
65-
const html = templateFn({ title: req.url, bodyContent });
65+
// get title as first line in the md file which starts with hashes, which indicates it is a title of some kind
66+
const title = md.match(/^##* (.+)$/m)?.[1] || "";
67+
const html = templateFn({ title, bodyContent });
6668
res.send(html);
6769
} else if (file) {
6870
res.sendFile(file);

0 commit comments

Comments
 (0)