add public field to adoc header

This commit is contained in:
Erik Winter 2021-04-14 07:01:39 +02:00
parent bc5e56ae26
commit 571c1df0a2
6 changed files with 14 additions and 1 deletions

View File

@ -2,6 +2,7 @@
Erik Winter <ik@erikwinter.nl> Erik Winter <ik@erikwinter.nl>
2020-12-01 2020-12-01
:kind: essay :kind: essay
:public: yes
:tags: asciidoc :tags: asciidoc
:project: shitty-ssg :project: shitty-ssg
:language: EN :language: EN
@ -27,6 +28,7 @@ A header consists of the title of the post and various fields of metadata. It lo
Erik Winter <info@erikwinter.nl> Erik Winter <info@erikwinter.nl>
2020-12-01 2020-12-01
:kind: note :kind: note
:public: yes
:language: EN :language: EN
:project: shitty-ssg :project: shitty-ssg
:tags: asciidoc, ssg, parser :tags: asciidoc, ssg, parser
@ -38,6 +40,7 @@ It starts with the title on the first line, which is prefixed with `=`, and it e
A the attributes of a post are defined as a key-value pair. Each pair gets its own line. The following attributes are supported: A the attributes of a post are defined as a key-value pair. Each pair gets its own line. The following attributes are supported:
* `kind` The type of post. Either `note`, `story` or `article`. * `kind` The type of post. Either `note`, `story` or `article`.
* `public` Can be exported to sites/systems that other people see. Values are `true`/`yes`, `false`/`no`. Defaults to `false`.
* `language` A two letter country code. Only `NL` will have a visible effect, by showing the Dutch flag in various places. * `language` A two letter country code. Only `NL` will have a visible effect, by showing the Dutch flag in various places.
* `project` Posts that belong to a personal project. * `project` Posts that belong to a personal project.
* `tags` A comma separated list of tags. * `tags` A comma separated list of tags.

View File

@ -2,6 +2,7 @@
Erik Winter <ik@erikwinter.nl> Erik Winter <ik@erikwinter.nl>
2021-03-09 2021-03-09
:kind: article :kind: article
:public: yes
:tags: golang, asciidoc :tags: golang, asciidoc
:project: shitty-ssg :project: shitty-ssg
:language: en :language: en

View File

@ -2,6 +2,7 @@
Erik Winter Erik Winter
2020-11-09 2020-11-09
:kind: article :kind: article
:public: yes
:tags: productivity, asciidoc, hugo :tags: productivity, asciidoc, hugo
:language: EN :language: EN
:project: shitty-ssg :project: shitty-ssg

View File

@ -67,6 +67,7 @@ type ADoc struct {
Author string Author string
Kind Kind Kind Kind
Language Language Language Language
Public bool
Path string Path string
Date time.Time Date time.Time
Tags []Tag Tags []Tag

View File

@ -128,6 +128,12 @@ func ParseHeader(text string, doc *ADoc) {
case strings.HasPrefix(l, ":language:"): case strings.HasPrefix(l, ":language:"):
s := strings.Split(l, ":") s := strings.Split(l, ":")
doc.Language = NewLanguage(strings.TrimSpace(s[2])) doc.Language = NewLanguage(strings.TrimSpace(s[2]))
case strings.HasPrefix(l, ":public:"):
s := strings.Split(l, ":")
val := strings.TrimSpace(s[2])
if val == "yes" || val == "true" {
doc.Public = true
}
case strings.HasPrefix(l, ":tags:"): case strings.HasPrefix(l, ":tags:"):
s := strings.Split(l, ":") s := strings.Split(l, ":")
t := strings.Split(s[2], ",") t := strings.Split(s[2], ",")

View File

@ -39,11 +39,12 @@ func TestNew(t *testing.T) {
}, },
{ {
name: "header", name: "header",
input: "= Title\nT. Test\n2020-10-27\n:tags:\ttag1, tag2\n:kind:\tnote\n:language:\tnl", input: "= Title\nT. Test\n2020-10-27\n:tags:\ttag1, tag2\n:kind:\tnote\n:language:\tnl\n:public: yes",
exp: &adoc.ADoc{ exp: &adoc.ADoc{
Title: "Title", Title: "Title",
Author: "T. Test", Author: "T. Test",
Kind: adoc.KIND_NOTE, Kind: adoc.KIND_NOTE,
Public: true,
Language: adoc.LANGUAGE_NL, Language: adoc.LANGUAGE_NL,
Tags: []adoc.Tag{ Tags: []adoc.Tag{
adoc.Tag("tag1"), adoc.Tag("tag1"),