Skip to content

Commit

Permalink
feat: add tags to post pages (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Sep 1, 2021
1 parent 9541762 commit 3f29662
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 29 deletions.
4 changes: 4 additions & 0 deletions exampleSite/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ markup:
startLevel: 1
endLevel: 9

taxonomies:
tag: tags

params:
# geekdocMenuBundle: true
geekdocToC: 3
geekdocTagsToMenu: true

geekdocRepo: https://github.com/thegeeklab/hugo-geekdoc
geekdocEditPath: edit/main/exampleSite/content
Expand Down
2 changes: 2 additions & 0 deletions exampleSite/content/posts/hello_geekdoc.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
title: Hello Geekdoc
type: posts
date: 2020-01-06
tags:
- Documentation
---

This is the first release of the Geekdoc theme.
Expand Down
12 changes: 12 additions & 0 deletions exampleSite/content/usage/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ enableGitInfo = true
startLevel = 1
endLevel = 9

[taxonomies]
tag = "tags"

[params]
# (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
Expand Down Expand Up @@ -97,6 +100,9 @@ enableGitInfo = true

# (Optional, default true) Display a "Back to top" link in the site footer.
geekdocBackToTop = true

# (Optional, default false) Enable or disable adding tags for post pages automatically to the navigation sidebar.
geekdocTagsToMenu = true
```

{{< /tab >}}
Expand All @@ -123,6 +129,9 @@ markup:
startLevel: 1
endLevel: 9

taxonomies:
tag: tags

params:
# (Optional, default 6) Set how many table of contents levels to be showed on page.
# Use false to hide ToC, note that 0 will default to 6 (https://gohugo.io/functions/default/)
Expand Down Expand Up @@ -196,6 +205,9 @@ params:

# (Optional, default true) Display a "Back to top" link in the site footer.
geekdocBackToTop: true

# (Optional, default false) Enable or disable adding tags for post pages automatically to the navigation sidebar.
geekdocTagsToMenu: true
```
{{< /tab >}}
Expand Down
3 changes: 3 additions & 0 deletions exampleSite/content/usage/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ To prepare your new site environment just a few steps are required:
[markup.tableOfContents]
startLevel = 1
endLevel = 9

[taxonomies]
tag = "tags"
```

5. Test your site.
Expand Down
1 change: 1 addition & 0 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{{ define "main" }}
{{ partial "page-header" . }}

<article class="gdoc-markdown gdoc-markdown__align--{{ default "left" (.Page.Params.GeekdocAlign | lower) }}">
<h1>{{ partial "title" . }}</h1>
{{ partial "content" . }}
Expand Down
16 changes: 16 additions & 0 deletions layouts/partials/menu.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,22 @@ <h2>Navigation</h2>
{{ end }}
</section>

{{ if and (in (slice "posts" "tags") .Section) (default false .Site.Params.GeekdocTagsToMenu) }}
<section class="gdoc-nav--tags">
<h2>Tags</h2>
<ul class="gdoc-nav__list">
{{ $currentPage := .RelPermalink }}
{{ range $name, $taxonomy := .Site.Taxonomies.tags }}
{{ with $.Site.GetPage (printf "/tags/%s" $name) }}
<li>
<a class="gdoc-nav__entry {{ if eq $currentPage .RelPermalink }} is-active {{ end }}" href="{{ .RelPermalink }}">{{ .Title }}</a>
</li>
{{ end }}
{{ end }}
</ul>
</section>
{{ end }}

<section class="gdoc-nav--more">
{{ if .Site.Data.menu.more.more }}
<h2>More</h2>
Expand Down
58 changes: 47 additions & 11 deletions layouts/posts/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,60 @@
<article class="gdoc-markdown gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
<div class="gdoc-post__date">
<svg class="icon gdoc_date"><use xlink:href="#gdoc_date"></use></svg>
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if ne (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }}
Updated on
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
</div>
</header>
<section>
{{ .Summary }}
</section>
{{ if .Truncated }}
<div class="gdoc-post__readmore">
{{ if .Truncated }}
<a class="flex-inline align-center fake-link" title="Read full post" href="{{ .RelPermalink }}">Read full post</a>
{{ end }}
</div>
{{ end }}

<footer class="gdoc-post__footer">
<span class="no-wrap">
<svg class="icon gdoc_date"><use xlink:href="#gdoc_date"></use></svg>
<span class="gdoc-post__tag">
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if .Lastmod.After (.Date.AddDate 0 0 1) }}
Updated on
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
</span>
</span>

<span class="no-wrap">
<svg class="icon gdoc_timer"><use xlink:href="#gdoc_timer"></use></svg>
<span class="gdoc-post__tag">{{ .ReadingTime }} min read</span>
</span>

{{ $tc := 0 }}
{{ with .Params.tags }}
{{ range sort . }}
{{ $name := . }}
{{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }}
{{ if eq $tc 0 }}
<span class="no-wrap">
<svg class="icon gdoc_bookmark"><use xlink:href="#gdoc_bookmark"></use></svg>
{{ template "post-tag" dict "name" $name "page" . }}
</span>
{{ else }}
{{ template "post-tag" dict "name" $name "page" . }}
{{ end }}
{{ end }}
{{ $tc = (add $tc 1) }}
{{ end }}
{{ end }}
</footer>
</article>
{{ end }}
{{ end }}

{{ define "post-tag" }}
<span class="gdoc-post__tag">
<span class="gdoc-button">
<a class="gdoc-button__link" href="{{ .page.RelPermalink }}" title="All posts tagged with '{{ .name }}'">{{ .name }}</a>
</span>
</span>
{{ end }}
27 changes: 18 additions & 9 deletions layouts/posts/single.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@
<article class="gdoc-markdown gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title">{{ .Title }}</h1>
<div class="gdoc-post__date">
<svg class="icon gdoc_date"><use xlink:href="#gdoc_date"></use></svg>
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if ne (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }}
Updated on
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
</div>
<div class="gdoc-post__meta">
<span class="no-wrap">
<svg class="icon gdoc_date"><use xlink:href="#gdoc_date"></use></svg>
<span class="gdoc-post__tag">
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if ne (.Lastmod.Format "2006-01-02") (.Date.Format "2006-01-02") }}
Updated on
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
</span>
</span>

<span class="no-wrap">
<svg class="icon gdoc_timer"><use xlink:href="#gdoc_timer"></use></svg>
<span class="gdoc-post__tag">{{ .ReadingTime }} min read</span>
</span>
</div>
</header>
<div>
{{ partial "content" . }}
Expand Down
62 changes: 62 additions & 0 deletions layouts/taxonomy/list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{ define "main" }}
{{ range .Paginator.Pages }}
<article class="gdoc-markdown gdoc-post">
<header class="gdoc-post__header">
<h1 class="gdoc-post__title"><a href="{{ .RelPermalink }}">{{ .Title }}</a></h1>
</header>
<section>
{{ .Summary }}
</section>
<div class="gdoc-post__readmore">
{{ if .Truncated }}
<a class="flex-inline align-center fake-link" title="Read full post" href="{{ .RelPermalink }}">Read full post</a>
{{ end }}
</div>

<footer class="gdoc-post__footer">
<span class="no-wrap">
<svg class="icon gdoc_date"><use xlink:href="#gdoc_date"></use></svg>
<span class="gdoc-post__tag">
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" | safeHTML }}">
{{ if .Lastmod.After (.Date.AddDate 0 0 1) }}
Updated on
{{ end }}
{{ .Lastmod.Format "Jan 2, 2006" }}
</time>
</span>
</span>

<span class="no-wrap">
<svg class="icon gdoc_timer"><use xlink:href="#gdoc_timer"></use></svg>
<span class="gdoc-post__tag">{{ .ReadingTime }} min read</span>
</span>

{{ $tc := 0 }}
{{ with .Params.tags }}
{{ range sort . }}
{{ $name := . }}
{{ with $.Site.GetPage (printf "/tags/%s" $name | urlize) }}
{{ if eq $tc 0 }}
<span class="no-wrap">
<svg class="icon gdoc_bookmark"><use xlink:href="#gdoc_bookmark"></use></svg>
{{ template "post-tag" dict "name" $name "page" . }}
</span>
{{ else }}
{{ template "post-tag" dict "name" $name "page" . }}
{{ end }}
{{ end }}
{{ $tc = (add $tc 1) }}
{{ end }}
{{ end }}
</footer>
</article>
{{ end }}
{{ end }}

{{ define "post-tag" }}
<span class="gdoc-post__tag">
<span class="gdoc-button">
<a class="gdoc-button__link" href="{{ .page.RelPermalink }}" title="All posts tagged with '{{ .name }}'">{{ .name }}</a>
</span>
</span>
{{ end }}
Empty file removed layouts/taxonomy/taxonomy.html
Empty file.
5 changes: 5 additions & 0 deletions src/icons/timer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 29 additions & 9 deletions src/sass/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ img {
cursor: pointer;

.icon {
font-size: 0.7rem;
font-size: $font-size-12;
}
}

Expand Down Expand Up @@ -311,6 +311,7 @@ img {
font-weight: bold;
}

&--tags,
&--more {
padding-top: $padding-8;
}
Expand Down Expand Up @@ -437,14 +438,6 @@ img {
}
}

&__date {
margin: 1em 0;

.icon {
font-size: 1.2em;
}
}

&:first-child {
border-top: 0;

Expand All @@ -468,6 +461,33 @@ img {
text-decoration: none !important;
}
}

&__tag {
margin: $padding-4 0 !important;

.gdoc-button {
background: var(--body-background);

&__link {
padding: $padding-4 $padding-8;
}
}
}

&__meta {
padding-bottom: $padding-16;
}

&__footer,
&__meta {
:not(:first-child).no-wrap {
margin-left: $padding-8;
}

.icon {
font-size: $font-size-20;
}
}
}

.gdoc-footer {
Expand Down
4 changes: 4 additions & 0 deletions src/sass/_utils.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@
text-align: center;
}

.no-wrap {
white-space: nowrap;
}

.hidden {
display: none;
}
Expand Down

0 comments on commit 3f29662

Please sign in to comment.