Add tagging support

This commit is contained in:
Serghei Iakovlev 2022-05-31 09:35:31 +02:00
parent 882af06563
commit 41df0128d6
No known key found for this signature in database
GPG key ID: C6AF1016BBDEA800
11 changed files with 319 additions and 15 deletions

View file

@ -9,13 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Provide ability to include custom scripts in the theme.
- Provide ability to specify custom language of a post.
- Provide ability to include custom scripts in the theme
- Provide ability to specify custom language of a post
- Add tagging support
### Changed
- Mior reformatting of posts layout.
- Allow to manually override lastmod date of a post.
- Minor reformatting of posts layout
- Allow manually override lastmod date of a post
- Check that `lastmod` exists and is greater than `date` before printing it
## [v0.2.0](https://github.com/sergeyklay/gohugo-theme-ed/compare/v0.1.0...v0.2.0)
@ -43,7 +45,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix margin bottom on the nested unordered lists for page's table of contents
- Fix default section type for the `params.mainSections` configuration variable
- Fix url to sitemap in robots.txt file
- Fix url to sitemap in `robots.txt` file
## v0.1.0 - 2022-05-27

View file

@ -139,3 +139,139 @@ ul.pager li {
margin-bottom: 1rem;
display: inline-block;
}
.post-tags-wrapper {
position: relative;
}
.post-tags {
margin: 0;
padding: 0;
position: absolute;
right: 24px;
bottom: -12px;
list-style: none;
}
.post-tags li,
.post-tags a {
font-family: $heading-font;
float: left;
height: 24px;
line-height: 24px;
position: relative;
font-size: .75em;
}
.post-tags a {
margin-left: 20px;
padding: 0 10px 0 12px;
background: $link-color;
color: #fff;
text-decoration: none;
-webkit-border-bottom-right-radius:4px;
-moz-border-radius-bottomright:4px;
border-bottom-right-radius:4px;
-webkit-border-top-right-radius:4px;
-moz-border-radius-topright:4px;
border-top-right-radius:4px;
}
.post-tags a:before {
content: "";
float: left;
position: absolute;
top: 0;
left: -12px;
width: 0;
height: 0;
border-color: transparent $link-color transparent transparent;
border-style: solid;
border-width: 12px 12px 12px 0;
}
.post-tags a:after {
content: "";
position: absolute;
top: 10px;
left: 0;
float: left;
width: 4px;
height: 4px;
background: #fff;
@include border-radius (2px);
@include box-shadow (-1px -1px 2px $text-color);
}
.post-tags a:hover {
background: $text-light-color;
}
.post-tags a:hover:before {
border-color: transparent $text-light-color transparent transparent;
}
/* Themes */
/* Red */
.theme-base-red .post-tags a {
background: #ac4142;
}
.theme-base-red .post-tags a:before {
border-color: transparent #ac4142 transparent transparent;
}
/* Orange */
.theme-base-orange .post-tags a {
background: #d28445;
}
.theme-base-orange .post-tags a:before {
border-color: transparent #d28445 transparent transparent;
}
/* Green */
.theme-base-green .post-tags a {
background: #90a959;
}
.theme-base-green .post-tags a:before {
border-color: transparent #90a959 transparent transparent;
}
/* Cyan */
.theme-base-cyan .post-tags a {
background: #75b5aa;
}
.theme-base-cyan .post-tags a:before {
border-color: transparent #75b5aa transparent transparent;
}
/* Blue */
.theme-base-blue .post-tags a {
background: #6a9fb5;
}
.theme-base-blue .post-tags a:before {
border-color: transparent #6a9fb5 transparent transparent;
}
/* Magenta */
.theme-base-magenta .post-tags a {
background: #aa759f;
}
.theme-base-magenta .post-tags a:before {
border-color: transparent #aa759f transparent transparent;
}
/* Brown */
.theme-base-brown .post-tags a {
background: #8f5536;
}
.theme-base-brown .post-tags a:before {
border-color: transparent #8f5536 transparent transparent;
}

View file

@ -42,3 +42,6 @@
[all_publications]
other = 'All publications'
[publications_tagged]
other = 'Publications tagged "{{ . }}"'

View file

@ -42,3 +42,6 @@
[all_publications]
other = 'Все публикации'
[publications_tagged]
other = 'Публикации с тегом "{{ . }}"'

View file

@ -1,7 +1,6 @@
{{ define "main" }}
<div class="articles">
{{/* Render category name if any */}}
{{ with .Title }}<h1 class="page-title">{{ . }}</h1>{{ end }}
{{/* Render category content if any */}}

View file

@ -13,5 +13,9 @@
<div class="post-body">
{{ .Content }}
</div>
<div class="post-tags-wrapper">
{{ partial "post-tags.html" . }}
</div>
</article>
{{ end }}

View file

