How to separate page content from it's frontmatter?

I use the following template:

```template
{{#each {
page
    where
        name =~ /^Fleeting Notes\//
    order by
        date desc
    }
}}
#{{
    replace(name, /^Fleeting Notes.+/, "")
}} [[{{name}}]]
{{readPage(name)}}
{{/each}}
```

Is there a way to get only the page content (without the YAML frontmatter)
and only the page frontmatter from the result of the readPage() function? I guess it’s doable with registering new custom functions somehow? Would somebody know how to achieve it? Thank you.

Since the frontmatter is delimited with --- we can use a regular expression to find where it is in text, and then replace this part of text with something else.

Luckily we don’t even have to figure out this expression ourselves, because finding the frontmatter is something that also the main silverbullet code needs to do (cf. lib/cheap_yaml.ts)

{{replace(readPage(name), /^---\n(([^\n]|\n)*?)---\n/, "")}}
3 Likes

@Maarrk Thanks. I haven’t known that I can work on the entire content like that (I’m probably too used to the line oriented unix approach that I was thinking of how to split it to lines and iterate over them etc.) :smile:

1 Like