Fix blog-relative links

This commit is contained in:
Jan-Lukas Else 2020-10-12 19:26:32 +02:00
parent 43cd803342
commit 83253f03c4
4 changed files with 12 additions and 4 deletions

View File

@ -77,6 +77,12 @@ func initRendering() error {
},
"urlize": urlize,
"sort": sortedStrings,
"blogRelative": func(blog *configBlog, path string) string {
if blog.Path != "/" {
return blog.Path + path
}
return path
},
}
templates = make(map[string]*template.Template)

View File

@ -1,6 +1,6 @@
{{ define "header" }}
<header>
<h1><a href="/" rel="home" title="{{ .Blog.Title }}">{{ .Blog.Title }}</a></h1>
<h1><a href="{{ blogRelative .Blog "/" }}" rel="home" title="{{ .Blog.Title }}">{{ .Blog.Title }}</a></h1>
{{ with .Blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
{{ include "menu" .Blog .Data }}
</header>

View File

@ -15,12 +15,13 @@
{{ end }}
</article>
{{ $post := .Data }}
{{ range $i, $tax := .Blog.Taxonomies }}
{{ $blog := .Blog }}
{{ range $i, $tax := $blog.Taxonomies }}
{{ $tvs := ps $post $tax.Name }}
{{ if gt (len $tvs) 0 }}
<p>In <b>{{ $tax.Title }}</b>:
{{ range $j, $tv := $tvs }}
<a href="/{{ $tax.Name }}/{{ urlize $tv }}">{{ $tv }}</a>
<a href="{{ blogRelative $blog ( printf "/%s/%s" $tax.Name (urlize $tv) ) }}">{{ $tv }}</a>
{{ end }}
</p>
{{ end }}

View File

@ -7,9 +7,10 @@
{{ with .Data.Taxonomy.Title }}<h1>{{ . }}</h1>{{ end }}
{{ with .Data.Taxonomy.Description }}{{ md . }}{{ end }}
<ul>
{{ $blog := .Blog }}
{{ $taxonomy := .Data.Taxonomy.Name }}
{{ range $i, $value := (sort .Data.TaxonomyValues) }}
<li><a href="/{{ $taxonomy }}/{{ urlize . }}">{{ . }}</a></li>
<li><a href="{{ blogRelative $blog ( printf "/%s/%s" $taxonomy (urlize .) ) }}">{{ . }}</a></li>
{{ end }}
</ul>
</main>