diff options
author | wlh233 <wlh233@live.com> | 2020-11-13 18:07:41 +0300 |
---|---|---|
committer | wlh233 <wlh233@live.com> | 2020-11-13 18:07:41 +0300 |
commit | ab9efea0dc0d0eb0202421aab978d8b54b5dac3b (patch) | |
tree | 4e133abd297ba1f7d74696a100af0466a51b1e83 /layouts |
first commit
Diffstat (limited to 'layouts')
-rw-r--r-- | layouts/404.html | 31 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 16 | ||||
-rw-r--r-- | layouts/_default/list.html | 4 | ||||
-rw-r--r-- | layouts/_default/single.html | 17 | ||||
-rw-r--r-- | layouts/_default/taxonomy.html | 35 | ||||
-rw-r--r-- | layouts/archives/single.html | 41 | ||||
-rw-r--r-- | layouts/index.html | 1 | ||||
-rw-r--r-- | layouts/partials/anchor.html | 9 | ||||
-rw-r--r-- | layouts/partials/backtotop.html | 12 | ||||
-rw-r--r-- | layouts/partials/footer.html | 9 | ||||
-rw-r--r-- | layouts/partials/head.html | 51 | ||||
-rw-r--r-- | layouts/partials/header.html | 14 | ||||
-rw-r--r-- | layouts/partials/highlight.html | 29 | ||||
-rw-r--r-- | layouts/partials/math.html | 32 | ||||
-rw-r--r-- | layouts/partials/nav.html | 44 | ||||
-rw-r--r-- | layouts/partials/paginator.html | 27 | ||||
-rw-r--r-- | layouts/partials/post.html | 63 | ||||
-rw-r--r-- | layouts/partials/posts.html | 87 | ||||
-rw-r--r-- | layouts/partials/toc.html | 22 |
19 files changed, 544 insertions, 0 deletions
diff --git a/layouts/404.html b/layouts/404.html new file mode 100644 index 0000000..a8bb465 --- /dev/null +++ b/layouts/404.html @@ -0,0 +1,31 @@ +<!DOCTYPE html> +<html> +{{- partial "head.html" . -}} + +<body> + <div id="main"> + <!-- {{- partial "nav.html" . -}} --> + <!-- {{- partial "header.html" . -}} --> + {{- block "404-main" . }}{{- end }} + </div> + <!-- {{- partial "footer.html" . -}} --> + <!-- {{- partial "backtotop.html" . -}} --> + <!-- {{- block "script" . }}{{- end }} --> +</body> + +</html> +{{ define "404-main" }} +<article class="message is-primary is-large"> + <div class="message-header"> + <p>404 Page Not Found</p> + </div> + <div class="message-body"> + 没找到该页面,请检查 url 或 <a href="/">返回首页</a> + </div> +</article> +<style> + .subtitle a { + text-decoration: underline; + } +</style> +{{ end }} diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html new file mode 100644 index 0000000..fbf3fab --- /dev/null +++ b/layouts/_default/baseof.html @@ -0,0 +1,16 @@ +<!DOCTYPE html> +<html> +{{- partial "head.html" . -}} + +<body> + <div id="main"> + {{- partial "nav.html" . -}} + <!-- {{- partial "header.html" . -}} --> + {{- block "main" . }}{{- end }} + </div> + {{- partial "footer.html" . -}} + {{- partial "backtotop.html" . -}} + {{- block "script" . }}{{- end }} +</body> + +</html> diff --git a/layouts/_default/list.html b/layouts/_default/list.html new file mode 100644 index 0000000..62f5e5d --- /dev/null +++ b/layouts/_default/list.html @@ -0,0 +1,4 @@ +{{ define "main" }} +{{- partial "header.html" . -}} +{{- partial "posts.html" . -}} +{{ end }} diff --git a/layouts/_default/single.html b/layouts/_default/single.html new file mode 100644 index 0000000..048b788 --- /dev/null +++ b/layouts/_default/single.html @@ -0,0 +1,17 @@ +{{ define "main" }} + {{- partial "post.html" . -}} +{{ end }} + +{{ define "script" }} + <!-- following is js part --> + {{- partial "highlight.html" . -}} + {{- partial "anchor.html" . -}} + + {{ if or .Params.math .Site.Params.math }} + {{- partial "math.html" . -}} + {{ end }} + + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + {{- partial "toc.html" . -}} + {{ end }} +{{ end }} diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html new file mode 100644 index 0000000..a528fe6 --- /dev/null +++ b/layouts/_default/taxonomy.html @@ -0,0 +1,35 @@ +{{ define "main" }} +{{- partial "header.html" . -}} +<!-- {{- partial "posts.html" . -}} --> +<section class="section"> + <div class="container"> + <div class="content"> + {{ if eq .Data.Singular "category" }} + <h3> + 分类 + <span class="tag mytag">{{ .Data.Term }}</span> + 中的文章 + </h3> + {{ else if eq .Data.Singular "tag" }} + <h3> + 包含标签 + <span class="tag mytag"><a>{{ .Data.Term }}</a></span> + 的文章 + </h3> + {{ end }} + </div> + <div class="post-lists"> + {{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} + {{ range $paginator.Pages }} + <div class="one-post box"> + <div class="is-6">{{ .Date.Format "2006/01/02" }}</div> + <div><a href="{{.Permalink }}" class="title is-size-5">{{ .Title }}</a></div> + </div> + {{ end }} + {{ partial "paginator.html" . }} + </div> + + </div> +</section> + +{{ end }} diff --git a/layouts/archives/single.html b/layouts/archives/single.html new file mode 100644 index 0000000..18ce343 --- /dev/null +++ b/layouts/archives/single.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +{{- partial "head.html" . -}} + +<body> + <div id="main"> + {{- partial "nav.html" . -}} + {{- partial "header.html" . -}} + <section class="section"> + {{- block "archives-main" . }}{{- end }} + </section> + </div> + {{- partial "footer.html" . -}} + {{- partial "backtotop.html" . -}} + {{- block "script" . }}{{- end }} +</body> + +</html> + +{{ define "archives-main" }} +<div class="container"> + <div class="box section"> + <div class="content"> + <p>本博客共 {{len (where (where .Site.Pages "Type" "post") "Kind" "page")}} 篇博文</p> + <div class="post-archive"> + {{ range (where (where .Site.Pages "Type" "post") "Kind" "page").GroupByDate "2006" }} + <h2>{{ .Key }}</h2> + <ul class="listing"> + {{ range .Pages }} + <li> + <span class="date">{{ .Date.Format "2006/01/02" }} </span> + <a href="{{ .Permalink }}" title="{{ .Title }}">{{ .Title }}</a> + </li> + {{ end }} + </ul> + {{ end }} + </div> + </div> + </div> +</div> +{{ end }} diff --git a/layouts/index.html b/layouts/index.html new file mode 100644 index 0000000..ca7abab --- /dev/null +++ b/layouts/index.html @@ -0,0 +1 @@ +{{ with .GetPage "/post" }}{{.Render}}{{end}} diff --git a/layouts/partials/anchor.html b/layouts/partials/anchor.html new file mode 100644 index 0000000..038babd --- /dev/null +++ b/layouts/partials/anchor.html @@ -0,0 +1,9 @@ +<script src="/js/anchor.min.js"></script> +<script> + anchors.options = { + placement: 'left', + // visible: 'always', + icon: '#' + }; + anchors.add('.content h1, .content h2, .content h3'); +</script> diff --git a/layouts/partials/backtotop.html b/layouts/partials/backtotop.html new file mode 100644 index 0000000..47c5657 --- /dev/null +++ b/layouts/partials/backtotop.html @@ -0,0 +1,12 @@ +<script src="/js/vanilla-back-to-top.min.js"></script> +<script> +addBackToTop({ + diameter: 42, +{{ if .Site.Params.primaryColor }} + backgroundColor: {{ .Param "primaryColor" }}, +{{end}} + + innerHTML: '<svg viewBox="0 0 24 24"><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/></svg>', + textColor: '#fff' +}); +</script> diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html new file mode 100644 index 0000000..da744c0 --- /dev/null +++ b/layouts/partials/footer.html @@ -0,0 +1,9 @@ +<footer class="footer"> + <div class="content has-text-centered"> + <p>Powered by <a href="https://gohugo.io">Hugo</a>. Theme <a href="https://www.github.com/wlh320/hugo-theme-hulga">Hulga</a></p> + <p> + {{ .Site.Params.copyright }} + </p> + </div> +</footer> +{{ template "_internal/google_analytics_async.html" . }} diff --git a/layouts/partials/head.html b/layouts/partials/head.html new file mode 100644 index 0000000..de32ad1 --- /dev/null +++ b/layouts/partials/head.html @@ -0,0 +1,51 @@ +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + {{ if .IsHome -}} + <title>{{ .Site.Title }} | {{ .Site.Params.subtitle}}</title> + <meta property="og:title" content="{{ .Site.Title }} | {{ .Site.Params.subtitle}}"> + <meta property="og:type" content="website"> + {{ if .Site.Params.keywords }} + <meta name="Keywords" content="{{.Site.Params.keywords}}"> + {{ end }} + {{ if .Site.Params.keywords }} + <meta name="description" content="{{ .Site.Params.description }}"> + {{ end }} + {{- else -}} + <title>{{ .Title }} | {{ .Site.Title }}</title> + <meta property="og:title" content="{{ .Title }} - {{ .Site.Title }}"> + <meta property="og:type" content="article"> + {{ with .Params.date }} + <meta property="article:published_time" content="{{ .Format "2006-01-02T15:04:05+08:00" }}"> + {{ end }} + {{ with .Params.lastmod }} + <meta property="article:modified_time" content="{{ .Format "2006-01-02T15:04:05+08:00" }}"> + {{ end }} + <meta name="Keywords" content="{{ if .Keywords }}{{ .Keywords }}{{ else }}{{ .Site.Params.keywords }}{{ end }}"> + <meta name="description" content="{{ if .Description }}{{ .Description }}{{ else }}{{ .Title }}{{ end }}"> + {{ if .Params.author -}} + <meta name="author" content="{{ .Params.author }}"> + {{- end }} + {{- end }} + + {{ $options := (dict "outputStyle" "compressed" "includePaths" (slice "sass")) }} + {{ $lightScss := resources.Get "css/hulga.scss" }} + {{ $darkScss := resources.Get "css/hulga-dark.scss" }} + {{ if .Site.Params.postcss }} + {{ $light := $lightScss | resources.ExecuteAsTemplate "css/hulga.scss" . | resources.ToCSS $options | postCSS | resources.Minify }} + <link rel="stylesheet" type="text/css" href="{{ $light.Permalink | relURL }}"> + {{ if .Site.Params.darkMedia }} + {{ $dark := $darkScss | resources.ExecuteAsTemplate "css/hulga-dark.scss" . | resources.ToCSS $options | postCSS | resources.Minify }} + <link rel="stylesheet" type="text/css" href="{{ $dark.Permalink | relURL }}" media="(prefers-color-scheme: dark)"> + {{ end }} + {{ else }} + {{ $light := $lightScss | resources.ExecuteAsTemplate "css/hulga.scss" . | resources.ToCSS $options }} + <link rel="stylesheet" type="text/css" href="{{ $light.Permalink | relURL }}"> + {{ if .Site.Params.darkMedia }} + {{ $dark := $darkScss | resources.ExecuteAsTemplate "css/hulga-dark.scss" . | resources.ToCSS $options }} + <link rel="stylesheet" type="text/css" href="{{ $dark.Permalink | relURL }}" media="(prefers-color-scheme: dark)"> + {{ end }} + {{ end }} + +</head> diff --git a/layouts/partials/header.html b/layouts/partials/header.html new file mode 100644 index 0000000..2baa402 --- /dev/null +++ b/layouts/partials/header.html @@ -0,0 +1,14 @@ +<section class="hero is-primary shadow-hero"> + <div class="hero-body"> + <div class="container has-text-centered"> + <h1 class="title"> + {{ .Site.Title }} + </h1> + {{ if .Site.Params.subtitle }} + <h2 class="subtitle"> + {{ .Site.Params.subtitle }} + </h2> + {{ end }} + </div> + </div> +</section> diff --git a/layouts/partials/highlight.html b/layouts/partials/highlight.html new file mode 100644 index 0000000..b7bbc76 --- /dev/null +++ b/layouts/partials/highlight.html @@ -0,0 +1,29 @@ +<link id="hlcss" rel="stylesheet" type="text/css"> + +<script> + function addCss(url) { + var link = document.getElementById('hlcss'); + link.href = url; + } + {{ if .Site.Params.darkMedia }} + var darkcss = '/css/monokai.css' + {{ else }} + var darkcss = '/css/monokailight.css' + {{ end }} + var lightcss = '/css/monokailight.css' + // load syntax css + if (window.matchMedia('(prefers-color-scheme)').media === 'not all') { + // alert('Browser doesn\'t support dark mode'); + addCss(lightcss); + } else if (window.matchMedia("(prefers-color-scheme: dark)").matches) { + addCss(darkcss); + } else { + addCss(lightcss); + } + window.matchMedia("(prefers-color-scheme: dark)").addListener( + e => e.matches && addCss(darkcss) + ); + window.matchMedia("(prefers-color-scheme: light)").addListener( + e => e.matches && addCss(lightcss) + ); +</script> diff --git a/layouts/partials/math.html b/layouts/partials/math.html new file mode 100644 index 0000000..02a521c --- /dev/null +++ b/layouts/partials/math.html @@ -0,0 +1,32 @@ +<link rel="stylesheet" href="/css/katex.min.css"> +<script defer src="/js/katex.min.js"></script> +<script defer src="/js/auto-render.min.js"></script> +<script> + document.addEventListener("DOMContentLoaded", function () { + renderMathInElement(document.body, { + // ...options... + delimiters: [{ + left: "$$", + right: "$$", + display: true + }, + { + left: "\\[", + right: "\\]", + display: true + }, + { + left: "$", + right: "$", + display: false + }, + { + left: "\\(", + right: "\\)", + display: false + } + ] + + }); + }); +</script> diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html new file mode 100644 index 0000000..350ce32 --- /dev/null +++ b/layouts/partials/nav.html @@ -0,0 +1,44 @@ +<nav class="navbar is-primary"> + <div class="navbar-brand"> + <a class="navbar-item {{if eq .Kind "home"}}fake-text{{end}}" href="/"> + {{.Site.Title}} + </a> + <a role="button" class="navbar-burger" data-target="navMenu" aria-label="menu" aria-expanded="false"> + <span aria-hidden="true"></span> + <span aria-hidden="true"></span> + <span aria-hidden="true"></span> + </a> + </div> + <!-- <div class="container"> --> + <div class="navbar-menu" id="navMenu"> + <div class="navbar-end"> + {{ range .Site.Menus.main.ByWeight -}} + {{ .Pre }} + <a class="navbar-item" href="{{ .URL }}" title="{{ .Identifier }}">{{- .Name -}}</a> + {{ .Post }} + {{- end }} + </div> + </div> + <!-- </div> --> +</nav> +<script type="text/javascript"> + // bulma's navbar-burger toggle button + document.addEventListener('DOMContentLoaded', () => { + // Get all "navbar-burger" elements + const $navbarBurgers = Array.prototype.slice.call(document.querySelectorAll('.navbar-burger'), 0); + // Check if there are any navbar burgers + if ($navbarBurgers.length > 0) { + // Add a click event on each of them + $navbarBurgers.forEach(el => { + el.addEventListener('click', () => { + // Get the target from the "data-target" attribute + const target = el.dataset.target; + const $target = document.getElementById(target); + // Toggle the "is-active" class on both the "navbar-burger" and the "navbar-menu" + el.classList.toggle('is-active'); + $target.classList.toggle('is-active'); + }); + }); + } + }); +</script> diff --git a/layouts/partials/paginator.html b/layouts/partials/paginator.html new file mode 100644 index 0000000..95e9ee5 --- /dev/null +++ b/layouts/partials/paginator.html @@ -0,0 +1,27 @@ +{{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} +{{ with $paginator }} + +{{ if gt .TotalPages 1 }} +<nav class="pagination is-centered" role="navigation" aria-label="pagination"> + {{ if .HasPrev }} + <a class="pagination-previous" href="{{ .Prev.URL }}">上一页</a> + {{ end }} + + {{ if .HasNext }} + <a class="pagination-next" href="{{ .Next.URL }}">下一页</a> + {{ end }} + + {{ if lt .TotalPages 20 }} + <ul class="pagination-list"> + {{ range .Pagers }} + <li> + <a class="pagination-link {{ if eq .PageNumber $.Paginator.PageNumber }}is-current{{ end }}" + href="{{ .URL }}">{{ .PageNumber }}</a> + </li> + {{ end }} + </ul> + {{ end }} +</nav> +{{ end }} + +{{ end }} diff --git a/layouts/partials/post.html b/layouts/partials/post.html new file mode 100644 index 0000000..554b9c7 --- /dev/null +++ b/layouts/partials/post.html @@ -0,0 +1,63 @@ +<section class="hero is-primary shadow-hero"> + <div class="hero-body"> + <header class="container has-text-centered"> + <h1 class="title post-title"> + {{ .Title }} + </h1> + <h2 class="subtitle"> + {{- if isset .Params "date" -}} + <time class="post-meta">{{ .Date.Format "2006/01/02" }}</time> + {{- end -}} + {{ with .Params.Categories }} ・ + {{ range .}} + <span class="post-tag post-meta"> + <a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> + </span> + {{ end }} + {{ end }} + </h2> + {{ with .Params.tags }} + <div class="tagbox post-meta"> + {{ range . }} + <span class="post-tag"> + <a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">#{{ . }}</a> + </span> + {{ end }} + <!-- <span class="post-tag">#Hello</span><span class="post-tag">#Hello</span> --> + </div> + {{ end }} + </header> + </div> +</section> +<section class="section"> + <div class="container"> + <div class="columns"> + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + <div class="column is-three-quarters"> + {{ else }} + <div class="column is-1"></div> + <div class="column is-10"> + {{ end }} + <article class="content" id="post-content"> + {{- .Content -}} + </article> + </div> + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + <div class="column is-hidden-mobile"> + <div class="sidebar" id="toc"> + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + <div class="post post-toc" id="post-toc"> + <!-- render by tocbot --> + </div> + {{- end }} + </div> + </div> + {{ end }} + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + {{ else }} + <div class="column is-1"></div> + {{ end }} + </div> + </div> + </div> +</section> diff --git a/layouts/partials/posts.html b/layouts/partials/posts.html new file mode 100644 index 0000000..50ea716 --- /dev/null +++ b/layouts/partials/posts.html @@ -0,0 +1,87 @@ +<section class="section"> + <div class="container"> + <div class="columns"> + <div class="column is-two-thirds"> + <div class="post-lists"> + {{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} + {{ range $paginator.Pages }} + <div class="box post-box"> + {{ with .Params.Tags }} + <div class="post-box-tags"> + {{ range .}} + <span class="post-tag post-box-tag"> + <a href="{{ "/tags/" | relLangURL }}{{ . | urlize }}">#{{ . }}</a> + </span> + {{ end }} + </div> + {{ end }} + <div class="post-box-title"> + <a href="{{.Permalink }}" class="title is-size-5">{{ .Title }}</a> + </div> + <div class="post-box-meta"> + {{ .Date.Format "2006/01/02" }} + {{ with .Params.Categories }} ・ + {{ range .}} + <span class="post-tag post-box-category"> + <a href="{{ "/categories/" | relLangURL }}{{ . | urlize }}">{{ . }}</a> + </span> + {{ end }} + {{ end }} + </div> + </div> + {{ end }} + </div> + <div style="padding-top: 1.5rem;"> + {{ partial "paginator.html" . }} + </div> + </div> + + <div class="column is-one-third is-hidden-mobile"> + {{ if .Site.Taxonomies.categories }} + <div class="card"> + <header class="card-header is-primary"> + <p class="card-header-title"> + 分类 + </p> + </header> + <div class="card-content"> + <div class="content"> + {{ range $name, $taxonomy := .Site.Taxonomies.categories }} + <div class="container" style="margin-bottom: 0.5rem"> + <a href="{{ "/categories/" | relLangURL }}{{ $name | urlize }}">{{ $name }}</a> + <span class="tag is-pulled-right"> + {{ $taxonomy.Count }} + </span> + </div> + {{ end }} + + </div> + </div> + </div> + <br> + {{ end }} + + {{ if .Site.Taxonomies.tags }} + <div class="card"> + <header class="card-header"> + <p class="card-header-title"> + 标签 + </p> + </header> + <div class="card-content"> + <div class="content"> + <div class="tags"> + {{ range $name, $taxonomy := .Site.Taxonomies.tags }} + <span class="tag"> + <a href="{{ "/tags/" | relLangURL }}{{ $name | urlize }}/">{{ $name }}</a> + </span> + {{ end }} + </div> + </div> + </div> + </div> + {{ end }} + </div> + </div> + </div> +</section> diff --git a/layouts/partials/toc.html b/layouts/partials/toc.html new file mode 100644 index 0000000..2a5c87c --- /dev/null +++ b/layouts/partials/toc.html @@ -0,0 +1,22 @@ +{{ $options := (dict "outputStyle" "compressed" "includePaths" (slice "sass")) }} +{{ $tocScss := resources.Get "css/toc.scss" }} +{{ $toc := $tocScss | resources.ExecuteAsTemplate "css/toc.scss" . | resources.ToCSS $options | resources.Minify }} +<link rel="stylesheet" type="text/css" href="{{ $toc.Permalink | relURL }}"> +<script src="/js/tocbot.min.js"></script> +{{ $globalAutoCollapseToc := .Site.Params.autoCollapseToc | default false }} +<script> + tocbot.init({ + // Where to render the table of contents. + tocSelector: '.post-toc', + // Where to grab the headings to build the table of contents. + contentSelector: '#post-content', + // Which headings to grab inside of the contentSelector element. + headingSelector: 'h1, h2, h3', + collapseDepth: {{ if not (or .Params.autoCollapseToc (and $globalAutoCollapseToc (ne .Params.autoCollapseToc false))) }} 6 {{else}} 0 {{ end }}, + scrollSmooth: true, + positionFixedSelector: '.post-toc', + // FIXME: elements in container's offsetTop is not right...It's to difficult for me... + // fixedSidebarOffset: 'auto', + fixedSidebarOffset: 273, + }); +</script> |