addSummary: use opening and closing tags to select page summary. So summary doesn't have to be first thing in file.

This commit is contained in:
Hans Fast 2026-04-01 11:02:51 +02:00
parent be6ea7b34e
commit 860380d46a
2 changed files with 6 additions and 2 deletions

View File

@ -3,10 +3,12 @@ title: My Public File
cuid: 26e4-a1
---
<!--summary-start-->
This is a public file with some nice text.
It's easy to write in this file.
<!--summary-above-->
<!--summary-end-->
I can write more things after the comment if I want.

View File

@ -1,6 +1,8 @@
//looks for an html comment pattern, and, if found,
//adds the text before it to the doc under the key `summary`.
const reg = /^(?<summary>.+)?<!--summary-above-->/s
const reg = /.*<!--summary-start-->(?<summary>.+)?<!--summary-end-->/s
//use a custom element instead.
// const reg = /<doc-summary>(?<summary>.+)?<\/doc-summary>/s
export default (doc) => {
const result = reg.exec(doc._body);
if (result) {