refactor: v2
This commit is contained in:
@@ -1,69 +0,0 @@
|
||||
---
|
||||
// 后面的 ?url 是 一个导入查询(import query),表示:不要把 SVG 当作组件或源码处理,而是返回这个资源的 URL 字符串。
|
||||
import backTopIcon from "@/assets/icon/back-top.svg?url";
|
||||
---
|
||||
|
||||
<button class="back-top" type="button" aria-label="返回顶部" hidden>
|
||||
<img src={backTopIcon} alt="">
|
||||
</button>
|
||||
|
||||
<script>
|
||||
const backTop = document.querySelector<HTMLButtonElement>(".back-top")
|
||||
|
||||
const toggleBackTop = () => {
|
||||
if (!backTop) return;
|
||||
|
||||
backTop.hidden = window.scrollY <= 500;
|
||||
};
|
||||
|
||||
backTop && backTop.addEventListener("click", () => {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: "smooth",
|
||||
});
|
||||
});
|
||||
|
||||
window.addEventListener("scroll", toggleBackTop, {passive: true});
|
||||
|
||||
toggleBackTop();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.back-top {
|
||||
position: fixed;
|
||||
right: 150px;
|
||||
bottom: 100px;
|
||||
width: 44px;
|
||||
height: 44px;
|
||||
z-index: 999;
|
||||
cursor: pointer;
|
||||
padding: 0;
|
||||
border: none;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.back-top[hidden] {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.back-top img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
:global(.dark) .back-top img {
|
||||
filter: invert(1);
|
||||
}
|
||||
|
||||
.back-top:focus-visible {
|
||||
outline: 2px solid currentColor;
|
||||
outline-offset: 4px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.back-top {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,46 +0,0 @@
|
||||
---
|
||||
import { metadata } from "../consts";
|
||||
|
||||
const year = new Date().getFullYear();
|
||||
---
|
||||
|
||||
<footer>
|
||||
<div class="content">
|
||||
<span>© 2026 {metadata.siteTitle}</span>
|
||||
<a target="_blank" href="https://beian.miit.gov.cn/#/Integrated/index">
|
||||
备案号:鄂ICP备2023000060号-2
|
||||
</a>
|
||||
</div>
|
||||
</footer>
|
||||
|
||||
|
||||
<style>
|
||||
footer {
|
||||
background: #22252b;
|
||||
height: 70px;
|
||||
overflow: hidden;
|
||||
flex-shrink: 0;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.content {
|
||||
max-width: var(--layout-width);
|
||||
margin: 0 auto;
|
||||
color: #fff;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 100%;
|
||||
font-size: 14px;
|
||||
justify-content: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
:global(.dark) footer {
|
||||
background: var(--background);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:global(.dark) .content {
|
||||
color: #ffffff;
|
||||
}
|
||||
</style>
|
||||
@@ -1,113 +0,0 @@
|
||||
---
|
||||
import {metadata} from "../consts";
|
||||
import ThemeIcon from './ThemeIcon.astro'
|
||||
import GitHubIcon from '@/assets/icon/github.svg?url'
|
||||
---
|
||||
|
||||
<header>
|
||||
<nav class="main-nav">
|
||||
<h1>
|
||||
<a href="/">{metadata.siteTitle}</a>
|
||||
</h1>
|
||||
|
||||
<div class="main-nav-right">
|
||||
<ul class="menu">
|
||||
<li class="menu-item"><a href="/">首页</a></li>
|
||||
<li class="menu-item"><a href="/archive">归档</a></li>
|
||||
<li class="menu-item"><a target="_blank" href="https://git.ua42.com">
|
||||
<img class="github-icon" src={GitHubIcon} alt="GitHub"/>
|
||||
</a></li>
|
||||
<!--<li class="menu-item"><a href="/">关于</a></li>-->
|
||||
</ul>
|
||||
|
||||
<ThemeIcon/>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<style>
|
||||
header {
|
||||
height: 60px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 99999;
|
||||
box-shadow: var(--shadow);
|
||||
flex-shrink: 0;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.main-nav {
|
||||
max-width: var(--layout-width);
|
||||
margin: 0 auto;
|
||||
height: 100%;
|
||||
padding: 0 32px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.main-nav-right {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.main-nav {
|
||||
padding: 16px;
|
||||
}
|
||||
}
|
||||
|
||||
.main-nav h1 {
|
||||
user-select: none;
|
||||
cursor: pointer;
|
||||
font-size: 24px;
|
||||
color: #000000;
|
||||
}
|
||||
|
||||
.main-nav .menu {
|
||||
list-style: none;
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
.menu-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.github-icon {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.main-nav .menu-item a {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.main-nav .menu-item a:hover {
|
||||
color: #64748b;
|
||||
}
|
||||
|
||||
:global(.dark) header {
|
||||
background: var(--background);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
:global(.dark) .main-nav h1 {
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
:global(.dark) .main-nav .menu-item a:hover {
|
||||
color: rgba(255, 255, 255, .8);
|
||||
}
|
||||
|
||||
:global(.dark) .github-icon {
|
||||
filter: invert(1);
|
||||
}
|
||||
</style>
|
||||
107
src/components/IndexPage.astro
Normal file
107
src/components/IndexPage.astro
Normal file
@@ -0,0 +1,107 @@
|
||||
---
|
||||
import {siteConfig} from "@/consts.ts";
|
||||
import PostList from "@/components/Post/List.astro";
|
||||
import Pagination from "@/components/Post/Pagination.astro";
|
||||
import type {Post} from "@/types";
|
||||
|
||||
const {siteTitle} = siteConfig;
|
||||
|
||||
interface Props {
|
||||
posts: Post[]
|
||||
page: number
|
||||
totalPage: number
|
||||
}
|
||||
|
||||
const {posts, page, totalPage} = Astro.props
|
||||
---
|
||||
|
||||
<div class="page-content">
|
||||
<header>
|
||||
<div class="top">
|
||||
<h1>{siteTitle}</h1>
|
||||
<!--<nav>-->
|
||||
<!-- <span>归档</span>-->
|
||||
<!-- <span>/</span>-->
|
||||
<!-- <span>标签</span>-->
|
||||
<!-- <span>/</span>-->
|
||||
<!-- <span>关于</span>-->
|
||||
<!--</nav>-->
|
||||
</div>
|
||||
<div class="intro">
|
||||
<p>did you stand too close to the fire?<br>
|
||||
like a liar looking for forgiveness from a stone.</p>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<PostList posts={posts}/>
|
||||
<Pagination page={page} totalPage={totalPage}/>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div>© 2026 Uroboros</div>
|
||||
<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">备案号:鄂ICP备2023000060号-2</a>
|
||||
</footer>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.page-content {
|
||||
min-height: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
header {
|
||||
margin-bottom: 24px;
|
||||
margin-top: 48px;
|
||||
}
|
||||
|
||||
.top {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: var(--border-primary);
|
||||
padding-bottom: 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
nav {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
.intro {
|
||||
padding: 28px 0;
|
||||
border-bottom: var(--border-secondary);
|
||||
line-height: 2;
|
||||
font-size: 15px;
|
||||
color: var(--text-secondary);
|
||||
}
|
||||
|
||||
main {
|
||||
flex: 1;
|
||||
flex-shrink: 0;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
footer {
|
||||
flex-shrink: 0;
|
||||
min-height: 0;
|
||||
height: 84px;
|
||||
padding-bottom: 24px;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
font-size: 13px;
|
||||
gap: 12px;
|
||||
color: var(--text-tertiary);
|
||||
}
|
||||
</style>
|
||||
@@ -1,152 +0,0 @@
|
||||
---
|
||||
import Folder from "@/assets/icon/folder.png?url";
|
||||
import TagIcon from "@/assets/icon/tag.png?url";
|
||||
import type { CategoriesStats,Tag } from "@/types";
|
||||
import { createHttp } from "@/lib/request";
|
||||
const http = createHttp(Astro.request.headers);
|
||||
|
||||
const { data: categories } =
|
||||
await http.get<ApiResponse<CategoriesStats[]>>("categories/stats");
|
||||
|
||||
const { data: tags } =
|
||||
await http.get<ApiResponse<Tag[]>>("posts/tags");
|
||||
---
|
||||
|
||||
<aside class="sidebar">
|
||||
<div class="widget">
|
||||
<h3 class="widget-title">
|
||||
<img src={Folder} alt="Folder" />
|
||||
文章分类
|
||||
</h3>
|
||||
<ul class="category-list">
|
||||
{
|
||||
categories.map((category) => (
|
||||
<li>
|
||||
<a
|
||||
href={`/search?c=${encodeURIComponent(category.code)}`}
|
||||
title={`${category.name} · ${category.post_count} 篇`}
|
||||
>
|
||||
{category.name}
|
||||
</a>
|
||||
<span class="count">{category.post_count}</span>
|
||||
</li>
|
||||
))
|
||||
}
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="widget">
|
||||
<h3 class="widget-title">
|
||||
<img src={TagIcon} alt="Tag" />
|
||||
标签云
|
||||
</h3>
|
||||
<div class="tag-cloud">
|
||||
{
|
||||
tags.map((tag) => (
|
||||
<a
|
||||
class="tag"
|
||||
href={`/search?t=${encodeURIComponent(tag.code)}`}
|
||||
>
|
||||
{tag.name}
|
||||
</a>
|
||||
))
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
|
||||
<style>
|
||||
.sidebar {
|
||||
flex-shrink: 0;
|
||||
width: 300px;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.widget {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
box-shadow: var(--shadow);
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.widget-title {
|
||||
font-size: 16px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 16px;
|
||||
padding-bottom: 10px;
|
||||
border-bottom: 1px solid var(--border);
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.widget-title img {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
|
||||
/* 分类 & 标签云 */
|
||||
.category-list {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
.category-list li {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: 8px 4px;
|
||||
font-size: 14px;
|
||||
border-bottom: 1px dashed var(--border);
|
||||
}
|
||||
|
||||
.category-list li:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.category-list a:hover {
|
||||
color: #4f6df5;
|
||||
}
|
||||
|
||||
.category-list .count {
|
||||
color: var(--text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.tag-cloud {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 12px;
|
||||
color: var(--tag-text);
|
||||
background: var(--tag-bg);
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.tag:hover {
|
||||
background: var(--tag-hover-bg);
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.sidebar {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.sidebar {
|
||||
gap: 16px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,46 +0,0 @@
|
||||
---
|
||||
import type {Post} from "@/types/post";
|
||||
import IndexSidebar from "@/components/IndexSidebar.astro";
|
||||
import PostList from "@/components/Post/List.astro";
|
||||
import Pagination from "@/components/Post/Pagination.astro";
|
||||
|
||||
interface Props {
|
||||
posts: Post[];
|
||||
page: number;
|
||||
totalPage: number;
|
||||
}
|
||||
|
||||
const {posts, page, totalPage} = Astro.props;
|
||||
---
|
||||
|
||||
<div class="page-content">
|
||||
<div class="container">
|
||||
<div class="post-container">
|
||||
<PostList posts={posts}/>
|
||||
<Pagination page={page} totalPage={totalPage}/>
|
||||
</div>
|
||||
<IndexSidebar/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.container {
|
||||
flex: 1;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
gap: 28px;
|
||||
}
|
||||
|
||||
.post-container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.container {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -52,7 +52,6 @@ const {
|
||||
.placeholder {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: #f3f4f6;
|
||||
background-image: linear-gradient(
|
||||
90deg,
|
||||
#f3f4f6 0%,
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
---
|
||||
import type {Post} from '@/types';
|
||||
import Eye from "@/assets/icon/eye.png?url";
|
||||
import Folder from "@/assets/icon/folder.png?url";
|
||||
import Calendar from "@/assets/icon/calendar.png?url";
|
||||
import LazyImage from "@/components/LazyImage.astro";
|
||||
import {formatDatetime} from "@/lib/format.ts";
|
||||
|
||||
interface Props {
|
||||
post: Post
|
||||
}
|
||||
|
||||
const {post} = Astro.props;
|
||||
const published_at = formatDatetime(post.published_at, 'YYYY-MM-DD')
|
||||
---
|
||||
|
||||
<a href={`/post/${post.slug}`}>
|
||||
<article class="post-card">
|
||||
<div class="post-cover">
|
||||
<LazyImage src={post.cover} alt={post.title}/>
|
||||
</div>
|
||||
<div class="post-body">
|
||||
<div class="post-meta">
|
||||
<span>
|
||||
<img src={Calendar} alt="Calendar"/>
|
||||
{published_at}
|
||||
</span>
|
||||
<span>
|
||||
<img src={Folder} alt="Folder"/>
|
||||
{post.category_name}
|
||||
</span>
|
||||
<span>
|
||||
<img src={Eye} alt="Eye"/>
|
||||
{post.view_count}
|
||||
</span>
|
||||
</div>
|
||||
<h3 class="post-title">
|
||||
{post.title}
|
||||
</h3>
|
||||
<div class="post-summary">
|
||||
{post.summary}
|
||||
</div>
|
||||
<div class="tags">
|
||||
{post.tags.map(tag =>
|
||||
<div class="tag">{tag.name}</div>)}
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
</a>
|
||||
|
||||
<style>
|
||||
.post-card {
|
||||
background: var(--card-bg);
|
||||
border-radius: 12px;
|
||||
box-shadow: var(--shadow);
|
||||
padding: 16px;
|
||||
transition: transform 0.2s, box-shadow 0.2s;
|
||||
display: flex;
|
||||
gap: 22px;
|
||||
}
|
||||
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
.post-card:hover {
|
||||
transform: translateY(-3px);
|
||||
box-shadow: var(--shadow-hover);
|
||||
}
|
||||
}
|
||||
|
||||
.post-cover {
|
||||
flex-shrink: 0;
|
||||
width: 160px;
|
||||
height: 100px;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 40px;
|
||||
color: #fff;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.post-body {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.post-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 6px;
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.post-meta span {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.post-meta span img {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 20px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 8px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.post-summary {
|
||||
font-size: 14px;
|
||||
color: var(--text-secondary);
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.tags {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.tag {
|
||||
font-size: 12px;
|
||||
color: var(--tag-text);
|
||||
background: var(--tag-bg);
|
||||
padding: 3px 10px;
|
||||
border-radius: 999px;
|
||||
transition: background 0.2s;
|
||||
}
|
||||
|
||||
.tag:hover {
|
||||
background: var(--tag-hover-bg);
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.post-card {
|
||||
padding: 16px;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.post-cover {
|
||||
width: 128px;
|
||||
height: 80px;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.post-meta {
|
||||
gap: 8px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 560px) {
|
||||
.post-card {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.post-title {
|
||||
font-size: 14px;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.post-meta {
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.post-summary {
|
||||
font-size: 12px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,37 +1,70 @@
|
||||
---
|
||||
import type {Post} from "@/types/post";
|
||||
import PostItem from '@/components/Post/Item.astro'
|
||||
import type {Post} from "@/types";
|
||||
import {formatDatetime} from '@/lib/format.ts'
|
||||
|
||||
interface Props {
|
||||
posts: Post[]
|
||||
}
|
||||
|
||||
const {posts} = Astro.props
|
||||
---
|
||||
|
||||
<section class="section">
|
||||
<div class="post-list">
|
||||
{posts.map(post => (
|
||||
<PostItem post={post}/>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
<div class="posts">
|
||||
{posts.map(item => (
|
||||
<div class="post">
|
||||
<span class="d">{formatDatetime(item.published_at, 'YY.MM.DD')}</span>
|
||||
<h2><a href=`/post/${item.slug}`>{item.title}</a></h2>
|
||||
<span class="arrow">→</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.section {
|
||||
flex: 1;
|
||||
height: 100%;
|
||||
.posts {
|
||||
|
||||
}
|
||||
|
||||
.post-list {
|
||||
.post {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: baseline;
|
||||
gap: 20px;
|
||||
padding: 26px 0;
|
||||
border-bottom: 1px solid #e8e8e8;
|
||||
}
|
||||
|
||||
@media (max-width: 860px){
|
||||
.post-list{
|
||||
gap: 12px;
|
||||
}
|
||||
.post .d {
|
||||
font-size: 12px;
|
||||
color: #b8b8b8;
|
||||
min-width: 80px;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.post h2 {
|
||||
font-size: 17px;
|
||||
font-weight: 500;
|
||||
flex: 1;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.post h2 a {
|
||||
color: #181818;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.post h2 a:hover {
|
||||
color: #334155;
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 6px;
|
||||
}
|
||||
|
||||
.post .arrow {
|
||||
color: #d0d0d0;
|
||||
font-size: 14px;
|
||||
transition: transform 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.post:hover .arrow {
|
||||
color: #334155;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -10,58 +10,40 @@ const {page, totalPage} = Astro.props
|
||||
<!--分页器-->
|
||||
{totalPage > 1 &&
|
||||
<nav class="pagination" aria-label="分页">
|
||||
{page > 1 ? <a href={`/page/${page - 1}`} class="link">« 上一页</a> : <span class="link disabled">« 上一页</span>}
|
||||
{Array.from({length: totalPage}).map((_, index) => {
|
||||
if (page === index + 1) {
|
||||
return <span class="link current">{index + 1}</span>
|
||||
}
|
||||
return <a class="link" href={`/page/${index + 1}`}>{index + 1}</a>
|
||||
})}
|
||||
{page < totalPage ? <a href={`/page/${page + 1}`} class="link">下一页 »</a> :
|
||||
<span class="link disabled">下一页 »</span>}
|
||||
{page < totalPage ? <a href={`/page/${page + 1}`} class="link">下一页</a> :
|
||||
<span class="link disabled">下一页</span>}
|
||||
</nav>}
|
||||
|
||||
<style>
|
||||
/* ========== 分页 ========== */
|
||||
.pagination {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
overflow-x: auto;
|
||||
margin-top: 32px;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 38px;
|
||||
height: 38px;
|
||||
padding: 0 12px;
|
||||
border-radius: 8px;
|
||||
background: var(--card-bg);
|
||||
border: 1px solid var(--border);
|
||||
font-size: 14px;
|
||||
display: inline-block;
|
||||
margin: 0 12px;
|
||||
line-height: 1;
|
||||
color: var(--text-secondary);
|
||||
transition: all 0.2s;
|
||||
white-space: nowrap;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
.link:first-child {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.link:hover,
|
||||
.link.current {
|
||||
background: var(--primary);
|
||||
border-color: var(--primary);
|
||||
color: #fff;
|
||||
.current{
|
||||
color: var(--text-primary);
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.link.disabled {
|
||||
color: var(--text-secondary);
|
||||
background: var(--card-bg);
|
||||
border-color: var(--border);
|
||||
color: var(--text-disabled);
|
||||
cursor: not-allowed;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
---
|
||||
---
|
||||
<div class="theme-toggle" id="themeToggle" aria-label="Toggle theme">
|
||||
<svg aria-hidden="true" width="20px" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
|
||||
<path class="sun" fill-rule="evenodd"
|
||||
d="M12 17.5a5.5 5.5 0 1 0 0-11 5.5 5.5 0 0 0 0 11zm0 1.5a7 7 0 1 0 0-14 7 7 0 0 0 0 14zm12-7a.8.8 0 0 1-.8.8h-2.4a.8.8 0 0 1 0-1.6h2.4a.8.8 0 0 1 .8.8zM4 12a.8.8 0 0 1-.8.8H.8a.8.8 0 0 1 0-1.6h2.5a.8.8 0 0 1 .8.8zm16.5-8.5a.8.8 0 0 1 0 1l-1.8 1.8a.8.8 0 0 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM6.3 17.7a.8.8 0 0 1 0 1l-1.7 1.8a.8.8 0 1 1-1-1l1.7-1.8a.8.8 0 0 1 1 0zM12 0a.8.8 0 0 1 .8.8v2.5a.8.8 0 0 1-1.6 0V.8A.8.8 0 0 1 12 0zm0 20a.8.8 0 0 1 .8.8v2.4a.8.8 0 0 1-1.6 0v-2.4a.8.8 0 0 1 .8-.8zM3.5 3.5a.8.8 0 0 1 1 0l1.8 1.8a.8.8 0 1 1-1 1L3.5 4.6a.8.8 0 0 1 0-1zm14.2 14.2a.8.8 0 0 1 1 0l1.8 1.7a.8.8 0 0 1-1 1l-1.8-1.7a.8.8 0 0 1 0-1z"/>
|
||||
<path class="moon" fill-rule="evenodd"
|
||||
d="M16.5 6A10.5 10.5 0 0 1 4.7 16.4 8.5 8.5 0 1 0 16.4 4.7l.1 1.3zm-1.7-2a9 9 0 0 1 .2 2 9 9 0 0 1-11 8.8 9.4 9.4 0 0 1-.8-.3c-.4 0-.8.3-.7.7a10 10 0 0 0 .3.8 10 10 0 0 0 9.2 6 10 10 0 0 0 4-19.2 9.7 9.7 0 0 0-.9-.3c-.3-.1-.7.3-.6.7a9 9 0 0 1 .3.8z"/>
|
||||
</svg>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#themeToggle {
|
||||
border: 0;
|
||||
background: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.theme-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.sun {
|
||||
fill: black;
|
||||
}
|
||||
|
||||
.moon {
|
||||
fill: transparent;
|
||||
}
|
||||
|
||||
:global(.dark) .sun {
|
||||
fill: transparent;
|
||||
}
|
||||
|
||||
:global(.dark) .moon {
|
||||
fill: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script is:inline>
|
||||
const meta = document.querySelector('meta[name="theme-color"]');
|
||||
|
||||
const theme = (() => {
|
||||
const localStorageTheme = localStorage?.getItem("theme") ?? '';
|
||||
if (['dark', 'light'].includes(localStorageTheme)) {
|
||||
return localStorageTheme;
|
||||
}
|
||||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
return 'light';
|
||||
})();
|
||||
|
||||
if (theme === 'light') {
|
||||
document.documentElement.classList.remove('dark');
|
||||
meta.setAttribute('content', '#ffffff');
|
||||
} else {
|
||||
document.documentElement.classList.add('dark');
|
||||
meta.setAttribute('content', '#0a0a0a');
|
||||
}
|
||||
|
||||
window.localStorage.setItem('theme', theme);
|
||||
|
||||
const handleToggleClick = () => {
|
||||
const element = document.documentElement;
|
||||
element.classList.toggle("dark");
|
||||
|
||||
const isDark = element.classList.contains("dark");
|
||||
meta.setAttribute('content', isDark ? '#0a0a0a' : '#ffffff');
|
||||
localStorage.setItem("theme", isDark ? "dark" : "light");
|
||||
}
|
||||
|
||||
document.getElementById("themeToggle")?.addEventListener("click", handleToggleClick);
|
||||
</script>
|
||||
Reference in New Issue
Block a user