kiln: page: extract title from first content line v1 PROPOSED

oliverpool: 1
 page: extract title from first content line

 1 files changed, 15 insertions(+), 0 deletions(-)
As alternative, one could trigger the fallback only if no frontmatter is present.

So “# some title” would be a frontmatter shorthand for
title: some title




Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~adnano/kiln-devel/patches/46488/mbox | git am -3
Learn more about email & git

[PATCH kiln] page: extract title from first content line Export this patch

when the title in the frontmatter title is empty


I have been using kiln reliably for my blog for quite a while and really
enjoyed it.
I recently realized that I only use the frontmatter to specify the title
of my post (and that I was never quite sure of the syntax for it).
To simplify my workflow, I propose to add a fallback, which looks at the
first content line and set it as a title if it starts with "# " (common
title syntax for markdown/gmi files).

With this change, I can simply drop the frontmatter from all my blog
posts and simply start with the title (prefixed by "# ").

What do you think?
 page.go | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/page.go b/page.go
index 5679bbd..e302444 100644
--- a/page.go
+++ b/page.go
@@ -138,6 +138,21 @@ func (p *Page) _read(fsys fs.FS, path string, task *Task, cfg *Site) error {
				content = bytes.TrimLeft(content, "\r\n")

			// If the frontmatter title is empty, try to extract it from the first content line
			// when it starts with "# " (title syntax for markdown and gemtext files)
			if page.Title == "" {
				if len(content) > 2 && content[0] == '#' && content[1] == ' ' {
					j := 2
					for ; j < len(content); j++ {
						if content[j] == '\r' || content[j] == '\n' {
					page.Title = string(content[2:j])
					content = content[j:]

			if cmd, ok := task.preprocess[strings.TrimPrefix(ext, ".")]; ok {
				var buf bytes.Buffer
				if err := execute(cmd, bytes.NewReader(content), &buf); err != nil {