go.talks/pkg/present: add Tags feature
By tagging articles and slide decks, we can point readers toward
related content.
R=campoy
CC=golang-dev
https://golang.org/cl/7065071
diff --git a/pkg/present/doc.go b/pkg/present/doc.go
index e1544f7..32be150 100644
--- a/pkg/present/doc.go
+++ b/pkg/present/doc.go
@@ -11,6 +11,7 @@
Title of document
Subtitle of document
15:04 2 Jan 2006
+ Tags: foo, bar, baz
<blank line>
Author Name
Job title, Company
@@ -18,11 +19,15 @@
http://url/
@twitter_name
-The subtitle and date lines are optional.
+The subtitle, date, and tags lines are optional.
+
The date line may be written without a time:
2 Jan 2006
In this case, the time will be interpreted as 10am UTC on that date.
+The tags line is a comma-separated list of tags that may be used to categorize
+the document.
+
The author section may contain a mixture of text, twitter names, and links.
For slide presentations, only the plain text lines will be displayed on the
first slide.
diff --git a/pkg/present/parse.go b/pkg/present/parse.go
index d676d6d..7bc8e40 100644
--- a/pkg/present/parse.go
+++ b/pkg/present/parse.go
@@ -59,6 +59,7 @@
Time time.Time
Authors []Author
Sections []Section
+ Tags []string
}
// Author represents the person who wrote and/or is presenting the document.
@@ -372,15 +373,20 @@
if text == "" {
break
}
- if t, ok := parseTime(text); ok {
+ const tagPrefix = "Tags:"
+ if strings.HasPrefix(text, tagPrefix) {
+ tags := strings.Split(text[len(tagPrefix):], ",")
+ for i := range tags {
+ tags[i] = strings.TrimSpace(tags[i])
+ }
+ doc.Tags = append(doc.Tags, tags...)
+ } else if t, ok := parseTime(text); ok {
doc.Time = t
- break
- }
- if doc.Subtitle == "" {
+ } else if doc.Subtitle == "" {
doc.Subtitle = text
- continue
+ } else {
+ return fmt.Errorf("unexpected header line: %q", text)
}
- return fmt.Errorf("unexpected header line: %q", text)
}
return nil
}