1
0
Fork 0

update layouts

This commit is contained in:
nanxiaobei 2021-08-24 03:59:02 +08:00
parent 34a66235ba
commit ef99ea997c
8 changed files with 186 additions and 166 deletions

View file

@ -1,3 +1,3 @@
{{ partial "header.html" . }} {{ define "main" }}
<h1 class="title-404">404</h1> <h1 class="title-404">404</h1>
{{ partial "footer.html" . }} {{ end }}

View file

@ -0,0 +1,20 @@
<!DOCTYPE html>
{{ $social := slice "twitter" "github" "instagram" }}<!---->
{{ range $key, $val := site.Params }}<!---->
{{ if in $social $key }}<!---->
{{ $.Scratch.SetInMap "social-map" $key $val }}<!---->
{{ end }}<!---->
{{ end }}<!---->
<html lang="{{ site.LanguageCode }}">
{{ partial "head.html" . }}
<body class="not-ready" data-menu="{{ isset site.Menus `main` }}">
{{ partial "header.html" . }}
<main class="main">{{ block "main" . }}{{ end }}</main>
{{ partial "footer.html" . }}
</body>
</html>

View file

@ -1,16 +1,17 @@
{{ partial "header.html" . }} {{ define "main" }}
<!-- Main Title -->
{{ if .Title }} {{ if .Title }}
<h1 class="page-title">{{ .Title }}</h1> <h1 class="main-title">{{ .Title }}</h1>
{{ end }} {{ end }}
<!-- $pages -->
{{ $pages := union .RegularPages .Sections }} {{ $pages := union .RegularPages .Sections }}
{{ if .IsHome }} <!---->{{ if .IsHome }} {{ $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ $pages = where site.RegularPages "Type" "in" site.Params.mainSections }}
{{ end }} {{ end }}
{{ $paginator := .Paginate $pages }}
{{ range $index, $page := $paginator.Pages }} <!-- Articles -->
{{ $paginator := .Paginate $pages }} {{ range $index, $page := $paginator.Pages }}
<article class="post-entry"> <article class="post-entry">
<h2>{{ .Title }}</h2> <h2>{{ .Title }}</h2>
<time>{{ .Date.Format "January 2, 2006" }}</time> <time>{{ .Date.Format "January 2, 2006" }}</time>
@ -18,15 +19,16 @@
</article> </article>
{{ end }} {{ end }}
<!-- Main Nav -->
{{ if gt $paginator.TotalPages 1 }} {{ if gt $paginator.TotalPages 1 }}
<nav class="page-nav"> <nav class="main-nav">
{{ if $paginator.HasPrev }} {{ if $paginator.HasPrev }}
<a class="prev" href="{{ $paginator.Prev.URL }}">← {{ i18n "prev_page" }}</a> <a class="prev" href="{{ $paginator.Prev.URL }}">← {{ i18n "prev_page" }}</a>
{{ end }} {{ end }}<!---->
{{ if $paginator.HasNext }} {{ if $paginator.HasNext }}
<a class="next" href="{{ $paginator.Next.URL }}">{{ i18n "next_page" }} →</a> <a class="next" href="{{ $paginator.Next.URL }}">{{ i18n "next_page" }} →</a>
{{ end }} {{ end }}
</nav> </nav>
{{ end }} {{ end }}<!---->
{{ partial "footer.html" . }} {{ end }}

View file