@ -0,0 +1,26 @@
{{ define "main" }}
<div class="articles">
{{/* TODO: Translate me */}}
<h1 class="page-title">
{{ with .Title }}{{ i18n "publications_tagged" . }}{{ end }}
</h1>
{{/* Render category content if any */}}
{{ with .Content }}
<div class="section-content">
{{ .Content }}
</div>
{{ end }}
{{/* Render posts list */}}
<div class="post-list">
{{ range .Paginator.Pages }}
{{ .Render "teaser" }}
{{ end }}
{{- partial "pagination.html" . -}}
</div>
</div>
{{ end }}

View file

@ -1,11 +1,14 @@
{{ if not .Date.IsZero }}
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ .Date | time.Format (site.Params.dateformat | default "January 02, 2006") }}
</time>
{{ $date := .Date | time.Format (site.Params.dateformat | default "January 02, 2006") }}
{{ $lastmod := .Lastmod | time.Format (site.Params.dateformat | default "January 02, 2006") }}
{{ if ne .Date .Lastmod }}
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">
({{ i18n "updated_at" }} {{ .Lastmod | time.Format (site.Params.dateformat | default "January 02, 2006") }})
</time>
{{ end }}
<time datetime="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}">
{{ $date }}
</time>
{{/* Check that lastmod exists and is greater than date
(i.e. the last modified date must be after the publish date) */}}
{{ if and (ne $lastmod $date) (gt .Lastmod .Date) }}
<time datetime="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}">
({{ i18n "updated_at" }} {{ $lastmod }})
</time>
{{ end }}

View file

@ -0,0 +1,9 @@
{{ $tags := .Params.Tags | default slice }}
<ul class="post-tags">
{{ range $index, $name := sort $tags -}}
<a href="{{ (printf "/tags/%s/" $name) | urlize }}">
{{ $name | markdownify }}
</a>
{{ end }}
</ul>

View file

@ -1,5 +1,7 @@
{{- if or .IsHome (eq .Title site.Title) -}}
{{- site.Title -}}
{{- else if and (eq .Kind "term") (eq .Data.Singular "tag") -}}
{{- with .Title }}{{ i18n "publications_tagged" . }} - {{ end }}{{ site.Title -}}
{{- else -}}
{{- with .Title }}{{ . }} - {{ end }}{{ site.Title -}}
{{- end -}}

View file

@ -970,3 +970,120 @@ ul.pager li {
.footnotes blockquote + a.footnote-backref {
margin-bottom: 1rem;
display: inline-block; }
.post-tags-wrapper {
position: relative; }
.post-tags {
margin: 0;
padding: 0;
position: absolute;
right: 24px;
bottom: -12px;
list-style: none; }
.post-tags li,
.post-tags a {
font-family: sans-serif;
float: left;
height: 24px;
line-height: 24px;
position: relative;
font-size: .75em; }
.post-tags a {
margin-left: 20px;
padding: 0 10px 0 12px;
background: #841212;
color: #fff;
text-decoration: none;
-webkit-border-bottom-right-radius: 4px;
-moz-border-radius-bottomright: 4px;
border-bottom-right-radius: 4px;
-webkit-border-top-right-radius: 4px;
-moz-border-radius-topright: 4px;
border-top-right-radius: 4px; }
.post-tags a:before {
content: "";
float: left;
position: absolute;
top: 0;
left: -12px;
width: 0;
height: 0;
border-color: transparent #841212 transparent transparent;
border-style: solid;
border-width: 12px 12px 12px 0; }
.post-tags a:after {
content: "";
position: absolute;
top: 10px;
left: 0;
float: left;
width: 4px;
height: 4px;
background: #fff;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
border-radius: 2px;
-webkit-box-shadow: -1px -1px 2px #454545;
-moz-box-shadow: -1px -1px 2px #454545;
box-shadow: -1px -1px 2px #454545; }
.post-tags a:hover {
background: #676767; }
.post-tags a:hover:before {
border-color: transparent #676767 transparent transparent; }
/* Themes */
/* Red */
.theme-base-red .post-tags a {
background: #ac4142; }
.theme-base-red .post-tags a:before {
border-color: transparent #ac4142 transparent transparent; }
/* Orange */
.theme-base-orange .post-tags a {
background: #d28445; }
.theme-base-orange .post-tags a:before {
border-color: transparent #d28445 transparent transparent; }
/* Green */
.theme-base-green .post-tags a {
background: #90a959; }
.theme-base-green .post-tags a:before {
border-color: transparent #90a959 transparent transparent; }
/* Cyan */
.theme-base-cyan .post-tags a {
background: #75b5aa; }
.theme-base-cyan .post-tags a:before {
border-color: transparent #75b5aa transparent transparent; }
/* Blue */
.theme-base-blue .post-tags a {
background: #6a9fb5; }
.theme-base-blue .post-tags a:before {
border-color: transparent #6a9fb5 transparent transparent; }
/* Magenta */
.theme-base-magenta .post-tags a {
background: #aa759f; }
.theme-base-magenta .post-tags a:before {
border-color: transparent #aa759f transparent transparent; }
/* Brown */
.theme-base-brown .post-tags a {
background: #8f5536; }
.theme-base-brown .post-tags a:before {
border-color: transparent #8f5536 transparent transparent; }