blob: 5760ad2bf3e613acb7aa9e692b48df4c06ef3bd6 [file] [log] [blame]
<div class="tags-wrapper">
<div class="font-weight-bold post-meta ">
<i class="fas fa-tags pr-1" aria-hidden="true"></i>
Tags
</div>
<ul class="tags-box">
{{ range $key, $taxonomy := .Site.Taxonomies.tags }}
{{ if (where $taxonomy.Pages "Section" "blog") }}
<li class="blog dn" data-type="blog">
<a href="{{ .Page.Permalink }}" class="tag-link">{{ .Page.Title }}</a>
<span class="count">{{ .Count }}</span>
</li>
{{ end }}
{{ if (where $taxonomy.Pages "Section" "zh") }}
<li class="zh dn" data-type="zh">
<a href="{{ .Page.Permalink }}" class="tag-link">{{ .Page.Title }}</a>
<span class="count">{{ .Count }}</span>
</li>
{{ end }}
{{ end }}
</ul>
</div>
<script>
$(function () {
initTags();
bindClick();
function initTags() {
var type = getTye()
switch (type) {
case 'blog':
$('.tags-box .blog').show();
replaceState('blog')
break;
case 'zh':
$('.tags-box .zh').show();
replaceState('zh')
break;
default:
$('.tags-box li').show();
}
}
function bindClick() {
$('.tag-link').on('click', function (e) {
e.preventDefault()
var type = getQueryValue('type')
var url = $(this).attr('href')
window.location.href = url + '?type=' + type;
})
}
function getTye() {
var type = getQueryValue('type')
if (type) {
return type
}
var oldURL = document.referrer;
if (oldURL.indexOf('/blog/') > -1) {
return 'blog'
} else if (oldURL.indexOf('/zh/') > -1) {
return 'zh'
}
}
function replaceState(param) {
var newurl = updateQueryStringParameter(window.location.href, 'type', param);
window.history.replaceState({
path: newurl
}, '', newurl);
}
function updateQueryStringParameter(uri, key, value) {
if (!value) {
return uri;
}
var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
var separator = uri.indexOf('?') !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, '$1' + key + "=" + value + '$2');
} else {
return uri + separator + key + "=" + value;
}
}
function getQueryValue(queryName) {
var reg = new RegExp("(^|&)" + queryName + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return decodeURI(r[2]);
} else {
return null;
}
}
})
</script>