mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-30 04:23:30 +08:00
Merge branch 'CaiJimmy:master' into master
This commit is contained in:
commit
ba0e6fa8cc
10
assets/icons/language.svg
Normal file
10
assets/icons/language.svg
Normal file
@ -0,0 +1,10 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-language" width="24" height="24" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">
|
||||
<path stroke="none" d="M0 0h24v24H0z" fill="none"/>
|
||||
<path d="M4 5h7" />
|
||||
<path d="M9 3v2c0 4.418 -2.239 8 -5 8" />
|
||||
<path d="M5 9c-.003 2.144 2.952 3.908 6.7 4" />
|
||||
<path d="M12 20l4 -9l4 9" />
|
||||
<path d="M19.1 18h-6.2" />
|
||||
</svg>
|
||||
|
||||
|
After Width: | Height: | Size: 467 B |
@ -91,7 +91,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
.article-time {
|
||||
.article-time,
|
||||
.article-translations {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
color: var(--card-text-color-tertiary);
|
||||
@ -101,19 +102,21 @@
|
||||
|
||||
svg {
|
||||
vertical-align: middle;
|
||||
margin-right: 15px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
stroke-width: 1.33;
|
||||
}
|
||||
|
||||
time {
|
||||
time,
|
||||
a {
|
||||
font-size: 1.4rem;
|
||||
color: var(--card-text-color-tertiary);
|
||||
}
|
||||
|
||||
& > div {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,67 +122,6 @@
|
||||
}
|
||||
}
|
||||
|
||||
.article-page.has-toc {
|
||||
.left-sidebar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.right-sidebar {
|
||||
width: 100%;
|
||||
padding: 0;
|
||||
display: none;
|
||||
|
||||
@include respond(xl) {
|
||||
display: block;
|
||||
top: var(--main-top-padding);
|
||||
}
|
||||
}
|
||||
|
||||
#article-toolbar {
|
||||
display: block;
|
||||
|
||||
@include respond(md) {
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
@include respond(xl) {
|
||||
margin-top: 0;
|
||||
position: sticky;
|
||||
top: var(--main-top-padding);
|
||||
flex-shrink: 1;
|
||||
|
||||
a {
|
||||
background: transparent;
|
||||
box-shadow: none;
|
||||
border: 1px solid var(--body-text-color);
|
||||
width: 100%;
|
||||
margin-right: 0;
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.main-container {
|
||||
align-items: start;
|
||||
flex-direction: column;
|
||||
|
||||
@include respond(xl) {
|
||||
flex-direction: row;
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
padding-top: 0;
|
||||
|
||||
@include respond(xl) {
|
||||
padding-top: var(--main-top-padding);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.widget--toc {
|
||||
background-color: var(--card-background);
|
||||
border-radius: var(--card-border-radius);
|
||||
|
@ -125,7 +125,6 @@
|
||||
.menu {
|
||||
padding-left: 0;
|
||||
list-style: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow-y: auto;
|
||||
flex-grow: 1;
|
||||
@ -138,8 +137,17 @@
|
||||
|
||||
margin: 0 -15px;
|
||||
|
||||
&,
|
||||
.menu-bottom-section {
|
||||
gap: 15px;
|
||||
@include respond(xl) {
|
||||
margin-top: 30px;
|
||||
gap: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
&.show {
|
||||
display: block;
|
||||
display: flex;
|
||||
}
|
||||
|
||||
@include respond(md) {
|
||||
@ -161,14 +169,6 @@
|
||||
vertical-align: middle;
|
||||
padding: 10px 30px;
|
||||
|
||||
&:not(:last-of-type) {
|
||||
margin-bottom: 15px;
|
||||
|
||||
@include respond(xl) {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
@include respond(md) {
|
||||
width: 100%;
|
||||
padding: 10px 0;
|
||||
@ -200,6 +200,13 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.menu-bottom-section {
|
||||
margin-top: auto;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.social-menu {
|
||||
|
@ -37,7 +37,7 @@
|
||||
}
|
||||
|
||||
.right-sidebar {
|
||||
flex-shrink: 0;
|
||||
width: 100%;
|
||||
display: none;
|
||||
|
||||
&.sticky {
|
||||
@ -158,3 +158,20 @@
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
#i18n-switch {
|
||||
color: var(--body-text-color);
|
||||
display: inline-flex;
|
||||
align-content: center;
|
||||
|
||||
select {
|
||||
border: 0;
|
||||
background-color: transparent;
|
||||
color: var(--body-text-color);
|
||||
|
||||
option {
|
||||
color: var(--card-text-color-main);
|
||||
background-color: var(--card-background);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
13
config.yaml
13
config.yaml
@ -95,6 +95,7 @@ params:
|
||||
darkTheme:
|
||||
reactionsEnabled: 1
|
||||
emitMetadata: 0
|
||||
lang:
|
||||
|
||||
gitalk:
|
||||
owner:
|
||||
@ -108,16 +109,8 @@ params:
|
||||
id:
|
||||
|
||||
widgets:
|
||||
enabled:
|
||||
- search
|
||||
- archives
|
||||
- tag-cloud
|
||||
|
||||
archives:
|
||||
limit: 5
|
||||
|
||||
tagCloud:
|
||||
limit: 10
|
||||
homepage: []
|
||||
page: []
|
||||
|
||||
opengraph:
|
||||
twitter:
|
||||
|
@ -4,6 +4,16 @@ theme: hugo-theme-stack
|
||||
paginate: 5
|
||||
title: Example Site
|
||||
|
||||
languages:
|
||||
en:
|
||||
languageName: English
|
||||
title: Example Site
|
||||
weight: 1
|
||||
cn:
|
||||
languageName: 中文
|
||||
title: 演示站点
|
||||
weight: 2
|
||||
|
||||
# Change it to your Disqus shortname before using
|
||||
disqusShortname: hugo-theme-stack
|
||||
|
||||
@ -132,16 +142,16 @@ params:
|
||||
host:
|
||||
id:
|
||||
widgets:
|
||||
enabled:
|
||||
- search
|
||||
- archives
|
||||
- tag-cloud
|
||||
|
||||
archives:
|
||||
limit: 5
|
||||
|
||||
tagCloud:
|
||||
limit: 10
|
||||
homepage:
|
||||
- type: search
|
||||
- type: archives
|
||||
params:
|
||||
limit: 5
|
||||
- type: tag-cloud
|
||||
params:
|
||||
limit: 10
|
||||
page:
|
||||
- type: toc
|
||||
|
||||
opengraph:
|
||||
twitter:
|
||||
|
5
exampleSite/content/page/about/index.cn.md
Normal file
5
exampleSite/content/page/about/index.cn.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
title: 关于
|
||||
---
|
||||
|
||||
This is a test page for i18n support.
|
@ -6,7 +6,8 @@
|
||||
</head>
|
||||
<body class="{{ block `body-class` . }}{{ end }}">
|
||||
{{- partial "head/colorScheme" . -}}
|
||||
<div class="container main-container flex {{ block `container-class` . }}on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }}{{ end }}">
|
||||
{{- $hasWidget := default (gt (len .Site.Params.widgets.homepage) 0) (.Scratch.Get "hasWidget") -}}
|
||||
<div class="container main-container flex on-phone--column {{ if $hasWidget }}extended{{ else }}compact{{ end }}">
|
||||
{{- block "left-sidebar" . -}}
|
||||
{{ partial "sidebar/left.html" . }}
|
||||
{{- end -}}
|
||||
|
@ -77,5 +77,5 @@
|
||||
{{ end }}
|
||||
|
||||
{{ define "right-sidebar" }}
|
||||
{{ partialCached "sidebar/right.html" . }}
|
||||
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
|
||||
{{ end }}
|
@ -1,15 +1,26 @@
|
||||
{{ define "body-class" }}
|
||||
{{ $TOCEnabled := default (default false .Site.Params.article.toc) .Params.toc }}
|
||||
{{- .Scratch.Set "hasTOC" (and (ge (len .TableOfContents) 100) $TOCEnabled) -}}
|
||||
article-page {{ if (.Scratch.Get "hasTOC") }}has-toc{{ end }}
|
||||
{{ end }}
|
||||
article-page
|
||||
{{/*
|
||||
Enable the right sidebar if
|
||||
- Widget different from 'TOC' is enabled
|
||||
- TOC is enabled and not empty
|
||||
*/}}
|
||||
{{- $HasWidgetNotTOC := false -}}
|
||||
{{- $TOCWidgetEnabled := false -}}
|
||||
{{- range .Site.Params.widgets.page -}}
|
||||
{{- if ne .type "toc" -}}
|
||||
{{ $HasWidgetNotTOC = true -}}
|
||||
{{- else -}}
|
||||
{{ $TOCWidgetEnabled = true -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{ define "container-class" }}
|
||||
{{ if (.Scratch.Get "hasTOC") }}
|
||||
extended
|
||||
{{ else }}
|
||||
on-phone--column {{ if .Site.Params.widgets.enabled }}extended{{ else }}compact{{ end }}
|
||||
{{ end }}
|
||||
{{- $TOCManuallyDisabled := eq .Params.toc false -}}
|
||||
{{- $TOCEnabled := and (not $TOCManuallyDisabled) $TOCWidgetEnabled -}}
|
||||
{{- $hasTOC := ge (len .TableOfContents) 100 -}}
|
||||
{{- .Scratch.Set "TOCEnabled" (and $TOCEnabled $hasTOC) -}}
|
||||
|
||||
{{- .Scratch.Set "hasWidget" (or $HasWidgetNotTOC (and $TOCEnabled $hasTOC)) -}}
|
||||
{{ end }}
|
||||
|
||||
{{ define "main" }}
|
||||
@ -30,32 +41,6 @@
|
||||
{{ partialCached "article/components/photoswipe" . }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "left-sidebar" }}
|
||||
{{ if (.Scratch.Get "hasTOC") }}
|
||||
<div id="article-toolbar">
|
||||
<a href="{{ .Site.BaseURL | relLangURL }}" class="back-home">
|
||||
{{ (resources.Get "icons/back.svg").Content | safeHTML }}
|
||||
<span>{{ T "article.back" }}</span>
|
||||
</a>
|
||||
</div>
|
||||
{{ else }}
|
||||
{{ partial "sidebar/left.html" . }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
|
||||
{{ define "right-sidebar" }}
|
||||
{{ if (.Scratch.Get "hasTOC") }}
|
||||
<aside class="sidebar right-sidebar sticky">
|
||||
<section class="widget archives">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" "hash" }}
|
||||
</div>
|
||||
<h2 class="widget-title section-title">{{ T "article.tableOfContents" }}</h2>
|
||||
|
||||
<div class="widget--toc">
|
||||
{{ .TableOfContents }}
|
||||
</div>
|
||||
</section>
|
||||
</aside>
|
||||
{{ end }}
|
||||
{{ if .Scratch.Get "hasWidget" }}{{ partial "sidebar/right.html" (dict "Context" . "Scope" "page") }}{{ end}}
|
||||
{{ end }}
|
||||
|
@ -15,5 +15,5 @@
|
||||
{{ end }}
|
||||
|
||||
{{ define "right-sidebar" }}
|
||||
{{ partial "sidebar/right.html" . }}
|
||||
{{ partial "sidebar/right.html" (dict "Context" . "Scope" "homepage") }}
|
||||
{{ end }}
|
@ -42,4 +42,15 @@
|
||||
{{ end }}
|
||||
</footer>
|
||||
{{ end }}
|
||||
|
||||
{{ if .IsTranslated }}
|
||||
<footer class="article-translations">
|
||||
{{ partial "helper/icon" "language" }}
|
||||
<div>
|
||||
{{ range .Translations }}
|
||||
<a href="{{ .Permalink }}" class="link">{{ .Language.LanguageName }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
</footer>
|
||||
{{ end }}
|
||||
</div>
|
@ -9,41 +9,41 @@
|
||||
data-reactions-enabled="{{- default 1 .reactionsEnabled -}}"
|
||||
data-emit-metadata="{{- default 0 .emitMetadata -}}"
|
||||
data-theme="{{- default `light` .lightTheme -}}"
|
||||
data-lang="{{- default `en` .lang -}}"
|
||||
crossorigin="anonymous"
|
||||
async
|
||||
></script>
|
||||
<script>
|
||||
function setGiscusTheme(theme) {
|
||||
let giscus = document.querySelector('iframe.giscus-frame');
|
||||
let giscus = document.querySelector("iframe.giscus-frame");
|
||||
if (giscus) {
|
||||
giscus.contentWindow.postMessage(
|
||||
{
|
||||
{
|
||||
giscus: {
|
||||
setConfig: {
|
||||
theme: theme
|
||||
}
|
||||
}
|
||||
setConfig: {
|
||||
theme: theme,
|
||||
},
|
||||
},
|
||||
},
|
||||
"https://giscus.app"
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
(function(){
|
||||
addEventListener('message', (e) => {
|
||||
if (event.origin !== 'https://giscus.app') return;
|
||||
handler()
|
||||
(function () {
|
||||
addEventListener("message", (e) => {
|
||||
if (event.origin !== "https://giscus.app") return;
|
||||
handler();
|
||||
});
|
||||
window.addEventListener('onColorSchemeChange', handler);
|
||||
window.addEventListener("onColorSchemeChange", handler);
|
||||
|
||||
function handler() {
|
||||
if (document.documentElement.dataset.scheme === "light") {
|
||||
setGiscusTheme('{{- default "light" .lightTheme -}}');
|
||||
} else {
|
||||
setGiscusTheme('{{- default "dark_dimmed" .darkTheme -}}');
|
||||
};
|
||||
};
|
||||
}());
|
||||
}
|
||||
}
|
||||
})();
|
||||
</script>
|
||||
{{- end -}}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<script src="//cdn.jsdelivr.net/npm/twikoo@1.4.15/dist/twikoo.all.min.js"></script>
|
||||
<script src="//cdn.jsdelivr.net/npm/twikoo@1.4.18/dist/twikoo.all.min.js"></script>
|
||||
<div id="tcomment"></div>
|
||||
<style>
|
||||
.twikoo {
|
||||
|
@ -73,12 +73,26 @@
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
{{ if (default false .Site.Params.colorScheme.toggle) }}
|
||||
<li id="dark-mode-toggle">
|
||||
{{ partial "helper/icon" "toggle-left" }}
|
||||
{{ partial "helper/icon" "toggle-right" }}
|
||||
<span>{{ T "darkMode" }}</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
<div class="menu-bottom-section">
|
||||
{{- $currentLanguageCode := .Language.Lang -}}
|
||||
{{ with .Site.Home.AllTranslations }}
|
||||
<li id="i18n-switch">
|
||||
{{ partial "helper/icon" "language" }}
|
||||
<select name="language" onchange="window.location.href = this.selectedOptions[0].value">
|
||||
{{ range . }}
|
||||
<option value="{{ .Permalink }}" {{ if eq .Language.Lang $currentLanguageCode }}selected{{ end }}>{{ .Language.LanguageName }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
</li>
|
||||
{{ end }}
|
||||
|
||||
{{ if (default false .Site.Params.colorScheme.toggle) }}
|
||||
<li id="dark-mode-toggle">
|
||||
{{ partial "helper/icon" "toggle-left" }}
|
||||
{{ partial "helper/icon" "toggle-right" }}
|
||||
<span>{{ T "darkMode" }}</span>
|
||||
</li>
|
||||
{{ end }}
|
||||
</div>
|
||||
</ol>
|
||||
</aside>
|
||||
|
@ -1,8 +1,13 @@
|
||||
{{ if .Site.Params.widgets.enabled }}
|
||||
{{ $context := . }}
|
||||
{{- $scope := default "homepage" .Scope -}}
|
||||
{{- $context := .Context -}}
|
||||
{{- with (index .Context.Site.Params.widgets $scope) -}}
|
||||
<aside class="sidebar right-sidebar sticky">
|
||||
{{ range $widget := .Site.Params.widgets.enabled }}
|
||||
{{ partial (printf "widget/%s" $widget) $context }}
|
||||
{{ range $widget := . }}
|
||||
{{ if templates.Exists (printf "partials/widget/%s.html" .type) }}
|
||||
{{ partial (printf "widget/%s" .type) (dict "Context" $context "Params" .params) }}
|
||||
{{ else }}
|
||||
{{ warnf "Widget %s not found" .type }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</aside>
|
||||
{{ end }}
|
@ -1,4 +1,6 @@
|
||||
{{- $query := first 1 (where .Site.Pages "Layout" "==" "archives") -}}
|
||||
{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "archives") -}}
|
||||
{{- $context := .Context -}}
|
||||
{{- $limit := default 5 .Params.limit -}}
|
||||
{{- if $query -}}
|
||||
{{- $archivesPage := index $query 0 -}}
|
||||
<section class="widget archives">
|
||||
@ -7,17 +9,17 @@
|
||||
</div>
|
||||
<h2 class="widget-title section-title">{{ T "widget.archives.title" }}</h2>
|
||||
|
||||
{{ $pages := where .Site.RegularPages "Type" "in" .Site.Params.mainSections }}
|
||||
{{ $notHidden := where .Site.RegularPages "Params.hidden" "!=" true }}
|
||||
{{ $pages := where $context.Site.RegularPages "Type" "in" $context.Site.Params.mainSections }}
|
||||
{{ $notHidden := where $context.Site.RegularPages "Params.hidden" "!=" true }}
|
||||
{{ $filtered := ($pages | intersect $notHidden) }}
|
||||
{{ $archives := $filtered.GroupByDate "2006" }}
|
||||
|
||||
<div class="widget-archive--list">
|
||||
{{ range $index, $item := first (add .Site.Params.widgets.archives.limit 1) ($archives) }}
|
||||
{{ range $index, $item := first (add $limit 1) ($archives) }}
|
||||
{{- $id := lower (replace $item.Key " " "-") -}}
|
||||
<div class="archives-year">
|
||||
<a href="{{ $archivesPage.RelPermalink }}#{{ $id }}">
|
||||
{{ if eq $index $.Site.Params.widgets.archives.limit }}
|
||||
{{ if eq $index $limit }}
|
||||
<span class="year">{{ T "widget.archives.more" }}</span>
|
||||
{{ else }}
|
||||
<span class="year">{{ .Key }}</span>
|
||||
|
@ -1,4 +1,4 @@
|
||||
{{- $query := first 1 (where .Site.Pages "Layout" "==" "search") -}}
|
||||
{{- $query := first 1 (where .Context.Site.Pages "Layout" "==" "search") -}}
|
||||
{{- if $query -}}
|
||||
{{- $searchPage := index $query 0 -}}
|
||||
<form action="{{ $searchPage.RelPermalink }}" class="search-form widget" {{ with .OutputFormats.Get "json" -}}data-json="{{ .Permalink }}" {{- end }}>
|
||||
|
@ -1,3 +1,5 @@
|
||||
{{- $context := .Context -}}
|
||||
{{- $limit := default 10 .Params.limit -}}
|
||||
<section class="widget tagCloud">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" "tag" }}
|
||||
@ -5,7 +7,7 @@
|
||||
<h2 class="widget-title section-title">{{ T "widget.tagCloud.title" }}</h2>
|
||||
|
||||
<div class="tagCloud-tags">
|
||||
{{ range first .Site.Params.widgets.tagCloud.limit .Site.Taxonomies.tags.ByCount }}
|
||||
{{ range first $limit $context.Site.Taxonomies.tags.ByCount }}
|
||||
<a href="{{ .Page.RelPermalink }}" class="font_size_{{ .Count }}">
|
||||
{{ .Page.Title }}
|
||||
</a>
|
||||
|
12
layouts/partials/widget/toc.html
Normal file
12
layouts/partials/widget/toc.html
Normal file
@ -0,0 +1,12 @@
|
||||
{{ if (.Context.Scratch.Get "TOCEnabled") }}
|
||||
<section class="widget archives">
|
||||
<div class="widget-icon">
|
||||
{{ partial "helper/icon" "hash" }}
|
||||
</div>
|
||||
<h2 class="widget-title section-title">{{ T "article.tableOfContents" }}</h2>
|
||||
|
||||
<div class="widget--toc">
|
||||
{{ .Context.TableOfContents }}
|
||||
</div>
|
||||
</section>
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user