feat: impove i18n and clean code
This commit is contained in:
@@ -1,15 +1,27 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ .Site.LanguageCode }}">
|
||||
{{ partial "head.html" . }}
|
||||
<body class="">
|
||||
<div class="wrapper">
|
||||
{{ partial "header" . }}
|
||||
<main class="main">
|
||||
<div class="container">
|
||||
{{ block "content" . }}{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ partial "footer.html" . }}
|
||||
</div>
|
||||
</body>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title>{{ block "title" . -}}{{ .Site.Title }}{{- end }}</title>
|
||||
{{ partial "head.html" . }}
|
||||
</head>
|
||||
{{ $cdn_url := ""}}
|
||||
{{ if eq ( getenv "HUGO_ENV" ) "production" }}
|
||||
{{ with .Site.Params.cdn_url }}
|
||||
{{ $cdn_url = .}}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ .Scratch.Set "cdn_url" $cdn_url }}
|
||||
<body class="">
|
||||
<div class="wrapper">
|
||||
{{ partial "header" . }}
|
||||
<main class="main">
|
||||
<div class="container">
|
||||
{{ block "content" . }}{{ end }}
|
||||
</div>
|
||||
</main>
|
||||
{{ partial "footer.html" . }}
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
{{ define "content" }}
|
||||
{{ $data := .Data }}
|
||||
<div class="post-warp archive">
|
||||
<h2 class="post-title" style="text-align:right;padding-bottom:2em">- {{ $data.Plural | humanize }}{{ .Title }} -</h2>
|
||||
{{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }}
|
||||
<h3>{{ .Key }}</h3>
|
||||
|
||||
{{ range .Pages }}
|
||||
<article class="archive-item">
|
||||
<a href="{{ .RelPermalink }}" class="archive-item-link">{{ .Title }}</a>
|
||||
<span class="archive-item-date">
|
||||
{{ .Date.Format "2 January 2006" }}
|
||||
</span>
|
||||
</article>
|
||||
{{ end }} {{ end }}
|
||||
{{ partial "paginator.html" . }}
|
||||
</div>
|
||||
{{end }}
|
||||
@@ -1,18 +0,0 @@
|
||||
{{ define "content" }}
|
||||
{{ $data := .Data }}
|
||||
<div class="post-warp archive">
|
||||
<h2 class="post-title" style="text-align:right;padding-bottom:2em">- {{ $data.Plural | humanize }}{{ .Title }} -</h2>
|
||||
{{ range (.Paginate (.Pages.GroupByDate "2006")).PageGroups }}
|
||||
<h3>{{ .Key }}</h3>
|
||||
|
||||
{{ range .Pages }}
|
||||
<article class="archive-item">
|
||||
<a href="{{ .RelPermalink }}" class="archive-item-link">{{ .Title }}</a>
|
||||
<span class="archive-item-date">
|
||||
{{ .Date.Format "2 January 2006" }}
|
||||
</span>
|
||||
</article>
|
||||
{{ end }} {{ end }}
|
||||
{{ partial "paginator.html" . }}
|
||||
</div>
|
||||
{{end }}
|
||||
@@ -1,112 +0,0 @@
|
||||
{{ define "content" -}}
|
||||
{{ $cdn_url := .Scratch.Get "cdn_url" }}
|
||||
<article class="post-warp">
|
||||
<header class="post-header">
|
||||
<h1 class="post-title">{{ .Title }}</h1>
|
||||
<div class="post-meta">
|
||||
{{ i18n "Written" }} {{ i18n "by" }} <a href="{{.Site.BaseURL }}" rel="author">{{ if isset .Params "author" }}{{ .Params.author }}{{ else }}{{ .Site.Params.author }}{{ end }}</a> {{ i18n "with" }} ♥
|
||||
<span class="post-time">
|
||||
{{ i18n "on" }} <time datetime={{.Date.Format (.Site.Params.dateFormatToUse | default "2006-01-02") }} >{{ .Date.Format (.Site.Params.dateFormatToUse | default "2 January 2006") }}</time>
|
||||
</span>
|
||||
{{ i18n "in" }}
|
||||
{{ with .Params.categories -}}
|
||||
<i class="iconfont icon-folder"></i>
|
||||
<span class="post-category">
|
||||
{{ range . }}
|
||||
{{- $name := . -}}
|
||||
{{- with $.Site.GetPage "taxonomy" (printf "categories/%s" $name) | default ($.Site.GetPage "taxonomy" (printf "categories/%s" ($name | urlize))) -}}
|
||||
<a href="{{ .Permalink }}"> {{ $name }} </a>
|
||||
{{ end -}}
|
||||
{{ end }}
|
||||
</span>
|
||||
{{- end }}
|
||||
<i class="iconfont icon-timer"></i>
|
||||
{{.ReadingTime }} min
|
||||
</div>
|
||||
</header>
|
||||
<div class="post-content">
|
||||
<!--featured_image-->
|
||||
|
||||
{{ $images := findRE "<img src=\"[^\"|\\\"]*\"" .Content -}}
|
||||
{{ if ge (len $images) 1}}
|
||||
{{ $.Scratch.Set "postHasImages" true }}
|
||||
{{ end }}
|
||||
|
||||
{{ with .Params.featured_image }}
|
||||
{{- $img := . -}}
|
||||
<img src="{{ printf "%s%s" $cdn_url $img }}" class="featured_image">
|
||||
{{ end }}
|
||||
<!-- end featured_image-->
|
||||
|
||||
{{ $reAltIn := "<img src=\"([^\"]+)\" alt=\"([^\"]+)?\" />" }}
|
||||
{{ $reAltOut := ( printf "<figure><img src=\"/images/ring.svg\" data-sizes=\"auto\" data-src=\"%s$1\" alt=\"$2\" class=\"lazyload\"><figcaption class=\"image-caption\">$2</figcaption></figure>" $cdn_url ) }}
|
||||
{{ $altContent := .Content | replaceRE $reAltIn $reAltOut | safeHTML }}
|
||||
|
||||
{{ $reAltTitleIn := "<img src=\"([^\"]+)\" alt=\"([^\"]+)?\" title=\"([^\"]+)?\" />" }}
|
||||
{{ $reAltTitleOut := ( printf "<figure><img src=\"/images/ring.svg\" data-src=\"%s$1\" data-sizes=\"auto\" alt=\"$2\" title=\"$3\" class=\"lazyload\"><figcaption class=\"image-caption\">$2</figcaption></figure>" $cdn_url ) }}
|
||||
{{ $finalContent := $altContent | replaceRE $reAltTitleIn $reAltTitleOut | safeHTML }}
|
||||
|
||||
{{ $finalContent }}
|
||||
</div>
|
||||
|
||||
<div class="post-copyright">
|
||||
{{ with .Site.Params.author }}
|
||||
<p class="copyright-item">
|
||||
<span>{{ i18n "Author" }}:</span>
|
||||
<span>{{ . }} </span>
|
||||
</p>
|
||||
{{ end }}
|
||||
|
||||
<p class="copyright-item">
|
||||
<span>{{ i18n "Words" }}:</span>
|
||||
<span>{{ .WordCount }}</span>
|
||||
</p>
|
||||
|
||||
<p class="copyright-item">
|
||||
{{ if and ( $.Param "socialShare" ) (gt (len ($.Param "share")) 0) }}
|
||||
<span>{{ i18n "Share" }}:</span>
|
||||
<span>{{ partial "share-links" . }}</span>
|
||||
{{ end }}
|
||||
</p>
|
||||
|
||||
{{ with .Site.Params.license }}
|
||||
<p class="copyright-item">
|
||||
{{ . | safeHTML}}
|
||||
</p>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<div class="post-tags">
|
||||
{{ with .Params.tags }}
|
||||
<section>
|
||||
<i class="iconfont icon-icon-tag"></i>{{ i18n "Tag" }}:
|
||||
{{ range . }}
|
||||
<span class="tag">
|
||||
<a href="{{ "tags/" | absURL }}{{ . | urlize }}/">#{{.}}</a>
|
||||
</span>
|
||||
{{ end }}
|
||||
</section>
|
||||
{{ end }}
|
||||
<section>
|
||||
<a href="javascript:window.history.back();">{{ i18n "back" }}</a></span> ·
|
||||
<span><a href="{{ .Site.BaseURL }}">{{ i18n "Home" }}</a></span>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="post-nav">
|
||||
{{ if .PrevInSection }}
|
||||
<a href="{{.PrevInSection.Permalink}}" class="prev" rel="prev" title="{{ .PrevInSection.Title}}"><i class="iconfont icon-dajiantou"></i> {{ .PrevInSection.Title}}</a>
|
||||
{{ end }}
|
||||
{{ if .NextInSection }}
|
||||
<a href="{{.NextInSection.Permalink}}" class="next" rel="next" title="{{.NextInSection.Title}}">{{.NextInSection.Title}} <i class="iconfont icon-xiaojiantou"></i></a>
|
||||
{{ end }}
|
||||
</div>
|
||||
|
||||
<div class="post-comment">
|
||||
{{ if ( .Params.showComments | default true ) }}
|
||||
{{ partial "comments" . }}
|
||||
{{ end }}
|
||||
</div>
|
||||
</article>
|
||||
{{- end }}
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
{{ define "content" }}
|
||||
|
||||
{{ $termName := .Data.Plural }}
|
||||
{{ $terms := .Data.Terms.ByCount }}
|
||||
{{ $length := len $terms }}
|
||||
{{ $type := .Type }}
|
||||
<!-- Categories Page -->
|
||||
<div class="post-warp {{.Data.Plural}}">
|
||||
<h2 class="post-title" style="text-align:right;padding-bottom:2em">- {{ .Data.Plural | humanize }} -</h2>
|
||||
{{ if and $.Site.Taxonomies.categories (eq $termName "categories") }}
|
||||
|
||||
<div class="categories-card">
|
||||
{{ range $terms }}
|
||||
{{ $term := .Term }}
|
||||
{{ $pages := .Pages }}
|
||||
{{ with $.Site.GetPage "taxonomy" (printf "%s/%s" $type $term) }}
|
||||
<div class="card-item">
|
||||
<div class="categories" >
|
||||
<a href="{{ .Permalink }}"><h3> <i class="iconfont icon-folder" style="padding-right: 3px"></i> {{ $term | humanize}} </h3> </a>
|
||||
{{ range first 5 $pages }}
|
||||
<article class="archive-item">
|
||||
<a href="{{ .Permalink }}" class="archive-item-link">{{ .Title }}</a>
|
||||
</article>
|
||||
{{ end }}
|
||||
{{ if gt (len $pages) 5 }}
|
||||
<span class="more-post">
|
||||
<a href="{{ .Permalink }}" class="more-post-link">{{ i18n "More" }} >></a>
|
||||
</span>
|
||||
{{ end }}
|
||||
</div>
|
||||
</div>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div> <!-- //categories-card -->
|
||||
<!-- Tag cloud Page -->
|
||||
{{ else if and $.Site.Taxonomies.tags (eq $termName "tags") }}
|
||||
<div class="tag-cloud-tags">
|
||||
{{ range $.Site.Taxonomies.tags.ByCount }}
|
||||
{{ if .Name }}
|
||||
<a href="/tags/{{ .Name | urlize}}/"> {{ .Name }} <small>({{ .Count }})</small></a>
|
||||
{{ end }}
|
||||
{{end}}
|
||||
</div>
|
||||
|
||||
{{ end }}
|
||||
</div>
|
||||
{{end }}
|
||||
Reference in New Issue
Block a user