From 571c1df0a2501d125231699a40d00fe694e95711 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Wed, 14 Apr 2021 07:01:39 +0200 Subject: [PATCH] add public field to adoc header --- doc/a-tiny-subset-of-asciidoc-for-blogging.adoc | 3 +++ doc/code-walkthrough.adoc | 1 + doc/why-i-built-my-own-shitty-static-site-generator.adoc | 1 + pkg/adoc/adoc.go | 1 + pkg/adoc/parser.go | 6 ++++++ pkg/adoc/parser_test.go | 3 ++- 6 files changed, 14 insertions(+), 1 deletion(-) diff --git a/doc/a-tiny-subset-of-asciidoc-for-blogging.adoc b/doc/a-tiny-subset-of-asciidoc-for-blogging.adoc index 0a0d6b1..0b41b57 100644 --- a/doc/a-tiny-subset-of-asciidoc-for-blogging.adoc +++ b/doc/a-tiny-subset-of-asciidoc-for-blogging.adoc @@ -2,6 +2,7 @@ Erik Winter 2020-12-01 :kind: essay +:public: yes :tags: asciidoc :project: shitty-ssg :language: EN @@ -27,6 +28,7 @@ A header consists of the title of the post and various fields of metadata. It lo Erik Winter 2020-12-01 :kind: note +:public: yes :language: EN :project: shitty-ssg :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: * `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. * `project` Posts that belong to a personal project. * `tags` A comma separated list of tags. diff --git a/doc/code-walkthrough.adoc b/doc/code-walkthrough.adoc index 40d4291..e2743a9 100644 --- a/doc/code-walkthrough.adoc +++ b/doc/code-walkthrough.adoc @@ -2,6 +2,7 @@ Erik Winter 2021-03-09 :kind: article +:public: yes :tags: golang, asciidoc :project: shitty-ssg :language: en diff --git a/doc/why-i-built-my-own-shitty-static-site-generator.adoc b/doc/why-i-built-my-own-shitty-static-site-generator.adoc index 0808da3..9d8db5a 100644 --- a/doc/why-i-built-my-own-shitty-static-site-generator.adoc +++ b/doc/why-i-built-my-own-shitty-static-site-generator.adoc @@ -2,6 +2,7 @@ Erik Winter 2020-11-09 :kind: article +:public: yes :tags: productivity, asciidoc, hugo :language: EN :project: shitty-ssg diff --git a/pkg/adoc/adoc.go b/pkg/adoc/adoc.go index 7d41625..560c65d 100644 --- a/pkg/adoc/adoc.go +++ b/pkg/adoc/adoc.go @@ -67,6 +67,7 @@ type ADoc struct { Author string Kind Kind Language Language + Public bool Path string Date time.Time Tags []Tag diff --git a/pkg/adoc/parser.go b/pkg/adoc/parser.go index 2926e46..a88812c 100644 --- a/pkg/adoc/parser.go +++ b/pkg/adoc/parser.go @@ -128,6 +128,12 @@ func ParseHeader(text string, doc *ADoc) { case strings.HasPrefix(l, ":language:"): s := strings.Split(l, ":") 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:"): s := strings.Split(l, ":") t := strings.Split(s[2], ",") diff --git a/pkg/adoc/parser_test.go b/pkg/adoc/parser_test.go index 9149300..72e37cc 100644 --- a/pkg/adoc/parser_test.go +++ b/pkg/adoc/parser_test.go @@ -39,11 +39,12 @@ func TestNew(t *testing.T) { }, { 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{ Title: "Title", Author: "T. Test", Kind: adoc.KIND_NOTE, + Public: true, Language: adoc.LANGUAGE_NL, Tags: []adoc.Tag{ adoc.Tag("tag1"),