diff options
| author | Eltrac <hi@guhub.cn> | 2025-07-15 23:21:44 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-07-15 23:21:44 +0800 |
| commit | f22d6fad8f7158b8cbe3e2d89c283977edfdd49a (patch) | |
| tree | 036dd590589040cab6efead584fcf9d9e6c9156b | |
| parent | 0d97407ab88288de8219dbcae5ff4afde892cb39 (diff) | |
refactor: global search UnoCSS-ify, rename postnav to home-nav
Former-commit-id: 43ac3a5b42166e77373ae2495678ab5ac888ae37
| -rw-r--r-- | assets/css/components/_global-search.scss | 76 | ||||
| -rw-r--r-- | assets/css/components/_postlist.scss | 160 | ||||
| -rw-r--r-- | assets/css/global.scss | 3 | ||||
| -rw-r--r-- | assets/css/utils/_animation.scss | 10 | ||||
| -rw-r--r-- | layouts/_partials/components/global-search.html | 30 | ||||
| -rw-r--r-- | layouts/_partials/components/postnav.html | 24 | ||||
| -rw-r--r-- | layouts/_partials/home/home-nav-item.html | 12 | ||||
| -rw-r--r-- | layouts/_partials/home/home-nav.html | 34 | ||||
| -rw-r--r-- | layouts/_partials/home/latest-posts.html | 49 | ||||
| -rw-r--r-- | layouts/_partials/items/post-small.html | 9 | ||||
| -rw-r--r-- | layouts/_partials/items/post.html | 42 | ||||
| -rw-r--r-- | layouts/featured.html | 34 | ||||
| -rw-r--r-- | layouts/home.html | 8 | ||||
| -rw-r--r-- | layouts/section.html | 28 | ||||
| -rw-r--r-- | layouts/stats.html | 4 | ||||
| -rw-r--r-- | layouts/taxonomy.html | 4 | ||||
| -rw-r--r-- | layouts/term.html | 18 | ||||
| -rw-r--r-- | layouts/uncategorized.html | 24 |
18 files changed, 170 insertions, 399 deletions
diff --git a/assets/css/components/_global-search.scss b/assets/css/components/_global-search.scss deleted file mode 100644 index db214b35..00000000 --- a/assets/css/components/_global-search.scss +++ /dev/null @@ -1,76 +0,0 @@ -#global-search-overlay { - position: fixed; - top: 0; - left: 0; - width: 100%; - height: 100%; - background-color: rgba(250,250,250,0.75); - @media (prefers-color-scheme: dark) { - background-color: rgba(30,30,30,0.75); - } - backdrop-filter: blur(10px); - -webkit-backdrop-filter: blur(10px); - - z-index: -10; - opacity: 0; - transition-duration: 0.3s; - transition-property: opacity; -} -#global-search-overlay.shown { - z-index: 10; - opacity: 1; -} - -#global-search { - position: fixed; - z-index: -10; - display: none; - top: 0; - left: 0; - right: 0; - bottom: 0; - align-items: center; - justify-content: center; - #global-search-close { - position: absolute; - top: 0; - right: 0; - padding: 0 1rem; - font-size: 3rem; - cursor: pointer; - } -} - -#global-search #pagefind { - max-height: 90vh; - overflow-y: auto; - width: 100%; - margin: 1rem; -} - -@media screen and (min-width: 768px) { - #global-search #pagefind { - width: 600px - } -} - -#global-search #pagefind input { - outline: none -} - -#global-search.shown { - z-index: 15; - display: flex; - animation: fade-in 0.3s ease-in-out; -} - -@keyframes fade-in { - from { - opacity: 0; - transform: translateY(1rem); - } - to { - opacity: 1; - transform: translateY(0); - } -} diff --git a/assets/css/components/_postlist.scss b/assets/css/components/_postlist.scss deleted file mode 100644 index 57c6b18f..00000000 --- a/assets/css/components/_postlist.scss +++ /dev/null @@ -1,160 +0,0 @@ -.index-section-morelink { - @include small-button; - - &::after { - content: " →"; - } -} - -/* Post List Styles */ - -.posts-list { - display: flex; - flex-direction: column; - margin: 1rem 0; - .posts-item { - overflow: hidden; - width: 100%; - margin: 0.5rem 0; - header { - width: 100%; - - @media screen and (min-width: 768px) { - display: flex; - justify-content: space-between; - } - - .posts-item-meta { - p, time { - color: var(--secondary-text-color); - } - time { - font-family: var(--mono-font-family); - } - a.tag { - font-size: 0.8rem; - color: var(--secondary-text-color); - } - .posts-item-title { - filter: url(#xs); - .posts-item-title-pill { - font-size: 1rem; - font-weight: normal; - color: var(--secondary-text-color) - } - } - } - - .posts-item-category { - margin: 0.5rem 0; - } - } - .posts-item-summary { - h1, h2, h3, h4, h5, h6 { - display: none; - } - iframe { - margin: 1rem 0; - } - font-size: 1.1rem; - } - - position: relative; - .posts-item-icon { - position: absolute; - top: 0; - right: 0; - opacity: 0.25; - z-index: -1; - transform: rotateY(180deg) rotate(-25deg); - img { - width: 8rem; - height: 8rem; - } - } - } -} - -#posts-list-navigation { - ul { - position: relative; - width: 100%; - padding-inline-start: 0; - display: flex; - list-style: none; - gap: 0.2rem; - li { - flex-shrink: 0; - flex-grow: 0; - - &.active { - font-weight: bolder - } - a:not(.icon-link) { - @include small-button; - } - - .icon-link { - opacity: 0.5; - transition: opacity 0.3s; - } - .icon-link:hover, - &.active .icon-link { - opacity: 1; - } - } - - #search-instruction { - font-size: 0.9rem; - color: var(--secondary-text-color); - margin-left: 0.5rem; - - } - - .list-decoration { - position: absolute; - right: 0; - img { - opacity: 0.55; - height: 2rem; - width: 2rem; - } - } - } -} - -.term-list { - .term-list-posts { - &:not(ol) { - list-style: none; - } - padding-inline-start: 0; - display: flex; - flex-direction: column; - gap: 1rem; - li { - display: flex; - justify-content: space-between; - font-size: 1.1rem; - time { - font-size: 0.9rem; - font-family: var(--mono-font-family); - color: var(--secondary-text-color); - flex-shrink: 0; - } - .posts-subtitle { - color: var(--secondary-text-color); - } - } - } -} - -.taxonomy-description hr { - margin: 0.25rem 0; -} - -.posts-item-category { - a { - @include postCategoryPill; - } -} diff --git a/assets/css/global.scss b/assets/css/global.scss index a7149e00..c4fe59a1 100644 --- a/assets/css/global.scss +++ b/assets/css/global.scss @@ -2,7 +2,6 @@ @import "utils/mixins"; @import "utils/reset"; @import "utils/utility"; +@import "utils/animation"; @import "components/markdown"; -@import "components/postlist"; -@import "components/global-search"; diff --git a/assets/css/utils/_animation.scss b/assets/css/utils/_animation.scss new file mode 100644 index 00000000..ccf86c59 --- /dev/null +++ b/assets/css/utils/_animation.scss @@ -0,0 +1,10 @@ +@keyframes fade-in { + from { + opacity: 0; + transform: translateY(1rem); + } + to { + opacity: 1; + transform: translateY(0); + } +} diff --git a/layouts/_partials/components/global-search.html b/layouts/_partials/components/global-search.html index 4f8ea499..a4b82122 100644 --- a/layouts/_partials/components/global-search.html +++ b/layouts/_partials/components/global-search.html @@ -1,15 +1,37 @@ +<style> +#global-search-overlay.shown { + z-index: 10!important; + opacity: 1!important; +} + +#global-search #pagefind input { + outline: none +} + +#global-search.shown { + z-index: 15!important; + display: flex!important; + animation: fade-in 0.3s ease-in-out!important; +} +</style> + <div id="global-search-container"> - <div id="global-search"> - <div id="global-search-close">×</div> + <div id="global-search" + class="fixed -z-10 hidden top-0 left-0 right-0 bottom-0 items-center justify-center"> + <div id="global-search-close" class="absolute top-0 right-0 px-4 text-[3rem] cursor-pointer">×</div> <!-- Pagefind Search --> - <div id="pagefind"></div> + <div id="pagefind" class="max-h-[90vh] overflow-y-auto w-full m-4 md:w-[600px]"></div> <script> window.addEventListener('DOMContentLoaded', () => { new PagefindUI({ element: "#pagefind", showSubResults: true }); }); </script> </div> - <div id="global-search-overlay"></div> + + <div id="global-search-overlay" + class="fixed top-0 left-0 w-full h-full bg-[rgba(250,250,250,0.75)] dark:bg-[rgba(30,30,30,0.75)] + backdrop-blur-md -z-10 opacity-0 transition-opacity duration-300"> + </div> <script> (() => { diff --git a/layouts/_partials/components/postnav.html b/layouts/_partials/components/postnav.html deleted file mode 100644 index 55dd8a51..00000000 --- a/layouts/_partials/components/postnav.html +++ /dev/null @@ -1,24 +0,0 @@ -<div id="posts-list-navigation"> - <ul> - <li class="{{ if eq "/" $.Page.RelPermalink }}active{{ end }}"> - <a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/">{{ T "postNav.latest" }}</a> - </li> - {{ if eq .Site.Language.Lang "zh" }} - <li class="{{ if eq "/featured/" $.Page.RelPermalink }}active{{ end }}"> - <a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/featured">{{ T "postNav.featured" }}</a> - </li> - <li class="{{ if or - (strings.HasPrefix $.Page.RelPermalink "/categories/") - (strings.HasPrefix $.Page.RelPermalink "/tags/") }}active{{ end }}"> - <a data-umami-event="🧭 Click postnav link" href="{{ .Site.LanguagePrefix }}/categories">{{ T "postNav.categories" }}</a> - </li> - {{ end }} - <li id="search-instruction"> - <span>{{ T "searchInstruction" }}</span> - </li> - <li class="list-decoration invert-if-dark{{ if eq "/stats/" $.Page.RelPermalink }} active{{ end }}"> - <a href="{{ .Site.LanguagePrefix }}/stats" class="icon-link" - data-umami-event="📈 Click stats page link"><img src="/img/graph.svg" /></a> - <li> - </ul> -</div> diff --git a/layouts/_partials/home/home-nav-item.html b/layouts/_partials/home/home-nav-item.html new file mode 100644 index 00000000..df1e6121 --- /dev/null +++ b/layouts/_partials/home/home-nav-item.html @@ -0,0 +1,12 @@ +{{ $active := .active }} +{{ $link := .link }} +{{ $text := .text }} + +<li class="flex-shrink-0 flex-grow-0 {{ if $active }}font-bolder{{ end }}"> + <a data-umami-event="🧭 Click postnav link" + href="{{ .Site.LanguagePrefix }}/{{ $link }}" + class="small-button" + > + {{ $text }} + </a> +</li> diff --git a/layouts/_partials/home/home-nav.html b/layouts/_partials/home/home-nav.html new file mode 100644 index 00000000..34ea9a8a --- /dev/null +++ b/layouts/_partials/home/home-nav.html @@ -0,0 +1,34 @@ +<div id="home-nav"> + <ul class="relative w-full ps-0 flex list-none gap-1"> + {{ partial "home/home-nav-item" (dict + "text" (T "postNav.latest") + "link" "" + "active" (eq "/" $.Page.RelPermalink) + ) }} + {{ if eq .Site.Language.Lang "zh" }} + {{ partial "home/home-nav-item" (dict + "text" (T "postNav.featured") + "link" "featured" + "active" (eq "/featured" $.Page.RelPermalink) + ) }} + {{ partial "home/home-nav-item" (dict + "text" (T "postNav.categories") + "link" "categories" + "active" (or + (strings.HasPrefix $.Page.RelPermalink "/categories/") + (strings.HasPrefix $.Page.RelPermalink "/tags/")) + ) }} + {{ end }} + <li id="search-instruction" class="text-[0.9rem] font-secondary ml-2"> + <span>{{ T "searchInstruction" }}</span> + </li> + <li class="absolute right-0 invert-if-dark"> + <a href="{{ .Site.LanguagePrefix }}/stats" + class="opacity-50 transition-opacity duration-300 hover:opacity-100 + {{ if eq "/stats/" $.Page.RelPermalink }} opacity-100 font-bolder{{ end }}" + data-umami-event="📈 Click stats page link"> + <img src="/img/graph.svg" class="opacity-50 h-8 w-8" /> + </a> + <li> + </ul> +</div> diff --git a/layouts/_partials/home/latest-posts.html b/layouts/_partials/home/latest-posts.html index 30b1f212..c7571fe9 100644 --- a/layouts/_partials/home/latest-posts.html +++ b/layouts/_partials/home/latest-posts.html @@ -1,50 +1,13 @@ <!-- Latest Posts --> <section id="latest-posts"> - <div class="posts-list"> + <div class="flex flex-col my-4"> {{ $firstPost := true }} <!-- 初始化标记 --> {{ range first 8 (where site.RegularPages "Type" "in" site.Params.mainSections) }} - <div class="posts-item" - style="view-transition-name: post-{{ .File.UniqueID }}"> - <header> - <div class="posts-item-meta"> - <p class="font-mono"> - <time>{{ .Date.Format "January 2" }},</time> - <span>in <a href="/{{ .Section }}/">{{ .Section }}</a></span> - </p> - <h2 class="posts-item-title" - {{ if $firstPost }} style="margin-bottom: 0"{{ end }}> - <a - href="{{ .Permalink }}" - data-umami-event="🏠 Click post link from index" - > - {{ if eq .Section "library" }} - 读《{{ .Title }}》 - {{ else }} - {{ .Title }} - {{ end }} - </a> - {{ if eq .Section "fictions" }} - <span class="posts-item-title-pill">小说</span> - {{ end }} - </h2> - </div> - {{ with .Params.categories }} - <div class="posts-item-category"> - <a href="/categories/{{ . }}" style="padding: 0.1rem 0.3rem;"> - {{ . }} - </a> - </div> - {{ end }} - </header> - <!-- 如果是第一篇文章,则显示摘要 --> - {{ if $firstPost }} - <div class="markdown-body posts-item-summary" - style="view-transition-name: post-content-{{ .File.UniqueID }}"> - {{ .Summary }} - </div> - {{ $firstPost = false }} <!-- 更新为非第一篇 --> - {{ end }} - </div> + {{ partial "items/post" (dict + "ctx" . + "showSummary" $firstPost + ) }} + {{ $firstPost = false }} {{ end }} </div> <a href="/posts" class="index-section-morelink" diff --git a/layouts/_partials/items/post-small.html b/layouts/_partials/items/post-small.html new file mode 100644 index 00000000..39d6ae5c --- /dev/null +++ b/layouts/_partials/items/post-small.html @@ -0,0 +1,9 @@ +<li class="flex justify-between text-[1.1rem]"> + <a href="{{ .RelPermalink }}" data-umami-event="🗃️ Click Post Link from Category Page"> + {{ .Title }}{{ with .Params.subtitle }}:<span class="font-secondary">{{. }}</span> + {{ end }} + </a> + <time class="text-[0.9rem] font-mono font-secondary flex-shrink-0"> + {{ .Date.Format "2006-1-2" }} + </time> +</li> diff --git a/layouts/_partials/items/post.html b/layouts/_partials/items/post.html new file mode 100644 index 00000000..10471180 --- /dev/null +++ b/layouts/_partials/items/post.html @@ -0,0 +1,42 @@ +{{ $ctx := .ctx }} +{{ $showSummary := .showSummary }} +<div class="posts-item w-full my-2" + style="view-transition-name: post-{{ .ctx.File.UniqueID }}"> + <header class="w-full md:flex md:justify-between"> + <div> + <p class="font-mono font-secondary"> + <time>{{ .ctx.Date.Format "January 2" }},</time> + <span>in <a href="/{{ .Section }}/">{{ .ctx.Section }}</a></span> + </p> + <h2 class="xerox" + {{ if $showSummary }} style="margin-bottom: 0"{{ end }}> + <a + href="{{ .ctx.Permalink }}" + data-umami-event="🏠 Click post link from index" + > + {{ if eq .ctx.Section "library" }} + 读《{{ .ctx.Title }}》 + {{ else }} + {{ .ctx.Title }} + {{ end }} + </a> + {{ if eq .ctx.Section "fictions" }} + <span class="font-normal text-[1rem] text-[var(--secondary-text-color)]">小说</span> + {{ end }} + </h2> + </div> + {{ with .ctx.Params.categories }} + <div class="my-2"> + <a href="/categories/{{ . }}" style="padding: 0.1rem 0.3rem;"> + {{ . }} + </a> + </div> + {{ end }} + </header> + {{ if $showSummary }} + <div class="markdown-body text-[1.1rem]" + style="view-transition-name: post-content-{{ .File.UniqueID }}"> + {{ .ctx.Summary }} + </div> + {{ end }} +</div> diff --git a/layouts/featured.html b/layouts/featured.html index 86d5f53a..d01e217c 100644 --- a/layouts/featured.html +++ b/layouts/featured.html @@ -1,41 +1,17 @@ {{ define "main" }} <article class="index"> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} <div class="markdown-content" style="line-height: 2"> {{ .Content }} </div> - <!-- Latest Posts --> <section id="featured-posts"> <div class="posts-list"> - {{ range where site.RegularPages "Params.featured" true }} - <div class="posts-item" - style="view-transition-name: post-{{ .File.UniqueID }}"> - <header> - <div class="posts-item-meta"> - <p> - <time>{{ .Date.Format "Jan 2, 2006" }}</time> - <span>·</span> - {{ partial "components/tags" . }} - </p> - <h2 class="posts-item-title"> - <a - href="{{ .Permalink }}" - data-umami-event="🪶 Click post link from featured" - > - {{ if eq .Section "library" }} - 读《{{ .Title }}》 - {{ else }} - {{ .Title }} - {{ end }} - </a> - </h2> - </div> - </header> - </div> - {{ end }} + {{ range where site.RegularPages "Params.featured" true }} + {{ partial "items/post" (dict "ctx" . ) }} + {{ end }} </div> </section> </article> diff --git a/layouts/home.html b/layouts/home.html index 18742fdf..2753ab2f 100644 --- a/layouts/home.html +++ b/layouts/home.html @@ -1,9 +1,9 @@ {{ define "main" }} <article class="index"> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} - {{ partial "home/latest-posts.html" . }} - {{ partial "home/latest-cards.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} + {{ partial "home/latest-posts" . }} + {{ partial "home/latest-cards" . }} </article> {{ partial "footer.html" . }} {{ end }} diff --git a/layouts/section.html b/layouts/section.html index 3fafc08e..b1602e6b 100644 --- a/layouts/section.html +++ b/layouts/section.html @@ -22,29 +22,11 @@ <small class="font-mono font-secondary text-[0.8rem]">{{ T "archivePage.postCountMonthly" (len .Pages) }}</small> </h2> </summary> - <div class="term-list"> - <ul class="term-list-posts"> - {{ range .Pages }} - <li> - <div style="display: flex; gap: 1rem;"> - <time class="font-mono"> - {{ .Date.Format "Jan 02" }} - </time> - <a href="{{ .Permalink }}"> - {{ .Title }} - </a> - </div> - <div class="posts-item-category"> - {{ with .Params.categories }} - <a href="/categories/{{ . }}"> - {{ . }} - </a> - {{ end }} - </div> - </li> - {{ end }} - </ul> - </div> + <ul class="ps-0 flex flex-col gap-2 list-none leading-relaxed"> + {{ range .Pages }} + {{ partial "items/post-small" . }} + {{ end }} + </ul> </details> {{ $remainingMonthsToOpen = sub $remainingMonthsToOpen 1 }} {{ end }} diff --git a/layouts/stats.html b/layouts/stats.html index 1aa7cf3e..cdd66f14 100644 --- a/layouts/stats.html +++ b/layouts/stats.html @@ -1,7 +1,7 @@ {{ define "main" }} <article> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} <section> <h2>站点统计</h2> diff --git a/layouts/taxonomy.html b/layouts/taxonomy.html index 42ebb61a..514440e6 100644 --- a/layouts/taxonomy.html +++ b/layouts/taxonomy.html @@ -1,7 +1,7 @@ {{ define "main" }} <article class="taxonomy"> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} <h2>文章系列</h2> {{ partial "taxonomy/all-categories.html" . }} diff --git a/layouts/term.html b/layouts/term.html index 7c401c79..b237e143 100644 --- a/layouts/term.html +++ b/layouts/term.html @@ -1,7 +1,7 @@ {{ define "main" }} <article> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} <div class="term-header"> <h1 class="term-title" style="view-transition-name: category-{{ .Title }}"> @@ -14,19 +14,11 @@ <p class="term-description">{{ . }}</p> {{ end }} </div> - <div class="term-list"> + <div> <!-- Posts under this Term --> - <ul class="term-list-posts"> + <ul class="ps-0 flex flex-col gap-2 list-none leading-relaxed"> {{ range where .Pages "Section" "not in" (slice "cards" "library") }} - <li> - <a href="{{ .RelPermalink }}" data-umami-event="🗃️ Click Post Link from Category Page"> - {{ .Title }}{{ with .Params.subtitle }}:<span class="posts-subtitle">{{. }}</span> - {{ end }} - </a> - <time> - {{ .Date.Format "2006-1-2" }} - </time> - </li> + {{ partial "items/post-small" . }} {{ end }} </ul> diff --git a/layouts/uncategorized.html b/layouts/uncategorized.html index b86e9b76..0eed855c 100644 --- a/layouts/uncategorized.html +++ b/layouts/uncategorized.html @@ -1,7 +1,7 @@ {{ define "main" }} <article class="posts termlist-page"> - {{ partial "header.html" . }} - {{ partial "components/postnav.html" . }} + {{ partial "header" . }} + {{ partial "home/home-nav" . }} <h1 class="term-title">{{ .Title }}</h1> <div class="post-content markdown-body"> <p>{{ .Content }}</p> @@ -9,21 +9,11 @@ <!-- Uncategorized --> {{ $uncategorized := where (where .Site.RegularPages "Section" "posts") "Params.categories" "==" nil }} {{ if $uncategorized }} - <section class="uncategorized-posts term-list"> - <ol class="term-list-posts"> - {{ range $uncategorized }} - <li> - <a href="{{ .RelPermalink }}" data-umami-event="🈚️ Click Post Link from Uncategorized"> - {{ .Title }}{{ with .Params.subtitle }}:<span class="posts-subtitle">{{. }}</span> - {{ end }} - </a> - <time> - {{ .Date.Format "2006-1-2" }} - </time> - </li> - {{ end }} - </ol> - </section> + <ol class="ps-0 flex flex-col gap-2 leading-relaxed"> + {{ range $uncategorized }} + {{ partial "items/post-small" . }} + {{ end }} + </ol> {{ end }} </article> {{ partial "footer.html" . }} |
