Skip to content

Commit

Permalink
feat: better tags support
Browse files Browse the repository at this point in the history
  • Loading branch information
dkolb committed Feb 8, 2025
1 parent 70f3e48 commit 7d66090
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 11 deletions.
33 changes: 25 additions & 8 deletions assets/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,19 @@ p.img-404 {
margin-left: 1em;
@include dimmed;
}

.post-tags {
display: flex;
flex-wrap: wrap;
flex-shrink: 0;
font-size:x-small;
@include dimmed;

a {
margin-right: 0.5em;
}
}

.post-description {
font-size:x-small;
flex-shrink: 0;
Expand Down Expand Up @@ -750,6 +763,18 @@ a.footnote-ref {
}
}

.tag {
text-transform: lowercase;
&::before {
{{- with .Site.Params.tagSymbol | default "#" -}}content: "{{ . }}"{{- end -}}
}
}
.category {
&::before {
{{- with .Site.Params.categorySymbol | default "⊲" -}}content: "{{ . }}"{{- end -}}
}
}

.post-description {
font-size: .8rem;
line-height: normal;
Expand All @@ -769,17 +794,9 @@ a.footnote-ref {

.tag {
margin-right: .5em;

&::before {
{{- with .Site.Params.tagSymbol | default "#" -}}content: "{{ . }}"{{- end -}}
}
}
.category {
margin-right: .5em;

&::before {
{{- with .Site.Params.categorySymbol | default "⊲" -}}content: "{{ . }}"{{- end -}}
}
}
}

Expand Down
3 changes: 2 additions & 1 deletion hugo.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ expiryDate = ["expiryDate"]
# categorySymbol = "⊲"
# pinned = "Pinned Posts"
# pinnedSVGname = "pin"
# descriptionInPosts= true
# descriptionInPosts = true
# tagsInPost = false
# initialPublish = "Initally Posted on: "
# human = ["single","posts"]
# noIndex = false
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{- partial "site-meta.html" . -}}
{{- partial "structure-extra.html" . -}}
{{- partial "webschema.html" . -}}
<title>{{.Title}}</title>
<title>{{ block "title" . }}{{ .Title }}{{ end }}</title>
{{ range .AlternativeOutputFormats -}}
{{ printf `<link rel="%s" type="%s" href="%s" title="%s" />` .Rel .MediaType.Type .Permalink $.Title | safeHTML }}
{{ end -}}
Expand Down
21 changes: 20 additions & 1 deletion layouts/_default/list.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@
{{ partialCached "header.html" . }}
{{ end }}

{{ define "title" }}
{{- if in .Page.RelPermalink "tags" -}}
{{- with .Site.Params.tagSymbol | default "#" -}}{{ . }}{{- end -}}{{ .Title | lower }}
{{- else -}}
{{ .Title }}
{{- end -}}
{{ end }}

{{ define "main" }}
<main class="site-main section-inner thin {{- if ne false .Site.Params.usesAnimation }} animated fadeIn faster{{- end -}}">
{{- if in .Page.RelPermalink "tags" -}}
<h1 class="tag">{{ .Title }}</h1>
{{- else -}}
<h1>{{ .Title }}</h1>
{{- end -}}
{{- if .Content }}
<div class="content">
{{ .Content }}
</div>
{{- end }}

{{- if and (ge (len (where .Site.Pages ".Params.pin" true)) 1) (.Site.Params.pinned) (not (in .Page.RelPermalink (or "tags" "categories"))) -}}
{{- if and (ge (len (where .Site.Pages ".Params.pin" true)) 1) (.Site.Params.pinned) (not (or (in .Page.RelPermalink "tags") (in .Page.RelPermalink "categories"))) -}}
<h2>{{- .Site.Params.pinned -}}</h2>
<div class="pinned-posts-group">
<ul class="pinned-posts-list">
Expand Down Expand Up @@ -40,6 +52,13 @@ <h2>{{- .Site.Params.pinned -}}</h2>
{{- if and .Page.Params.description .Site.Params.descriptionInPosts -}}
<span class="post-description">{{ .Page.Params.description }}</span>
{{- end -}}
{{- if and .Page.Params.tags .Site.Params.tagsInPosts -}}
<span class="post-tags">
{{- range .Page.Params.tags -}}
<a href="{{- printf "/tags/%s" . | urlize -}}" class="tag">{{- . -}}</a>
{{- end -}}
</span>
{{- end -}}
</li>
{{- end }}
</ul>
Expand Down
35 changes: 35 additions & 0 deletions layouts/_default/terms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{ define "header" }}
{{ partialCached "header.html" . }}
{{ end }}

{{ define "main" }}
<main class="site-main section-inner thin {{- if ne false .Site.Params.usesAnimation }} animated fadeIn faster{{- end -}}">
<h1>{{ .Title }}</h1>
{{- if .Content }}
<div class="content">
{{ .Content }}
</div>
{{- end }}

{{- range .Data.Terms.ByCount }}
<div class="posts-group">
<ul class="posts-list">
<li class="post-item">
<a href="{{.Page.RelPermalink}}">
{{- if in .Page.RelPermalink "tags" -}}
<span class="post-title tag">{{.Page.LinkTitle }}</span>
{{- else if in .Page.RelPermalink "categories" -}}
<span class="post-title category">{{.Page.LinkTitle}}</span>
{{- else -}}
<span class="post-title">{{.Page.LinkTitle}}</span>
{{- end -}}
<span class="post-day">{{ .Count }}</span>
</a>
</li>
</ul>
</div>
{{- end -}}
</main>
{{ end }}
{{ define "footer" }}<footer id="site-footer" class="section-inner thin {{- if ne false .Site.Params.usesAnimation }} animated fadeIn faster {{- end -}}">{{- if templates.Exists "partials/list-footer.html" -}}{{- partialCached "list-footer.html" . -}}{{- else -}}{{- partial "footer.html" . -}}{{- end -}}</footer>
{{ end }}

0 comments on commit 7d66090

Please sign in to comment.