diff options
author | Sébastien Rochette <statnmap@users.noreply.github.com> | 2018-01-20 19:38:44 +0300 |
---|---|---|
committer | Patrick Collins <thepatrickcollins@gmail.com> | 2018-01-20 19:38:44 +0300 |
commit | b700f40ab2d0e14b365cea2dc9daff4718892d47 (patch) | |
tree | 15c4b927fc67b54ed3aade74f8c862782321ce82 | |
parent | 8327be139c3c5d6d3103b3957e4cd07c9956d144 (diff) |
Add post tags (#103)
* Add gitignore
* Add tags in post footer + css
* Add tag in exampleSite template
* Allow page for list of (1) tags (/tags), (2) posts of specific tag
* ignore .gitignore
* Delete .gitignore
Nicer for pull requests to master
-rw-r--r-- | exampleSite/content/blog/creating-a-new-theme.md | 1 | ||||
-rw-r--r-- | layouts/post/footer-category.html | 66 | ||||
-rw-r--r-- | layouts/taxonomy/tag.html | 16 | ||||
-rw-r--r-- | layouts/taxonomy/tag.terms.html | 37 | ||||
-rw-r--r-- | static/css/main.css | 23 |
5 files changed, 94 insertions, 49 deletions
diff --git a/exampleSite/content/blog/creating-a-new-theme.md b/exampleSite/content/blog/creating-a-new-theme.md index 834ce9d..93b088d 100644 --- a/exampleSite/content/blog/creating-a-new-theme.md +++ b/exampleSite/content/blog/creating-a-new-theme.md @@ -1,6 +1,7 @@ +++ author = "Theme author" categories = ["Hugo"] +tags = ["tutorial"] date = "2014-09-28" description = "Learn how to create a theme on Hugo" featured = "pic03.jpg" diff --git a/layouts/post/footer-category.html b/layouts/post/footer-category.html index 35d85a9..8818c03 100644 --- a/layouts/post/footer-category.html +++ b/layouts/post/footer-category.html @@ -1,44 +1,30 @@ <ul class="stats"> - {{ if isset .Params "categories" }} - {{ $categoryCount := (len .Params.categories) }} - - <!-- - Set the title before displaying the categories associated with this post. - The title will use the variables from the Categories menu set in the Config. - If the Categories menu was not set then use the default values instead. - --> - {{ if ge $categoryCount 1 }} - <li> - {{ $categoryMenu := (where .Site.Menus.main "Name" "Categories") }} - {{ if ne (len $categoryMenu) 0 }} - {{ $categoryMenu := index $categoryMenu 0 }} - - {{ $.Scratch.Set "categoryUrl" $categoryMenu.URL }} - - {{ with $categoryMenu.Identifier }} - <i class="{{ . }}"> </i> - {{ end }} - - {{ if gt $categoryCount 1 }} - {{ $categoryMenu.Name }} - {{ else }} - {{ $categoryMenu.Name | singularize }} - {{ end }} - {{ else }} - {{ $.Scratch.Set "categoryUrl" "/categories/" }} - - {{ if gt $categoryCount 1 }} - Categories - {{ else }} - Category - {{ end }} + <li class="categories"> + <ul> + {{ if isset .Params "categories" }} + {{ $categoriesLen := len .Params.categories }} + {{ if gt $categoriesLen 0 }} + <i class="fa fa-folder"></i> + {{ range $k, $v := .Params.categories }} + {{ $url := printf "categories/%s" (. | urlize | lower) }} + <li><a class="article-category-link" href="{{ $url | absLangURL }}">{{ . }}</a></li> {{ end }} - </li> + {{ end }} {{ end }} - {{ end }} - - <!-- Display the categories associated with this post --> - {{ range .Params.categories }} - <li><a href='{{ add ($.Scratch.Get "categoryUrl") . | urlize }}'>{{ . }}</a></li> - {{ end }} + </ul> + </li> + <li class="tags"> + <ul> + {{ if isset .Params "tags" }} + {{ $tagsLen := len .Params.tags }} + {{ if gt $tagsLen 0 }} + <i class="fa fa-tags"></i> + {{ range $k, $v := .Params.tags }} + {{ $url := printf "tags/%s" (. | urlize | lower) }} + <li><a class="article-category-link" href="{{ $url | absLangURL }}">{{ . }}</a></li> + {{ end }} + {{ end }} + {{ end }} + </ul> + </li> </ul> diff --git a/layouts/taxonomy/tag.html b/layouts/taxonomy/tag.html new file mode 100644 index 0000000..8881b14 --- /dev/null +++ b/layouts/taxonomy/tag.html @@ -0,0 +1,16 @@ +{{ partial "general-title" . }} + +{{ partial "header" . }} + {{ partial "navbar" . }} + <!-- Main --> + <div id="main"> + <h1>{{ .Title }}</h1> + {{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} + {{ range $paginator.Pages }} + {{ .Render "content-list" }} + {{ end }} + + {{ partial "pagination" . }} + </div> + {{ partial "sidebar" . }} +{{ partial "footer" . }} diff --git a/layouts/taxonomy/tag.terms.html b/layouts/taxonomy/tag.terms.html new file mode 100644 index 0000000..34f591f --- /dev/null +++ b/layouts/taxonomy/tag.terms.html @@ -0,0 +1,37 @@ +{{ partial "general-title" . }} + +{{ partial "header" . }} + {{ partial "navbar" . }} + <!-- Main --> + <div id="main"> + {{ if .Site.Params.categoriesByCount }} + {{ $.Scratch.Set "tags" .Data.Terms.ByCount }} + {{ else }} + {{ $.Scratch.Set "tags" .Data.Terms.Alphabetical }} + {{ end }} + + <ul class="posts"> + <header> + <h1>{{ .Data.Plural }}</h1> + </header> + {{ $data := .Data }} + {{ range $key, $value := $.Scratch.Get "tags" }} + <li> + <article> + <header> + {{ if ne $value.Name "" }} + <a href="{{ printf "/%s/%s" $data.Plural $value.Name | urlize | relLangURL }}">{{ $value.Name }}</a> + <span style="float:right;">{{ $value.Count }}</span> + {{ else }} + {{ i18n "uncategorized" }} + <span style="float:right;">{{ $value.Count }}</span> + {{ end }} + </header> + </article> + </li> + {{ end }} + </ul> + </div> + + {{ partial "sidebar" . }} +{{ partial "footer" . }} diff --git a/static/css/main.css b/static/css/main.css index 50803b5..ba32a84 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1071,8 +1071,8 @@ ul.posts li { border-top: dotted 1px rgba(160, 160, 160, 0.3); - margin: 1.5em 0 0 0; - padding: 1.5em 0 0 0; + margin: 0.5em 0 0 0; + padding: 0.5em 0 0 0; } ul.posts li:first-child { @@ -1398,7 +1398,12 @@ padding: 0; } - .post > footer .stats li { + .post > footer .stats li, + .post > footer .stats li ul { + margin: 0; + padding-left: 0; + } + .post > footer .stats li ul li { border-left: solid 1px rgba(160, 160, 160, 0.3); display: inline-block; font-family: "Raleway", Helvetica, sans-serif; @@ -1406,22 +1411,22 @@ font-weight: 400; letter-spacing: 0.25em; line-height: 1; - margin: 0 0 0 2em; - padding: 0 0 0 2em; + margin: 0 0 0 1em; + padding: 0 0 0 1em; text-transform: uppercase; } - .post > footer .stats li:first-child { + .post > footer .stats li ul li:first-child { border-left: 0; margin-left: 0; padding-left: 0; } - .post > footer .stats li .icon { + .post > footer .stats li ul li .icon { border-bottom: 0; } - .post > footer .stats li .icon:before { + .post > footer .stats li ul li .icon:before { color: rgba(160, 160, 160, 0.3); margin-right: 0.75em; } @@ -1577,7 +1582,7 @@ text-align: center; } - .post > footer .stats li { + .post > footer .stats li ul li { margin: 0 0 0 1.25em; padding: 0 0 0 1.25em; } |