Make links language-relative

This ensures that links work correctly in languages other than
English. For example, clicking on the navbar "brand" link used to
take you to the English home page even if you were browsing the
site in another language. Now it takes you to the home page for
that language.
This commit is contained in:
Jack Taylor 2017-04-07 08:01:06 +09:00
parent 655c2011fe
commit c4cfe47e01
6 changed files with 12 additions and 12 deletions

View File

@ -53,7 +53,7 @@
{{ if .Params.tags }}
<span class="post-meta">
{{ range .Params.tags }}
#<a href="/tags/{{ . | urlize }}">{{ . }}</a>&nbsp;
#<a href="{{ $.Site.LanguagePrefix }}/tags/{{ . | urlize }}">{{ . }}</a>&nbsp;
{{ end }}
</span>
{{ end }}

View File

@ -14,7 +14,7 @@
<article class="post-preview">
<div class="list-group col-lg-4 col-lg-offset-4 col-md-6 col-md-offset-3">
{{ range $key, $value := .Data.Terms.ByCount }}
<a href="/{{ $data.Plural }}/{{ $value.Name | urlize }}" class="list-group-item">
<a href="{{ $.Site.LanguagePrefix }}/{{ $data.Plural }}/{{ $value.Name | urlize }}" class="list-group-item">
{{ $value.Name }}<span class="badge">{{ $value.Count }}</span></a>
{{ end }}
</div>

View File

@ -45,7 +45,7 @@
{{ if .Params.tags }}
<span class="post-meta">
{{ range .Params.tags }}
#<a href="/tags/{{ . | urlize }}">{{ . }}</a>&nbsp;
#<a href="{{ $.Site.LanguagePrefix }}/tags/{{ . | urlize }}">{{ . }}</a>&nbsp;
{{ end }}
</span>
{{ end }}

View File

@ -17,7 +17,7 @@
{{ end }}
{{ if .Site.Params.rss }}
<li>
<a href="{{ .Site.BaseURL}}/index.xml" title="RSS">
<a href="{{ "/index.xml" | absLangURL }}" title="RSS">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-rss fa-stack-1x fa-inverse"></i>
@ -33,7 +33,7 @@
{{ if .Site.Title }}
&nbsp;&bull;&nbsp;
<a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a>
<a href="{{ "/" | absLangURL }}">{{ .Site.Title }}</a>
{{ end }}
</p>
<!-- Please don't remove this, keep my open source work credited :) -->

View File

@ -36,8 +36,8 @@
<!-- Hugo Version number -->
{{ .Hugo.Generator -}}
<!-- Links and stylesheets -->
<link rel="canonical" href="{{ .URL | absURL }}" />
<link rel="alternate" href="{{ "/index.xml" | absURL }}" type="application/rss+xml" title="{{ .Site.Title }}">
<link rel="canonical" href="{{ .URL | absLangURL }}" />
<link rel="alternate" href="{{ "/index.xml" | absLangURL }}" type="application/rss+xml" title="{{ .Site.Title }}">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.7.1/katex.min.css" integrity="sha384-wITovz90syo1dJWVh32uuETPVEtGigN07tkttEqPv+uR2SE/mbQcG7ATL28aI9H0" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

View File

@ -7,7 +7,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a>
<a class="navbar-brand" href="{{ "/" | absLangURL }}">{{ .Site.Title }}</a>
</div>
<div class="collapse navbar-collapse" id="main-navbar">
@ -18,13 +18,13 @@
<a class="navlinks-parent" href="javascript:void(0)">{{ .Name }}</a>
<div class="navlinks-children">
{{ range .Children }}
<a href="{{ .URL }}">{{ .Name }}</a>
<a href="{{ .URL | relLangURL }}">{{ .Name }}</a>
{{ end }}
</div>
</li>
{{ else }}
<li>
<a title="{{ .Name }}" href="{{ .URL }}">{{ .Name }}</a>
<a title="{{ .Name }}" href="{{ .URL | relLangURL }}">{{ .Name }}</a>
</li>
{{ end }}
{{ end }}
@ -65,7 +65,7 @@
<div class="avatar-container">
<div class="avatar-img-border">
{{ if isset .Site.Params "logo" }}
<a title="{{ .Site.Title }}" href="{{ .Site.BaseURL }}">
<a title="{{ .Site.Title }}" href="{{ "/" | absLangURL }}">
<img class="avatar-img" src="{{ .Site.BaseURL }}/{{ .Site.Params.logo }}" alt="{{ .Site.Title }}" />
</a>
{{ end }}