aboutsummaryrefslogtreecommitdiff
path: root/internal/front
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2019-03-21 07:55:32 -0700
committerChristine Dodrill <me@christine.website>2019-03-21 07:57:23 -0700
commit368bd244aed0709c8b1bb05464d44f4d0cca07a4 (patch)
treebabc41308d52a97f0f3b50bad57bbb92ece79dc6 /internal/front
parent47ddf59c12bc8827dafa80383c6c7b0595fecab1 (diff)
downloadxesite-368bd244aed0709c8b1bb05464d44f4d0cca07a4.tar.xz
xesite-368bd244aed0709c8b1bb05464d44f4d0cca07a4.zip
vendor some dependencies
Diffstat (limited to 'internal/front')
-rw-r--r--internal/front/LICENSE19
-rw-r--r--internal/front/front.go24
2 files changed, 43 insertions, 0 deletions
diff --git a/internal/front/LICENSE b/internal/front/LICENSE
new file mode 100644
index 0000000..e8152bb
--- /dev/null
+++ b/internal/front/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2017 TJ Holowaychuk <tj@vision-media.ca>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE. \ No newline at end of file
diff --git a/internal/front/front.go b/internal/front/front.go
new file mode 100644
index 0000000..b2c7f0e
--- /dev/null
+++ b/internal/front/front.go
@@ -0,0 +1,24 @@
+// Package front provides YAML frontmatter unmarshalling.
+package front
+
+import (
+ "bytes"
+
+ "gopkg.in/yaml.v2"
+)
+
+// Delimiter.
+var delim = []byte("---")
+
+// Unmarshal parses YAML frontmatter and returns the content. When no
+// frontmatter delimiters are present the original content is returned.
+func Unmarshal(b []byte, v interface{}) (content []byte, err error) {
+ if !bytes.HasPrefix(b, delim) {
+ return b, nil
+ }
+
+ parts := bytes.SplitN(b, delim, 3)
+ content = parts[2]
+ err = yaml.Unmarshal(parts[1], v)
+ return
+}