diff options
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | assets/css/common.scss | 3 | ||||
-rw-r--r-- | i18n/en.toml | 23 | ||||
-rw-r--r-- | i18n/zh-cn.toml | 23 | ||||
-rw-r--r-- | layouts/_default/baseof.html | 3 | ||||
-rw-r--r-- | layouts/_default/taxonomy.html | 55 | ||||
-rw-r--r-- | layouts/archives/single.html | 30 | ||||
-rw-r--r-- | layouts/partials/footer.html | 4 | ||||
-rw-r--r-- | layouts/partials/header.html | 5 | ||||
-rw-r--r-- | layouts/partials/nav.html | 49 | ||||
-rw-r--r-- | layouts/partials/navburger.html | 21 | ||||
-rw-r--r-- | layouts/partials/paginator.html | 52 | ||||
-rw-r--r-- | layouts/partials/post.html | 47 | ||||
-rw-r--r-- | layouts/partials/posts.html | 144 | ||||
-rw-r--r-- | theme.toml | 4 |
15 files changed, 274 insertions, 200 deletions
@@ -9,7 +9,10 @@ ## Features -- basic functions: category/tag/archives +- small & fast +- basic functions: + - category & tag + - archives - TOC sidebar - `prefers-color-scheme` media support @@ -28,7 +31,7 @@ theme = "hulga" ``` and then config it. -3. to use `postcss`, copy `package.json ` and `postcss-config.js` to the root of your site folder, then `npm install` +3. to use `postcss`, copy `package.json ` and `postcss.config.js` to the root of your site folder, then `npm install` ## Config @@ -37,6 +40,7 @@ An example of avaliable params: ```toml baseURL = "https://example.com" languageCode = "zh-cn" +DefaultContentLanguage = "zh-cn" title = "My New Hugo Site" paginate = 10 theme = "hulga" @@ -66,6 +70,9 @@ theme = "hulga" # enable prefers-color-scheme:dark darkMedia = true + # enable hero section's is-bold effect + heroBold = true + # to enable different hightlight themes in light/dark mode [markup] [markup.highlight] diff --git a/assets/css/common.scss b/assets/css/common.scss index 26e4ec8..19b2665 100644 --- a/assets/css/common.scss +++ b/assets/css/common.scss @@ -120,10 +120,9 @@ a { } .post-box-tag { color: $primary; - font-size: 0.8em; + font-size: 0.9em; } .post-box-meta { - padding-top: 0.2rem; padding-bottom: 0.1rem; opacity: 0.8; font-size: 0.9rem; diff --git a/i18n/en.toml b/i18n/en.toml new file mode 100644 index 0000000..1fcae9e --- /dev/null +++ b/i18n/en.toml @@ -0,0 +1,23 @@ +[categories] +other = "Categories" + +[tags] +other = "Tags" + +[taxo_cat_before] +other = "Articles with category " + +[taxo_tag_before] +other = "Articles with tag " + +[taxo_after] +other = "" + +[prev_page] +other = "Previous" + +[next_page] +other = "Next" + +[archives] +other = "There are {{ .Count }} articles in this blog"
\ No newline at end of file diff --git a/i18n/zh-cn.toml b/i18n/zh-cn.toml new file mode 100644 index 0000000..b7c786e --- /dev/null +++ b/i18n/zh-cn.toml @@ -0,0 +1,23 @@ +[categories] +other = "分类" + +[tags] +other = "标签" + +[taxo_cat_before] +other = "分类 " + +[taxo_tag_before] +other = "标签 " + +[taxo_after] +other = " 中的文章" + +[prev_page] +other = "上一页" + +[next_page] +other = "下一页" + +[archives] +other = "本博客共 {{ .Count }} 篇博文"
\ No newline at end of file diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index fbf3fab..ea5525d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -4,12 +4,11 @@ <body> <div id="main"> - {{- partial "nav.html" . -}} - <!-- {{- partial "header.html" . -}} --> {{- block "main" . }}{{- end }} </div> {{- partial "footer.html" . -}} {{- partial "backtotop.html" . -}} + {{- partial "navburger.html" . -}} {{- block "script" . }}{{- end }} </body> diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index a528fe6..fba4a8f 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -3,33 +3,38 @@ <!-- {{- 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 class="columns"> + <div class="column is-2"></div> + <div class="column is-8"> + <div class="content"> + {{ if eq .Data.Singular "category" }} + <h3> + {{- i18n "taxo_cat_before" -}} + <span class="tag mytag">{{ .Data.Term }}</span> + {{- i18n "taxo_after" -}} + </h3> + {{ else if eq .Data.Singular "tag" }} + <h3> + {{- i18n "taxo_tag_before" -}} + <span class="tag mytag"><a>{{ .Data.Term }}</a></span> + {{- i18n "taxo_after" -}} + </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> - {{ end }} - {{ partial "paginator.html" . }} + <div class="column is-2"></div> </div> - </div> </section> -{{ end }} +{{ end }}
\ No newline at end of file diff --git a/layouts/archives/single.html b/layouts/archives/single.html index 18ce343..9cec5f7 100644 --- a/layouts/archives/single.html +++ b/layouts/archives/single.html @@ -4,7 +4,6 @@ <body> <div id="main"> - {{- partial "nav.html" . -}} {{- partial "header.html" . -}} <section class="section"> {{- block "archives-main" . }}{{- end }} @@ -19,22 +18,21 @@ {{ 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> + <div class="box content"> + {{ $count := len (where (where .Site.Pages "Type" "post") "Kind" "page") }} + <p>{{ i18n "archives" (dict "Count" $count) }}</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 }} - </div> + </ul> + {{ end }} </div> </div> </div> diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index da744c0..b698406 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -2,7 +2,11 @@ <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> + {{- if .Site.Params.copyright -}} {{ .Site.Params.copyright }} + {{- else -}} + {{ .Site.Copyright }} + {{ end }} </p> </div> </footer> diff --git a/layouts/partials/header.html b/layouts/partials/header.html index 2baa402..740eb25 100644 --- a/layouts/partials/header.html +++ b/layouts/partials/header.html @@ -1,4 +1,7 @@ -<section class="hero is-primary shadow-hero"> +<section class="hero is-primary shadow-hero {{ if .Site.Params.heroBold }}is-bold{{ end }}"> + <div class="hero-head"> + {{ partial "nav.html" . }} + </div> <div class="hero-body"> <div class="container has-text-centered"> <h1 class="title"> diff --git a/layouts/partials/nav.html b/layouts/partials/nav.html index 350ce32..f2a8626 100644 --- a/layouts/partials/nav.html +++ b/layouts/partials/nav.html @@ -1,16 +1,16 @@ <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="container"> + <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="navbar-menu" id="navMenu"> <div class="navbar-end"> {{ range .Site.Menus.main.ByWeight -}} {{ .Pre }} @@ -19,26 +19,5 @@ {{- 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> + </div> +</nav>
\ No newline at end of file diff --git a/layouts/partials/navburger.html b/layouts/partials/navburger.html new file mode 100644 index 0000000..dc1e157 --- /dev/null +++ b/layouts/partials/navburger.html @@ -0,0 +1,21 @@ +<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 index 95e9ee5..f311349 100644 --- a/layouts/partials/paginator.html +++ b/layouts/partials/paginator.html @@ -1,27 +1,35 @@ -{{ $paginator := .Paginate (where .Data.Pages "Type" "post") }} -{{ with $paginator }} - -{{ if gt .TotalPages 1 }} +{{ $pag := .Paginate (where .Data.Pages "Type" "post") }} +{{ if gt $pag.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 }} + <a class="pagination-previous" {{ if $pag.HasPrev }} href="{{ $pag.Prev.URL }}" {{ else }} disabled {{ end }}> + {{ i18n "prev_page"}} + </a> + <ul class="pagination-list"> + {{- $ellipsed := false -}} + {{- $shouldEllipse := false -}} + {{- range $pag.Pagers -}} + {{- $right := sub .TotalPages .PageNumber -}} + {{- $showNumber := or (le .PageNumber 3) (eq $right 0) -}} + {{- $showNumber := or $showNumber (le .TotalPages 5) -}}{{/* Issue #7523 */}} + {{- $showNumber := or $showNumber (and (gt .PageNumber (sub $pag.PageNumber 2)) (lt .PageNumber (add $pag.PageNumber 2))) -}} + {{- if $showNumber -}} + {{- $ellipsed = false -}} + {{- $shouldEllipse = false -}} + {{- else -}} + {{- $shouldEllipse = not $ellipsed -}} + {{- $ellipsed = true -}} + {{- end -}} + {{- if $showNumber }} <li> - <a class="pagination-link {{ if eq .PageNumber $.Paginator.PageNumber }}is-current{{ end }}" + <a class="pagination-link {{ if eq . $pag }}is-current{{ end }}" href="{{ .URL }}">{{ .PageNumber }}</a> </li> - {{ end }} - </ul> - {{ end }} -</nav> -{{ end }} - + {{- else if $shouldEllipse }} + <li><span class="pagination-ellipsis">…</span></li> + {{- end -}} + {{- end }} + </ul> + <a class="pagination-next" {{ if $pag.HasNext }} href="{{ $pag.Next.URL }}" {{ else }} disabled {{ end }}> + {{ i18n "next_page"}} + </a> {{ end }} diff --git a/layouts/partials/post.html b/layouts/partials/post.html index 554b9c7..80cf98d 100644 --- a/layouts/partials/post.html +++ b/layouts/partials/post.html @@ -1,6 +1,13 @@ -<section class="hero is-primary shadow-hero"> +<section class="hero is-primary shadow-hero {{ if .Site.Params.heroBold}} is-bold {{ end }}"> + <div class="hero-head"> + {{ partial "nav.html" . }} + </div> <div class="hero-body"> + {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} + <header class="container"> + {{ else }} <header class="container has-text-centered"> + {{ end }} <h1 class="title post-title"> {{ .Title }} </h1> @@ -34,29 +41,25 @@ <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 }} + {{ else }} + <!-- <div class="column is-1 is-hidden-mobile"></div> --> + <div class="column is-three-fifths is-offset-one-fifth"> + {{ 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> - {{ end }} - {{ if or .Params.toc (and .Site.Params.toc (ne .Params.toc false)) }} - {{ else }} - <div class="column is-1"></div> - {{ end }} + </div> + {{ end }} </div> </div> </div> diff --git a/layouts/partials/posts.html b/layouts/partials/posts.html index 50ea716..3c6512f 100644 --- a/layouts/partials/posts.html +++ b/layouts/partials/posts.html @@ -1,87 +1,89 @@ -<section class="section"> +<section class="section post-box-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> + <div class="column is-10 is-offset-1"> + <div class="columns"> + <div class="column is-8"> + <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> - {{ 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 style="padding-top: 1.5rem;"> + {{ partial "paginator.html" . }} </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 class="column is-4 is-hidden-mobile"> + {{ if .Site.Taxonomies.categories }} + <div class="card"> + <header class="card-header is-primary"> + <p class="card-header-title"> + {{ i18n "categories" }} + </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> - {{ end }} - </div> - </div> - </div> - <br> - {{ end }} + <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 }} + {{ if .Site.Taxonomies.tags }} + <div class="card"> + <header class="card-header"> + <p class="card-header-title"> + {{ i18n "tags" }} + </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> - {{ end }} </div> </div> </div> -</section> +</section>
\ No newline at end of file @@ -6,8 +6,8 @@ license = "MIT" licenselink = "https://github.com/wlh320/hugo-theme-hulga/blob/master/LICENSE" description = "hugo+bulma=hulga" homepage = "http://github.com/wlh320/hugo-theme-hulga/" -tags = ['bulma'] -features = [] +tags = ['bulma', 'blog', 'fast', 'simple', 'dark'] +features = ['bulma', 'fast', 'toc', 'dark mode'] min_version = "0.41.0" [author] |