From aee32aafdfe313be5b5fff21866e4bd562a7e545 Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Sun, 16 Apr 2017 12:05:58 -0700 Subject: tags support wip --- archive/tag.go | 3 +-- post/post.go | 11 ++++++++++- site/site.go | 2 -- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/archive/tag.go b/archive/tag.go index 038ccb8..8c1b96d 100644 --- a/archive/tag.go +++ b/archive/tag.go @@ -24,9 +24,8 @@ func (ta TagArchive) Render() []byte { return render.Render(tagTmplName, ta) } -/* TODO: make this configurable */ func (ta TagArchive) Target() string { - return path.Join(config.Config.HtmlDir, "/tag/", fmt.Sprintf("%s.html", ta.Tag)) + return path.Join(config.Config.HtmlDir, "tag", t, "index.html") } type TagArchives []*TagArchive diff --git a/post/post.go b/post/post.go index 7a6f478..792635f 100644 --- a/post/post.go +++ b/post/post.go @@ -134,14 +134,23 @@ func (p *Post) parse() { p.WordCount = len(strings.Split(p.Text, " ")) // Tags + // TODO: separate tag stuff to other module if p.Meta["tags"] != "" { tags := strings.Split(p.Meta["tags"], ",") for _, tag := range tags { - p.Tags = append(p.Tags, strings.TrimSpace(tag)) + p.Tags = append(p.Tags, NormalizeTag(tag)) } } } +/* +NormalizeTag trims leading/ending spaces, lowercases, and replaces internal spaces with _ +*/ +func NormalizeTag(tag string) string { + t := strings.ToLower(strings.TrimSpace(tag)) + return strings.Replace(t, " ", "_", -1) +} + /* splitText splits up p.Unparsed into p.Text and p.Meta[attr][value] */ diff --git a/site/site.go b/site/site.go index f897171..00814ce 100644 --- a/site/site.go +++ b/site/site.go @@ -48,7 +48,6 @@ func (s *Site) Read() { } if render.TmplExists("tag") { s.Tagged = archive.ParseTags(s.Posts) - log.Printf("%v\n", s.Tagged) } if render.TmplExists("home") { s.Home = archive.NewListArchive(s.Posts) @@ -133,7 +132,6 @@ func (s *Site) WriteArchives() { } if render.TmplExists("tag") { for _, t := range *s.Tagged { - log.Printf("%s\n%v\n\n", t.Tag, t.Posts) t.Site = s render.Write(t) } -- cgit v1.2.3