diff options
| author | Christine Dodrill <me@christine.website> | 2019-05-21 21:47:09 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-05-21 21:47:09 -0400 |
| commit | d64c666255665c5e03812c47e70d6edb46432510 (patch) | |
| tree | 1dd44e77f7d57a5a52ccfa0fe96fc073cb3da2fe /internal | |
| parent | a275fc754b4c82a81ba06f0f3cbddb39946db1ac (diff) | |
| download | xesite-d64c666255665c5e03812c47e70d6edb46432510.tar.xz xesite-d64c666255665c5e03812c47e70d6edb46432510.zip | |
add talks support (#40)
* add talks support
* gosimplify
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/blog/blog.go | 14 | ||||
| -rw-r--r-- | internal/blog/blog_test.go | 38 |
2 files changed, 47 insertions, 5 deletions
diff --git a/internal/blog/blog.go b/internal/blog/blog.go index a73f27b..eac5d64 100644 --- a/internal/blog/blog.go +++ b/internal/blog/blog.go @@ -20,6 +20,7 @@ type Post struct { Summary string `json:"summary,omitifempty"` Body string `json:"-"` BodyHTML template.HTML `json:"body"` + SlidesLink string `json:"slides_link"` Date time.Time DateString string `json:"date"` } @@ -37,10 +38,11 @@ func (p Posts) Less(i, j int) bool { func (p Posts) Swap(i, j int) { p[i], p[j] = p[j], p[i] } // LoadPosts loads posts for a given directory. -func LoadPosts(path string) (Posts, error) { +func LoadPosts(path string, prepend string) (Posts, error) { type postFM struct { - Title string - Date string + Title string + Date string + SlidesLink string `yaml:"slides_link"` } var result Posts @@ -78,13 +80,17 @@ func LoadPosts(path string) (Posts, error) { return err } + fname := filepath.Base(path) + fname = strings.TrimSuffix(fname, filepath.Ext(fname)) + p := Post{ Title: fm.Title, Date: date, DateString: fm.Date, - Link: strings.Split(path, ".")[0], + Link: filepath.Join(prepend, fname), Body: string(remaining), BodyHTML: template.HTML(output), + SlidesLink: fm.SlidesLink, } result = append(result, p) diff --git a/internal/blog/blog_test.go b/internal/blog/blog_test.go index b073880..8a446cd 100644 --- a/internal/blog/blog_test.go +++ b/internal/blog/blog_test.go @@ -5,8 +5,44 @@ import ( ) func TestLoadPosts(t *testing.T) { - _, err := LoadPosts("../../blog") + posts, err := LoadPosts("../../blog", "blog") if err != nil { t.Fatal(err) } + + for _, post := range posts { + t.Run(post.Link, post.test) + } +} + +func TestLoadTalks(t *testing.T) { + talks, err := LoadPosts("../../talks", "talks") + if err != nil { + t.Fatal(err) + } + + for _, talk := range talks { + t.Run(talk.Link, talk.test) + if talk.SlidesLink == "" { + t.Errorf("talk %s (%s) doesn't have a slides link", talk.Title, talk.DateString) + } + } +} + +func (p Post) test(t *testing.T) { + if p.Title == "" { + t.Error("no post title") + } + + if p.DateString == "" { + t.Error("no date") + } + + if p.Link == "" { + t.Error("no link") + } + + if p.Body == "" { + t.Error("no body") + } } |
