summaryrefslogtreecommitdiff
path: root/frontmatter.go
diff options
context:
space:
mode:
Diffstat (limited to 'frontmatter.go')
-rw-r--r--frontmatter.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/frontmatter.go b/frontmatter.go
new file mode 100644
index 0000000..03237b5
--- /dev/null
+++ b/frontmatter.go
@@ -0,0 +1,39 @@
+// Copyright (c) 2023 Nicolas Paul All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+import (
+ "bytes"
+ "time"
+
+ "github.com/adrg/frontmatter"
+)
+
+// FrontMatter is the front matter of a Markdown document.
+type FrontMatter struct {
+ Title string `yaml:"title"`
+ Description string `yaml:"description"`
+ PublicationTime time.Time `yaml:"publication_time"`
+ LastUpdateTime time.Time `yaml:"last_update_time"`
+ Keywords []string `yaml:"keywords"`
+ Author string `yaml:"author"`
+ Hide bool `yaml:"hide"`
+}
+
+// ParseFrontMatter parses the front matter of a Markdown document.
+// It returns a FrontMatter struct and the Markdown document without the
+// front matter.
+func ParseFrontMatter(r []byte) (FrontMatter, []byte, error) {
+ var fm FrontMatter
+
+ reader := bytes.NewReader(r)
+
+ rest, err := frontmatter.MustParse(reader, &fm)
+ if err != nil {
+ return FrontMatter{}, nil, err
+ }
+
+ return fm, rest, nil
+}