@ -1,4 +1,4 @@
{{ partial "header.html" . }} {{ define "main" }}
<article class="post-single"> <article class="post-single">
<header class="post-title"> <header class="post-title">
@ -8,33 +8,32 @@
<span>{{ .Params.Author | default site.Author.name }}</span> <span>{{ .Params.Author | default site.Author.name }}</span>
{{ end }} {{ end }}
</aside> </aside>
<h1>{{ .Title }}</h1> <h1>{{ .Title }}</h1>
</header> </header>
<section class="post-content">{{ .Content }}</section> <section class="post-content">{{ .Content }}</section>
<!-- Post Tags -->
{{ if .Params.tags }} {{ if .Params.tags }}
<footer class="post-tags"> <footer class="post-tags">
{{ range .Params.tags }} {{ range .Params.tags }} {{ $href := print (absURL "tags/") (urlize .) }}
{{ $href := print (absURL "tags/") (urlize .) }}
<a href="{{ $href }}">{{ . }}</a> <a href="{{ $href }}">{{ . }}</a>
{{ end }} {{ end }}
</footer> </footer>
{{ end }} {{ end }}
{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }} <!-- Post Nav -->
{{ $pages := where site.RegularPages "Type" "in" site.Params.mainSections }}<!---->
{{ if and (gt (len $pages) 1) (in $pages . ) }} {{ if and (gt (len $pages) 1) (in $pages . ) }}
<nav class="post-nav"> <nav class="post-nav">
{{ with $pages.Next . }} {{ with $pages.Next . }}
<a class="prev" href="{{ .Permalink }}"><span></span><span>{{ .Name }}</span></a> <a class="prev" href="{{ .Permalink }}"><span></span><span>{{ .Name }}</span></a>
{{ end }} {{ end }} {{ with $pages.Prev . }}
{{ with $pages.Prev . }}
<a class="next" href="{{ .Permalink }}"><span>{{ .Name }}</span><span></span></a> <a class="next" href="{{ .Permalink }}"><span>{{ .Name }}</span><span></span></a>
{{ end }} {{ end }}
</nav> </nav>
{{ end }} {{ end }}
<!-- Disqus -->
{{ if and site.DisqusShortname (not (eq .Params.comments false)) }} {{ if and site.DisqusShortname (not (eq .Params.comments false)) }}
<div id="disqus_thread" class="post-comments"></div> <div id="disqus_thread" class="post-comments"></div>
<script> <script>
@ -47,4 +46,4 @@
{{ end }} {{ end }}
</article> </article>
{{ partial "footer.html" . }} {{ end }}

View file

@ -1,8 +1,7 @@
</main> <footer class="footer">
<footer class="footer"> <p>&copy; {{ now.Year }} <a href="{{ `` | absURL }}">{{ site.Title }}</a></p>
<p>&copy; {{ now.Year }} <a href="{{ "" | absURL }}">{{ site.Title }}</a></p> <p>Powered by <a href="https://gohugo.io/" rel="noopener" target="_blank">Hugo</a></p>
<p>Powered by <a href="https://gohugo.io/" rel="noopener" target="_blank">Hugo</a></p> <p>
<p><a href="https://github.com/nanxiaobei/hugo-paper" rel="noopener" target="_blank">Paper 5.0</a></p> <a href="https://github.com/nanxiaobei/hugo-paper" rel="noopener" target="_blank">Paper 5.0</a>
</footer> </p>
</body> </footer>
</html>

View file

@ -0,0 +1,73 @@
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- Title -->
<title>{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ site.Title }}</title>
<!-- Meta -->
{{ if eq .Kind "page" }}
<meta name="description" content="{{ .Summary }}" />
<meta name="author" content="{{ .Params.Author | default site.Author.name }}" />
{{ else }}
<meta name="description" content="{{ site.Params.description }}" />
<meta name="author" content="{{ site.Author.name }}" />
{{ end }}
<!-- Styles & Scripts -->
{{ $app_css := resources.Get "app.css" }}
<!---->
{{ $custom_css := resources.Get "custom.css" }}
<!---->
{{ $css := slice $app_css $custom_css | resources.Concat "app.css" | minify }}
<link rel="preload stylesheet" as="style" href="{{ $css.Permalink }}" />
{{ if and .IsPage (not site.Params.disableHLJS) }}
<link rel="preload stylesheet" as="style" href="{{ `an-old-hope.min.css` | absURL }}" />
<script
defer
src="{{ `highlight.min.js` | absURL }}"
onload="hljs.initHighlightingOnLoad();"
></script>
{{ end }}
<!-- Preload -->
<link rel="preload" as="image" href="{{ `theme.png` | absURL }}" />
{{ range $key, $val := $.Scratch.Get "social-map" }}
<link rel="preload" as="image" href="{{ printf `%s.svg` $key | absURL }}" />
{{ end }}
<!-- Favicon -->
<link rel="icon" href="{{ `favicon.ico` | absURL }}" />
<link rel="apple-touch-icon" href="{{ `apple-touch-icon.png` | absURL }}" />
<!-- Generator -->
{{ hugo.Generator }}
<!-- RSS -->
{{ range .AlternativeOutputFormats }}
<link
rel="{{ .Rel }}"
type="{{ .MediaType.Type }}"
href="{{ .Permalink }}"
title="{{ site.Title }}"
/>
{{ end }}
<!-- Misc -->
{{ if hugo.IsProduction | eq site.Params.env "production" }}
<!---->
{{ template "_internal/google_analytics_async.html" . }}
<!---->
{{ template "_internal/google_news.html" . }}
<!---->
{{ template "_internal/opengraph.html" . }}
<!---->
{{ template "_internal/schema.html" . }}
<!---->
{{ template "_internal/twitter_cards.html" . }}
<!---->
{{ end }}
</head>

View file

@ -1,127 +1,60 @@
<!DOCTYPE html> <header class="header">
<html lang="{{ site.LanguageCode }}"> {{ if .IsHome }}
<head> <h1 class="logo">
<meta charset="utf-8"> <a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-theme"></a>
<meta http-equiv="X-UA-Compatible" content="IE=edge"> </h1>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> {{ else }}
<p class="logo">
<a class="site-name" href="{{ `` | absURL }}">{{ site.Title }}</a><a class="btn-theme"></a>
</p>
{{ end }}
<!-- Title --> <script>
<title>{{ if not .IsHome }}{{ .Title }} - {{ end }}{{ site.Title }}</title> let bodyClass = document.body.classList;
let buttonDark = document.querySelector('.btn-theme');
let schemeDark = window.matchMedia('(prefers-color-scheme: dark)');
<!-- Meta --> let setDark = () => {
{{ if eq .Kind "page" }} bodyClass.add('dark');
<meta name="description" content="{{ .Summary }}"> localStorage.setItem('dark', 'true');
<meta name="author" content="{{ .Params.Author | default site.Author.name }}"> };
{{ else }} let setLight = () => {
<meta name="description" content="{{ site.Params.description }}"> bodyClass.remove('dark');
<meta name="author" content="{{ site.Author.name }}"> localStorage.removeItem('dark');
};
if (schemeDark.matches || localStorage.getItem('dark')) setDark();
requestAnimationFrame(() => {
bodyClass.remove('not-ready');
});
buttonDark.addEventListener('click', () => {
bodyClass.contains('dark') ? setLight() : setDark();
});
schemeDark.addEventListener('change', event => {
event.matches ? setDark() : setLight();
});
</script>
{{ $url := .RelPermalink }}<!---->
{{ with site.Menus.main }}
<nav class="menu">
{{ range . }}
<a class="{{ if eq .URL $url }}active{{ end }}" href="{{ .URL }}">{{ .Name }}</a>
{{ end }} {{ end }}
</nav>
{{ end }}<!---->
<!-- Styles & Scripts --> {{ with $.Scratch.Get "social-map" }}
{{ $app_css := resources.Get "app.css" }} <nav class="social">
{{ $custom_css := resources.Get "custom.css" }} {{ range $key, $val := . }}
{{ $css := slice $app_css $custom_css | resources.Concat "app.css" | minify }} <a
<link rel="preload stylesheet" as="style" href="{{ $css.Permalink }}"> class="{{ $key }}"
style="--img: url(./{{ printf `%s.svg` $key }})"
{{ if and .IsPage (not site.Params.disableHLJS) }} href="https://{{ $key }}.com/{{ $val }}"
<link rel="preload stylesheet" as="style" href="{{ `an-old-hope.min.css` | absURL }}"> target="_blank"
<script defer src="{{ `highlight.min.js` | absURL }}" onload="hljs.initHighlightingOnLoad();"></script> ></a>
{{ end }} {{ end }}
</nav>
<!-- Preload --> {{ end }}
<link rel="preload" as="image" href="{{ `theme.png` | absURL }}"> </header>
{{ if site.Params.twitter }}
<link rel="preload" as="image" href="{{ `twitter.svg` | absURL }}">
{{ end }}
{{ if site.Params.github }}
<link rel="preload" as="image" href="{{ `github.svg` | absURL }}">
{{ end }}
{{ if site.Params.instagram }}
<link rel="preload" as="image" href="{{ `instagram.svg` | absURL }}">
{{ end }}
<!-- Favicon -->
<link rel="icon" href="{{ `favicon.ico` | absURL }}">
<link rel="apple-touch-icon" href="{{ `apple-touch-icon.png` | absURL }}">
<!-- Generator -->
{{ hugo.Generator }}
<!-- RSS -->
{{ range .AlternativeOutputFormats }}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}" href="{{ .Permalink }}" title="{{ site.Title }}">
{{ end }}
<!-- Misc -->
{{ if hugo.IsProduction | eq site.Params.env "production" }}
{{ template "_internal/google_analytics_async.html" . }}
{{ template "_internal/google_news.html" . }}
{{ template "_internal/opengraph.html" . }}
{{ template "_internal/schema.html" . }}
{{ template "_internal/twitter_cards.html" . }}
{{ end }}
</head>
<body class="not-ready" data-menu="{{ isset site.Menus `main` }}">
<header class="header">
{{ $tag := cond .IsHome "h1" "p" }}
{{ printf `
<%s class="logo">
<a class="site-name" href="%s">%s</a>
<a class="btn-theme"></a>
</%s>
` $tag ("" | absURL) site.Title $tag | safeHTML }}
<script>
let bodyClass = document.body.classList;
let schemeDark = window.matchMedia('(prefers-color-scheme: dark)');
let buttonDark = document.querySelector('.btn-theme');
let setDark = () => {
bodyClass.add('dark');
localStorage.setItem('dark', 'true');
};
let setLight = () => {
bodyClass.remove('dark');
localStorage.removeItem('dark');
};
if (schemeDark.matches || localStorage.getItem('dark')) setDark();
requestAnimationFrame(() => {
bodyClass.remove('not-ready');
});
schemeDark.addEventListener('change', event => {
event.matches ? setDark() : setLight();
});
buttonDark.addEventListener('click', () => {
bodyClass.contains('dark') ? setLight() : setDark();
});
</script>
{{ if site.Menus.main }}
<nav class="menu">
{{ $url := .Permalink }}
{{ range site.Menus.main }}
<a class="{{ if eq $url .URL }}active{{ end }}" href="{{ .URL }}">{{ .Name }}</a>
{{ end }}
</nav>
{{ end }}
{{ if site.Params.twitter }}
<a class="social-icon twitter" href="https://twitter.com/{{ site.Params.twitter }}" target="_blank"></a>
{{ end }}
{{ if site.Params.github }}
<a class="social-icon github" href="https://github.com/{{ site.Params.github }}" target="_blank"></a>
{{ end }}
{{ if site.Params.instagram }}
<a class="social-icon instagram" href="https://www.instagram.com/{{ site.Params.instagram }}/" target="_blank"></a>
{{ end }}
</header>
<main class="main">

View file

@ -1,15 +1,9 @@
{{ if .Get "content" }} <!---->{{ if not (.Get "summary") }}
{{ if .Get "summary" }} <!---->{{ errorf "missing param 'summary': %s" .Position }}
{{ else }} <!---->{{ else if not (.Get "content") }}{{ warnf "missing param 'content': %s" .Position }}
{{ warnf "missing value for param 'summary': %s" .Position }} <!---->{{ end }}
{{ end }}
{{ else }}
{{ errorf "missing value for param 'content': %s" .Position }}
{{ end }}
<p> <details {{ if (eq (.Get `openByDefault`) true) }}open="true" {{ end }}>
<details {{ if (eq (.Get "openByDefault") true) }}open=true{{ end }}> <summary markdown="span">{{ .Get "summary" | markdownify }}</summary>
<summary markdown="span">{{ .Get "summary" | markdownify }}</summary> {{ .Get "content" | markdownify }}
{{ .Get "content" | markdownify }} </details>
</details>
</p>