Compare commits
65 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 990d4b0728 | |||
| f7929be18d | |||
| 963722996e | |||
| e4c362030d | |||
| d7bbb7b70b | |||
| 555135aedb | |||
| b3038603e8 | |||
| 37d720ebc3 | |||
| 25e5249739 | |||
| a99c165ba3 | |||
| 60131d6fa9 | |||
| 67070e5fc4 | |||
| ecf730bda7 | |||
| f7b7f7d320 | |||
| 67ec0bffee | |||
| 03822cffee | |||
| e2ccdb68b4 | |||
| 9d0540ecfc | |||
| 2ead477997 | |||
| 3100c1c1e9 | |||
| a91ee9ac55 | |||
| 6a8c75fc94 | |||
| 44bafa1435 | |||
| 7807f98709 | |||
| 965dbbce41 | |||
| f3f0b43b6d | |||
| 4d3b6e4ce2 | |||
| 790a867313 | |||
| bc6fdb6149 | |||
| 54eae0e738 | |||
| 2346842ef5 | |||
| c9d6ce3464 | |||
| aa4f3389a3 | |||
| e8738cca3c | |||
| 17b1bf1e8a | |||
| 634824ff44 | |||
| 60d8f66ad0 | |||
| 0b18d55712 | |||
| 1ddaabe64b | |||
| a5f4d0a28d | |||
| 95320835b6 | |||
| a0db85f1f2 | |||
| b34a041052 | |||
| aa4da842d6 | |||
| f77f8d13d1 | |||
| ed73a3fe72 | |||
| f1cb633cb3 | |||
| 9909d8d7a5 | |||
| c7766edb01 | |||
| ba14074509 | |||
| 36b04537b4 | |||
| 0b9c253402 | |||
| 4dcee7790b | |||
| 66717405db | |||
| 712f556d67 | |||
| 540168d30f | |||
| 26ce6ed4ef | |||
| df4bb9212b | |||
| bbacb11bce | |||
| 4fe81f1e48 | |||
| 3c9ef565b3 | |||
| 59664d139d | |||
| 12e521891a | |||
| e67829562d | |||
| 4c20ee73d3 |
9
.editorconfig
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
charset = utf-8
|
||||||
|
indent_style = space
|
||||||
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
insert_final_newline = true
|
||||||
|
trim_trailing_whitespace = true
|
||||||
1
.env.production
Normal file
@@ -0,0 +1 @@
|
|||||||
|
VITE_API_BASE_URL=https://admin.ua42.com/api/
|
||||||
6
.gitignore
vendored
@@ -13,10 +13,6 @@ yarn-debug.log*
|
|||||||
yarn-error.log*
|
yarn-error.log*
|
||||||
pnpm-debug.log*
|
pnpm-debug.log*
|
||||||
|
|
||||||
# environment variables
|
|
||||||
.env
|
|
||||||
.env.production
|
|
||||||
|
|
||||||
# macOS-specific files
|
# macOS-specific files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
@@ -25,3 +21,5 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
*.tar
|
*.tar
|
||||||
*.gz
|
*.gz
|
||||||
|
|
||||||
|
.claude
|
||||||
|
|||||||
34
AGENTS.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Project Scope Rules
|
||||||
|
|
||||||
|
## 文件范围限制
|
||||||
|
|
||||||
|
本项目根目录:
|
||||||
|
|
||||||
|
./
|
||||||
|
|
||||||
|
所有操作必须限制在当前项目目录内。
|
||||||
|
|
||||||
|
禁止:
|
||||||
|
- 访问项目外文件
|
||||||
|
- 修改父级目录文件
|
||||||
|
- 创建项目外文件
|
||||||
|
- 修改用户目录中的其他内容
|
||||||
|
- 禁止访问服务端仓库
|
||||||
|
|
||||||
|
## 修改规则
|
||||||
|
|
||||||
|
修改前必须:
|
||||||
|
1. 列出将修改的文件
|
||||||
|
2. 说明修改原因
|
||||||
|
3. 等待确认
|
||||||
|
|
||||||
|
禁止修改:
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
.git/
|
||||||
|
build/
|
||||||
|
.env
|
||||||
|
|
||||||
|
## 开发环境
|
||||||
|
|
||||||
|
默认认为已经启动服务,端口为4321
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-check
|
// @ts-check
|
||||||
import { defineConfig } from 'astro/config';
|
import {defineConfig} from 'astro/config';
|
||||||
import solidJs from '@astrojs/solid-js';
|
import solidJs from '@astrojs/solid-js';
|
||||||
import node from '@astrojs/node';
|
import node from '@astrojs/node';
|
||||||
|
|
||||||
@@ -7,8 +7,19 @@ import node from '@astrojs/node';
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
site: 'https://ua42.com',
|
site: 'https://ua42.com',
|
||||||
output: 'server',
|
output: 'server',
|
||||||
|
server: {
|
||||||
|
host: "0.0.0.0",
|
||||||
|
},
|
||||||
integrations: [solidJs()],
|
integrations: [solidJs()],
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: 'standalone'
|
mode: 'standalone'
|
||||||
})
|
}),
|
||||||
|
vite: {
|
||||||
|
plugins: [],
|
||||||
|
server: {
|
||||||
|
watch: {
|
||||||
|
usePolling: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
15
package.json
@@ -10,13 +10,22 @@
|
|||||||
"deploy": "./scripts/deploy.sh"
|
"deploy": "./scripts/deploy.sh"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/node": "^9.5.1",
|
"@astrojs/node": "11.0.2",
|
||||||
"@astrojs/solid-js": "^5.1.3",
|
"@astrojs/solid-js": "^5.1.3",
|
||||||
"astro": "^5.15.8",
|
"astro": "^7.0.6",
|
||||||
|
"dayjs": "^1.11.21",
|
||||||
|
"github-markdown-css": "^5.9.0",
|
||||||
|
"jsdom": "^29.1.1",
|
||||||
|
"ky": "^2.0.2",
|
||||||
"modern-normalize": "^3.0.1",
|
"modern-normalize": "^3.0.1",
|
||||||
"solid-js": "^1.9.10"
|
"photoswipe": "^5.4.4",
|
||||||
|
"shiki": "^4.3.1",
|
||||||
|
"solid-js": "^1.9.14"
|
||||||
},
|
},
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "22.21.1"
|
"node": "22.21.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/jsdom": "^28.0.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
4118
pnpm-lock.yaml
generated
3
pnpm-workspace.yaml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
allowBuilds:
|
||||||
|
esbuild: true
|
||||||
|
sharp: true
|
||||||
BIN
public/favicon.ico
Normal file
|
After Width: | Height: | Size: 17 KiB |
@@ -1,46 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" viewBox="0 0 64 64" role="img" aria-label="placeholder favicon">
|
|
||||||
<defs>
|
|
||||||
<!-- 轻微渐变底色 -->
|
|
||||||
<linearGradient id="g" x1="0" x2="0" y1="0" y2="1">
|
|
||||||
<stop offset="0" stop-color="#f7f8fb"/>
|
|
||||||
<stop offset="1" stop-color="#e6e9f2"/>
|
|
||||||
</linearGradient>
|
|
||||||
|
|
||||||
<!-- 圆角外形的蒙版(用来制造中间空缺) -->
|
|
||||||
<mask id="holeMask">
|
|
||||||
<!-- 全白表示顯示 -->
|
|
||||||
<rect x="0" y="0" width="64" height="64" fill="white"/>
|
|
||||||
<!-- 中间用黑色(掏空) -->
|
|
||||||
<!-- 这里用一个较大的圆角方块作为"空缺" -->
|
|
||||||
<rect x="14" y="14" width="36" height="36" rx="8" ry="8" fill="black"/>
|
|
||||||
</mask>
|
|
||||||
|
|
||||||
<!-- 描边样式(虚线) -->
|
|
||||||
<pattern id="dash" width="6" height="6" patternUnits="userSpaceOnUse">
|
|
||||||
<rect width="6" height="6" fill="none"/>
|
|
||||||
</pattern>
|
|
||||||
</defs>
|
|
||||||
|
|
||||||
<!-- 圆角底板 -->
|
|
||||||
<rect x="2" y="2" width="60" height="60" rx="12" ry="12" fill="url(#g)" stroke="#d9dce8" stroke-width="1"/>
|
|
||||||
|
|
||||||
<!-- 在底板上绘制一个较暗的阴影区域,让边缘有质感 -->
|
|
||||||
<rect x="2" y="34" width="60" height="28" rx="12" ry="12" fill-opacity="0.03" fill="#000"/>
|
|
||||||
|
|
||||||
<!-- 使用mask把中间挖空(透明) -->
|
|
||||||
<g mask="url(#holeMask)">
|
|
||||||
<!-- 这层是底色的延伸,挖空后中间变透明 -->
|
|
||||||
<rect x="2" y="2" width="60" height="60" rx="12" ry="12" fill="url(#g)" />
|
|
||||||
</g>
|
|
||||||
|
|
||||||
<!-- 在被挖空的边缘画一圈圆角虚线作为占位提示 -->
|
|
||||||
<rect x="14" y="14" width="36" height="36" rx="8" ry="8"
|
|
||||||
fill="none" stroke="#9aa0b6" stroke-width="1.5" stroke-dasharray="3 3" />
|
|
||||||
|
|
||||||
<!-- 中心放置一个小图形(可选): 一个微小的“文件”轮廓来提示占位 -->
|
|
||||||
<g transform="translate(28,20)">
|
|
||||||
<path d="M0 0 L8 0 L8 12 L0 12 Z" fill="none" stroke="#9aa0b6" stroke-width="1" stroke-linejoin="round"/>
|
|
||||||
<path d="M5 0 L5 3" stroke="#9aa0b6" stroke-width="1" stroke-linecap="round"/>
|
|
||||||
</g>
|
|
||||||
</svg>
|
|
||||||
|
Before Width: | Height: | Size: 2.0 KiB |
4
public/robots.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
User-agent: *
|
||||||
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: https://ua42.com/sitemap.xml
|
||||||
@@ -5,7 +5,7 @@ PROJECT_ROOT=$(cd -- "$(dirname "${BASH_SOURCE[0]}")/.." &> /dev/null && pwd)
|
|||||||
DOCKERFILE_PATH=./scripts/Dockerfile
|
DOCKERFILE_PATH=./scripts/Dockerfile
|
||||||
IMAGE_NAME=blog
|
IMAGE_NAME=blog
|
||||||
IMAGE_FILE_NAME=$IMAGE_NAME.tar.gz
|
IMAGE_FILE_NAME=$IMAGE_NAME.tar.gz
|
||||||
REMOTE_SERVER=02
|
REMOTE_SERVER=01
|
||||||
REMOTE_PATH=/srv/docker/nginx/www
|
REMOTE_PATH=/srv/docker/nginx/www
|
||||||
DOCKER_NETWORK=docker_app-bridge
|
DOCKER_NETWORK=docker_app-bridge
|
||||||
|
|
||||||
|
|||||||
1
src/assets/icon/back-top.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1784628432297" class="icon" viewBox="0 0 1035 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="9153" xmlns:xlink="http://www.w3.org/1999/xlink" width="202.1484375" height="200"><path d="M513.407379 0C230.713951 0 1.407379 229.306573 1.407379 512c0 282.693427 229.306573 512 512 512 282.693427 0 512-229.293792 512-512C1025.407379 229.306573 796.100806 0 513.407379 0z m26.17579 817.737837c-6.812352 6.799571-16.756085 10.991787-26.17579 10.991787-9.943733 0-19.37622-4.192216-26.175791-10.991787-6.799571-6.812352-10.991787-16.756085-10.991787-26.699818 0-9.943733 4.192216-19.900247 10.991787-26.699818s16.756085-10.991787 26.175791-10.991787c9.943733 0 19.363439 4.192216 26.17579 10.991787s10.991787 16.756085 10.991787 26.699818c0 9.943733-4.192216 19.887466-10.991787 26.699818z m-26.17579-87.435832c-20.424274 0-37.167578-16.743304-37.167578-37.691605 0-20.424274 16.743304-37.691605 37.167578-37.691605 20.411493 0 37.167578 16.756085 37.167577 37.691605 0 20.948301-16.756085 37.691605-37.167577 37.691605z m258.089717-237.678225c-7.847625 7.860406-17.804139 11.515814-27.747872 11.515814-9.943733 0-19.900247-3.668189-27.747871-11.515814l-163.343069-163.343069v261.23388c0 21.472328-17.804139 39.263686-39.263686 39.263686s-39.263686-17.791358-39.263687-39.263686V329.293492l-163.330287 163.343069c-15.184004 15.184004-40.31174 15.184004-55.495744 0-15.184004-15.184004-15.184004-40.31174 0-55.495744L485.646726 206.798972c15.184004-15.184004 40.31174-15.184004 55.495743 0l230.354627 230.341845c15.184004 15.171222 15.184004 39.774932 0 55.482963z m0 0" p-id="9154"></path><path d="M771.497096 492.636561c-7.847625 7.860406-17.804139 11.515814-27.747872 11.515814-9.943733 0-19.900247-3.668189-27.747871-11.515814l-163.343069-163.343069v261.23388c0 21.472328-17.804139 39.263686-39.263686 39.263686s-39.263686-17.791358-39.263687-39.263686V329.293492l-163.330287 163.343069c-15.184004 15.184004-40.31174 15.184004-55.495744 0-15.184004-15.184004-15.184004-40.31174 0-55.495744L485.659507 206.798972c15.184004-15.184004 40.31174-15.184004 55.495744 0l230.354626 230.341845c15.171222 15.184004 15.171222 39.787713-0.012781 55.495744zM513.407379 730.302005c-20.424274 0-37.167578-16.743304-37.167578-37.691605 0-20.424274 16.743304-37.691605 37.167578-37.691605 20.411493 0 37.167578 16.756085 37.167577 37.691605 0 20.948301-16.756085 37.691605-37.167577 37.691605M513.407379 828.729624c-20.424274 0-37.167578-16.743304-37.167578-37.691605 0-20.424274 16.743304-37.691605 37.167578-37.691605 20.411493 0 37.167578 16.743304 37.167577 37.691605 0 20.93552-16.756085 37.691605-37.167577 37.691605" fill="#FFFFFF" p-id="9155"></path></svg>
|
||||||
|
After Width: | Height: | Size: 2.7 KiB |
BIN
src/assets/icon/calendar.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
src/assets/icon/client.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
src/assets/icon/eye.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
BIN
src/assets/icon/folder.png
Normal file
|
After Width: | Height: | Size: 8.4 KiB |
1
src/assets/icon/github.svg
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1785642324396" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="7302" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M695.744 981.312H419.712c-26.816 0-47.296-21.056-47.296-48.64V739.84c0-29.184 6.336-56.768 17.344-81.088-129.28-48.64-214.528-150.72-214.528-264.256 0-53.44 17.344-103.68 50.496-147.52C213.12 204.8 209.92 151.296 213.12 89.664c3.2-27.52 23.68-46.976 48.896-46.976 14.208 0 134.08 1.6 203.52 64.832a504.384 504.384 0 0 1 184.512 0C717.888 44.288 837.696 42.688 853.504 42.688a47.36 47.36 0 0 1 47.36 45.376c4.672 61.568 0 115.072-12.672 157.248 33.152 45.44 50.496 95.68 50.496 147.52 0 113.472-85.184 215.68-214.528 264.32 11.072 25.856 17.344 53.44 17.344 81.024v192.896c1.6 27.52-20.48 50.24-45.76 50.24z m-228.672-97.28h181.376V739.84c0-27.52-12.608-53.504-33.152-71.36a48.96 48.96 0 0 1-15.744-50.24c4.736-17.856 18.944-32.384 36.288-35.648 123.008-24.32 208.192-102.144 208.192-189.696 0-46.976-25.216-82.688-45.76-105.344a47.36 47.36 0 0 1-7.872-55.168c6.336-12.928 15.808-40.512 15.808-89.152-39.488 6.464-85.184 19.456-102.528 45.44a47.552 47.552 0 0 1-50.56 19.392 393.024 393.024 0 0 0-193.92 0c-18.944 4.864-37.888-3.2-50.56-19.456-17.28-25.92-63.04-38.912-102.464-45.376 1.6 48.64 9.472 76.16 15.744 89.152a53.696 53.696 0 0 1-7.872 55.168c-20.48 22.656-45.76 58.368-45.76 105.344 0 87.552 85.184 163.776 208.256 189.696 17.28 3.2 31.552 17.792 36.224 35.648a51.008 51.008 0 0 1-15.744 50.24c-20.48 17.856-33.152 43.776-33.152 71.36v144.256h3.2z" fill="#172B4D" p-id="7303"></path><path d="M403.968 788.416c-212.928 0-309.12-194.56-313.92-202.688-11.008-24.32-1.536-53.44 20.48-64.832a47.424 47.424 0 0 1 63.168 21.12c3.136 6.4 80.448 157.248 241.28 149.12a46.08 46.08 0 0 1 48.896 47.04c1.6 27.52-18.88 50.24-45.696 50.24h-14.208z" fill="#172B4D" p-id="7304"></path></svg>
|
||||||
|
After Width: | Height: | Size: 2.0 KiB |
BIN
src/assets/icon/tag.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
69
src/components/BackTop.astro
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
---
|
||||||
|
// 后面的 ?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,28 +1,46 @@
|
|||||||
|
---
|
||||||
|
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>
|
<style>
|
||||||
footer {
|
footer {
|
||||||
background-color: #1a1a1a;
|
background: #22252b;
|
||||||
height: 70px;
|
height: 70px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
color: aliceblue;
|
|
||||||
max-width: var(--layout-width);
|
max-width: var(--layout-width);
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
color: #f9f8f6;
|
color: #fff;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) footer {
|
||||||
|
background: var(--background);
|
||||||
|
box-shadow: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .content {
|
||||||
|
color: #ffffff;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<footer>
|
|
||||||
<div class="content">
|
|
||||||
<a href="https://beian.miit.gov.cn/#/Integrated/index">
|
|
||||||
备案号:鄂ICP备2023000060号-2
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
</footer>
|
|
||||||
|
|||||||
@@ -1,10 +1,37 @@
|
|||||||
|
---
|
||||||
|
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>
|
<style>
|
||||||
header {
|
header {
|
||||||
height: 60px;
|
height: 60px;
|
||||||
position: sticky;
|
position: sticky;
|
||||||
top: 0;
|
top: 0;
|
||||||
z-index: 99999;
|
z-index: 99999;
|
||||||
box-shadow: rgba(17, 17, 26, 0.1) 0px 1px 0px;
|
box-shadow: var(--shadow);
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
}
|
}
|
||||||
@@ -13,7 +40,29 @@
|
|||||||
max-width: var(--layout-width);
|
max-width: var(--layout-width);
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
padding: 0 16px;
|
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 {
|
.main-nav .menu {
|
||||||
@@ -22,22 +71,43 @@
|
|||||||
gap: 20px;
|
gap: 20px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
margin-right: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.github-icon {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
display: block;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* element: menu-item */
|
|
||||||
.main-nav .menu-item a {
|
.main-nav .menu-item a {
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.main-nav .menu-item a:hover {
|
.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>
|
</style>
|
||||||
|
|
||||||
<header>
|
|
||||||
<nav class="main-nav">
|
|
||||||
<ul class="menu">
|
|
||||||
<li class="menu-item"><a href="/">首页</a></li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
</header>
|
|
||||||
|
|||||||
152
src/components/IndexSidebar.astro
Normal file
@@ -0,0 +1,152 @@
|
|||||||
|
---
|
||||||
|
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>
|
||||||
46
src/components/IndexView.astro
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
---
|
||||||
|
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>
|
||||||
131
src/components/LazyImage.astro
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
---
|
||||||
|
interface Props {
|
||||||
|
src: string;
|
||||||
|
alt?: string;
|
||||||
|
width?: number;
|
||||||
|
height?: number;
|
||||||
|
class?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
src,
|
||||||
|
alt = "",
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
class: className = ""
|
||||||
|
} = Astro.props;
|
||||||
|
---
|
||||||
|
|
||||||
|
<div
|
||||||
|
class={`lazy-image ${className}`}
|
||||||
|
data-src={src}
|
||||||
|
style={`aspect-ratio:${width}/${height}`}
|
||||||
|
>
|
||||||
|
<div class="placeholder"></div>
|
||||||
|
|
||||||
|
<img
|
||||||
|
class="real-image"
|
||||||
|
alt={alt}
|
||||||
|
width={width}
|
||||||
|
height={height}
|
||||||
|
loading="lazy"
|
||||||
|
decoding="async"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.lazy-image {
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lazy-image img {
|
||||||
|
display: block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
object-fit: cover;
|
||||||
|
}
|
||||||
|
|
||||||
|
.placeholder {
|
||||||
|
position: absolute;
|
||||||
|
inset: 0;
|
||||||
|
background: #f3f4f6;
|
||||||
|
background-image: linear-gradient(
|
||||||
|
90deg,
|
||||||
|
#f3f4f6 0%,
|
||||||
|
#e5e7eb 50%,
|
||||||
|
#f3f4f6 100%
|
||||||
|
);
|
||||||
|
background-size: 200% 100%;
|
||||||
|
animation: loading 1.5s infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes loading {
|
||||||
|
from {
|
||||||
|
background-position: 200% 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
background-position: -200% 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.real-image {
|
||||||
|
opacity: 0;
|
||||||
|
transition: opacity .35s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.real-image.loaded {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
|
||||||
|
<script>
|
||||||
|
function initLazyImages() {
|
||||||
|
const images = document.querySelectorAll(".lazy-image");
|
||||||
|
|
||||||
|
const observer = new IntersectionObserver(
|
||||||
|
entries => {
|
||||||
|
entries.forEach(entry => {
|
||||||
|
|
||||||
|
if (!entry.isIntersecting) return;
|
||||||
|
|
||||||
|
const container = entry.target as HTMLElement;
|
||||||
|
const img = container.querySelector(
|
||||||
|
".real-image"
|
||||||
|
) as HTMLImageElement;
|
||||||
|
|
||||||
|
const src = container.dataset.src;
|
||||||
|
|
||||||
|
if (!src) return;
|
||||||
|
|
||||||
|
img.src = src;
|
||||||
|
|
||||||
|
img.onload = () => {
|
||||||
|
img.classList.add("loaded");
|
||||||
|
|
||||||
|
const placeholder =
|
||||||
|
container.querySelector(".placeholder");
|
||||||
|
|
||||||
|
placeholder?.remove();
|
||||||
|
};
|
||||||
|
|
||||||
|
observer.unobserve(container);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{
|
||||||
|
rootMargin: "300px"
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
images.forEach(img => observer.observe(img));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
initLazyImages();
|
||||||
|
</script>
|
||||||
185
src/components/Post/Item.astro
Normal file
@@ -0,0 +1,185 @@
|
|||||||
|
---
|
||||||
|
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>
|
||||||
37
src/components/Post/List.astro
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
---
|
||||||
|
import type {Post} from "@/types/post";
|
||||||
|
import PostItem from '@/components/Post/Item.astro'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
posts: Post[]
|
||||||
|
}
|
||||||
|
|
||||||
|
const {posts} = Astro.props
|
||||||
|
---
|
||||||
|
|
||||||
|
<section class="section">
|
||||||
|
<div class="post-list">
|
||||||
|
{posts.map(post => (
|
||||||
|
<PostItem post={post}/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.section {
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 860px){
|
||||||
|
.post-list{
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
67
src/components/Post/Pagination.astro
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
---
|
||||||
|
interface Props {
|
||||||
|
page: number
|
||||||
|
totalPage: number
|
||||||
|
}
|
||||||
|
|
||||||
|
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>}
|
||||||
|
</nav>}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
/* ========== 分页 ========== */
|
||||||
|
.pagination {
|
||||||
|
width: 100%;
|
||||||
|
text-align: center;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.link.disabled {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-color: var(--border);
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
75
src/components/ThemeIcon.astro
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
---
|
||||||
|
---
|
||||||
|
<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>
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
export const metadata = {
|
export const metadata = {
|
||||||
siteTitle: "42的博客",
|
site: "https://ua42.com",
|
||||||
|
siteTitle: "Uroboros",
|
||||||
|
postPageSize: 6
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,80 +1,42 @@
|
|||||||
---
|
---
|
||||||
import "@/styles/base.css";
|
import "@/styles/global.css";
|
||||||
|
|
||||||
import BaseHeader from "@/components/BaseHeader.astro";
|
import BaseHeader from "@/components/BaseHeader.astro";
|
||||||
import BaseFooter from "@/components/BaseFooter.astro";
|
import BaseFooter from "@/components/BaseFooter.astro";
|
||||||
|
import BackTop from "@/components/BackTop.astro";
|
||||||
|
|
||||||
import { metadata } from "@/consts.ts";
|
import { metadata } from "@/consts.ts";
|
||||||
const { siteTitle } = metadata;
|
const { siteTitle } = metadata;
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title?: string;
|
||||||
|
description?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { title, description } = Astro.props;
|
||||||
|
const pageTitle = title ? `${title} - ${siteTitle}` : siteTitle;
|
||||||
---
|
---
|
||||||
|
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="zh-CN">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta
|
<meta
|
||||||
name="viewport"
|
name="viewport"
|
||||||
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
||||||
/>
|
/>
|
||||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico" />
|
||||||
<meta name="generator" content={Astro.generator} />
|
<meta name="generator" content={Astro.generator} />
|
||||||
<title>{siteTitle}</title>
|
<meta name="description" content={description} />
|
||||||
|
<meta name="theme-color" content="#ffffff" />
|
||||||
|
<title>{pageTitle}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<BaseHeader />
|
<BaseHeader />
|
||||||
<main>
|
<main class="main">
|
||||||
<div class="grid-background"></div>
|
|
||||||
<slot />
|
<slot />
|
||||||
</main>
|
</main>
|
||||||
<BaseFooter />
|
<BaseFooter />
|
||||||
|
<BackTop />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
<style>
|
|
||||||
html,
|
|
||||||
body {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
body {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
main {
|
|
||||||
flex: 1;
|
|
||||||
max-width: var(--layout-width);
|
|
||||||
width: 100%;
|
|
||||||
margin: 0 auto;
|
|
||||||
padding: 16px;
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
|
|
||||||
.grid-background {
|
|
||||||
position: absolute;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
z-index: -1;
|
|
||||||
background-color: #ffffff;
|
|
||||||
opacity: 0.3;
|
|
||||||
background-image: linear-gradient(#d7edfb 2px, transparent 2px),
|
|
||||||
linear-gradient(90deg, #d7edfb 2px, transparent 2px),
|
|
||||||
linear-gradient(#d7edfb 1px, transparent 1px),
|
|
||||||
linear-gradient(90deg, #d7edfb 1px, #ffffff 1px);
|
|
||||||
background-size:
|
|
||||||
50px 50px,
|
|
||||||
50px 50px,
|
|
||||||
10px 10px,
|
|
||||||
10px 10px;
|
|
||||||
background-position:
|
|
||||||
-2px -2px,
|
|
||||||
-2px -2px,
|
|
||||||
-1px -1px,
|
|
||||||
-1px -1px;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
10
src/lib/format.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import dayjs from 'dayjs';
|
||||||
|
import utc from 'dayjs/plugin/utc';
|
||||||
|
import timezone from 'dayjs/plugin/timezone';
|
||||||
|
|
||||||
|
dayjs.extend(utc);
|
||||||
|
dayjs.extend(timezone);
|
||||||
|
|
||||||
|
export const formatDatetime = (date: string,format = 'YYYY-MM-DD HH:mm') => {
|
||||||
|
return dayjs(date).tz('Asia/Shanghai').format(format);
|
||||||
|
};
|
||||||
85
src/lib/highlight.js
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import {JSDOM} from 'jsdom'
|
||||||
|
import {createHighlighter} from 'shiki'
|
||||||
|
|
||||||
|
const highlighter = await createHighlighter({
|
||||||
|
themes: ['github-dark-dimmed'],
|
||||||
|
langs: [
|
||||||
|
"bash",
|
||||||
|
"json",
|
||||||
|
"yaml",
|
||||||
|
"xml",
|
||||||
|
"html",
|
||||||
|
"css",
|
||||||
|
"scss",
|
||||||
|
"javascript",
|
||||||
|
"typescript",
|
||||||
|
"jsx",
|
||||||
|
"tsx",
|
||||||
|
"vue",
|
||||||
|
"markdown",
|
||||||
|
"sql",
|
||||||
|
"graphql",
|
||||||
|
"python",
|
||||||
|
"java",
|
||||||
|
"go",
|
||||||
|
"rust",
|
||||||
|
"c",
|
||||||
|
"cpp",
|
||||||
|
"csharp",
|
||||||
|
"php",
|
||||||
|
"ruby",
|
||||||
|
"kotlin",
|
||||||
|
"swift",
|
||||||
|
"dockerfile",
|
||||||
|
"nginx"
|
||||||
|
]
|
||||||
|
})
|
||||||
|
|
||||||
|
const resolveLang = (lang) => {
|
||||||
|
const supported = highlighter.getLoadedLanguages?.() || []
|
||||||
|
if (!lang) return 'text'
|
||||||
|
if (supported.includes(lang)) return lang
|
||||||
|
return 'text'
|
||||||
|
}
|
||||||
|
|
||||||
|
export const highlightHtmlWithJsdom = async (rawHtml) => {
|
||||||
|
const dom = new JSDOM(rawHtml)
|
||||||
|
const document = dom.window.document
|
||||||
|
|
||||||
|
const codeElements = document.querySelectorAll('pre code')
|
||||||
|
|
||||||
|
for (const codeEl of codeElements) {
|
||||||
|
const preEl = codeEl.parentElement
|
||||||
|
if (!preEl || preEl.tagName !== 'PRE') continue
|
||||||
|
|
||||||
|
const codeContent = codeEl.textContent?.trim() || ''
|
||||||
|
|
||||||
|
// 提取语言
|
||||||
|
let lang = 'text'
|
||||||
|
for (const cls of codeEl.classList) {
|
||||||
|
if (cls.startsWith('language-')) {
|
||||||
|
lang = cls.slice('language-'.length)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lang = resolveLang(lang)
|
||||||
|
|
||||||
|
// 生成高亮 HTML
|
||||||
|
const highlighted = highlighter.codeToHtml(codeContent, {
|
||||||
|
lang,
|
||||||
|
theme: 'github-dark-dimmed',
|
||||||
|
})
|
||||||
|
|
||||||
|
// 替换 DOM
|
||||||
|
const wrapper = document.createElement('div')
|
||||||
|
wrapper.innerHTML = highlighted.trim()
|
||||||
|
|
||||||
|
const newNode = wrapper.firstChild
|
||||||
|
if (newNode && preEl.parentNode) {
|
||||||
|
preEl.parentNode.replaceChild(newNode, preEl)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return dom.serialize()
|
||||||
|
}
|
||||||
51
src/lib/request.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import ky, {type Options} from 'ky'
|
||||||
|
|
||||||
|
type ForwardHeaderSource = Headers | Record<string, string | undefined> | undefined | null
|
||||||
|
|
||||||
|
const api = ky.create({
|
||||||
|
baseUrl: import.meta.env.VITE_API_BASE_URL
|
||||||
|
});
|
||||||
|
|
||||||
|
const pickHeader = (source: ForwardHeaderSource, name: string): string | undefined => {
|
||||||
|
if (!source) return undefined
|
||||||
|
if (source instanceof Headers) return source.get(name) ?? undefined
|
||||||
|
return source[name] ?? source[name.toLowerCase()]
|
||||||
|
}
|
||||||
|
|
||||||
|
const buildForwardHeaders = (source: ForwardHeaderSource): Record<string, string> => {
|
||||||
|
const xff = pickHeader(source, 'x-forwarded-for')
|
||||||
|
const realIp = pickHeader(source, 'x-real-ip')
|
||||||
|
const cfIp = pickHeader(source, 'cf-connecting-ip')
|
||||||
|
const ua = pickHeader(source, 'user-agent')
|
||||||
|
const referer = pickHeader(source, 'referer')
|
||||||
|
const host = pickHeader(source, 'host')
|
||||||
|
const proto = pickHeader(source, 'x-forwarded-proto')
|
||||||
|
|
||||||
|
return {
|
||||||
|
...(xff ? {'x-forwarded-for': xff} : {}),
|
||||||
|
...(realIp ? {'x-real-ip': realIp} : {}),
|
||||||
|
...(cfIp ? {'cf-connecting-ip': cfIp} : {}),
|
||||||
|
...(ua ? {'user-agent': ua} : {}),
|
||||||
|
...(referer ? {referer} : {}),
|
||||||
|
...(host ? {host} : {}),
|
||||||
|
...(proto ? {'x-forwarded-proto': proto} : {})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const createHttp = (forwardHeadersSource?: ForwardHeaderSource) => {
|
||||||
|
const forwardedHeaders = buildForwardHeaders(forwardHeadersSource)
|
||||||
|
|
||||||
|
return {
|
||||||
|
get: async <T = unknown>(url: string, options?: Options): Promise<T> => {
|
||||||
|
return api.get(url, {
|
||||||
|
...options,
|
||||||
|
headers: {
|
||||||
|
...forwardedHeaders,
|
||||||
|
...(options?.headers ?? {})
|
||||||
|
}
|
||||||
|
}).json<T>()
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export const http = createHttp();
|
||||||
29
src/pages/404.astro
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
---
|
||||||
|
import Layout from "@/layouts/Layout.astro";
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="404">
|
||||||
|
<div class="not-found">
|
||||||
|
<h1>404 Not Found</h1>
|
||||||
|
<a class="back-home" href="/">返回首页</a>
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.not-found {
|
||||||
|
flex: 1;
|
||||||
|
width: 100%;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-home {
|
||||||
|
background: black;
|
||||||
|
color: white;
|
||||||
|
padding: 10px 20px;
|
||||||
|
border-radius: 12px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
198
src/pages/archive.astro
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
---
|
||||||
|
import Layout from "@/layouts/Layout.astro";
|
||||||
|
import type {Archive} from "@/types/archive";
|
||||||
|
import {createHttp} from "@/lib/request";
|
||||||
|
|
||||||
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
|
const {data} = await http.get<ApiResponse<Archive>>("posts/archives");
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="归档">
|
||||||
|
<div class="page-content">
|
||||||
|
<div class="archive">
|
||||||
|
{
|
||||||
|
data.map((year) => (
|
||||||
|
<div class="archive-year">
|
||||||
|
<h2 class="year-title">
|
||||||
|
<span class="year-badge">{year.year}</span>
|
||||||
|
<span class="year-count">共 {year.total} 篇</span>
|
||||||
|
</h2>
|
||||||
|
<div>
|
||||||
|
{year.list.map((month) => (
|
||||||
|
<div class="month-group">
|
||||||
|
<h3 class="month-title">{month.month} 月</h3>
|
||||||
|
<ul class="post-list">
|
||||||
|
{month.list.map((post) => (
|
||||||
|
<li class="post-item">
|
||||||
|
<span class="post-date">
|
||||||
|
{post.published_at_display}
|
||||||
|
</span>
|
||||||
|
<a href={`/post/${post.slug}`}>{post.title}</a>
|
||||||
|
<span class="post-cat">{post.category_name}</span>
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
:root {
|
||||||
|
--border: #e5e7eb;
|
||||||
|
--radius: 12px;
|
||||||
|
--shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 860px;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.archive-year {
|
||||||
|
margin-bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.year-title {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 14px;
|
||||||
|
font-size: 24px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin-bottom: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.year-title .year-badge {
|
||||||
|
background: linear-gradient(135deg, #4f6df5, #7b5cf0);
|
||||||
|
color: #fff;
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 999px;
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.year-title .year-count {
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-weight: 400;
|
||||||
|
}
|
||||||
|
|
||||||
|
.year-title::after {
|
||||||
|
content: "";
|
||||||
|
flex: 1;
|
||||||
|
height: 1px;
|
||||||
|
background: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 月份分组 */
|
||||||
|
.month-group {
|
||||||
|
position: relative;
|
||||||
|
padding-left: 28px;
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 时间轴竖线 */
|
||||||
|
.month-group::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
left: 7px;
|
||||||
|
top: 8px;
|
||||||
|
bottom: 0;
|
||||||
|
width: 2px;
|
||||||
|
background: var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.month-title {
|
||||||
|
position: relative;
|
||||||
|
font-size: 17px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--primary);
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .month-title{
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 月份节点圆点 */
|
||||||
|
.month-title::before {
|
||||||
|
content: "";
|
||||||
|
position: absolute;
|
||||||
|
left: -26px;
|
||||||
|
top: 8px;
|
||||||
|
width: 10px;
|
||||||
|
height: 10px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: var(--primary);
|
||||||
|
box-shadow: 0 0 0 3px var(--tag-bg);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-list {
|
||||||
|
list-style: none;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: var(--radius);
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 14px;
|
||||||
|
padding: 18px 20px;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
transition: background 0.2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-item:last-child {
|
||||||
|
border-bottom: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-item:hover {
|
||||||
|
background: #f9faff;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .post-item:hover {
|
||||||
|
background: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-date {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
width: 52px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-item a {
|
||||||
|
flex: 1;
|
||||||
|
min-width: 0;
|
||||||
|
font-size: 15px;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-item a:hover {
|
||||||
|
color: var(--primary);
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .post-item a:hover {
|
||||||
|
color: inherit;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-cat {
|
||||||
|
flex-shrink: 0;
|
||||||
|
font-size: 12px;
|
||||||
|
color: var(--primary);
|
||||||
|
background: var(--tag-bg);
|
||||||
|
padding: 2px 10px;
|
||||||
|
border-radius: 999px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
140
src/pages/embed/gitea.astro
Normal file
@@ -0,0 +1,140 @@
|
|||||||
|
---
|
||||||
|
const noindex = true;
|
||||||
|
import {metadata} from '@/consts.ts'
|
||||||
|
---
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="zh-CN">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8"/>
|
||||||
|
<meta
|
||||||
|
name="viewport"
|
||||||
|
content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
|
||||||
|
/>
|
||||||
|
<link rel="icon" type="image/svg+xml" href="/favicon.ico"/>
|
||||||
|
<meta name="generator" content={Astro.generator}/>
|
||||||
|
<title>Gitea 入口</title>
|
||||||
|
<meta name="theme-color" content="#ffffff"/>
|
||||||
|
<meta name="robots" content="noindex, nofollow">
|
||||||
|
<style>
|
||||||
|
@import "modern-normalize";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--bg: #f6f7f9;
|
||||||
|
--card-bg: #ffffff;
|
||||||
|
--border: #e5e7eb;
|
||||||
|
--text-color: #2b2f36;
|
||||||
|
--text-secondary: #6b7280;
|
||||||
|
--primary: #4f6df5;
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
margin: 0;
|
||||||
|
min-height: 100vh;
|
||||||
|
background: var(--bg);
|
||||||
|
color: var(--text-color);
|
||||||
|
font-family: system-ui, -apple-system, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
|
||||||
|
-webkit-font-smoothing: antialiased;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-container {
|
||||||
|
height: 100vh;
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
padding: 24px 24px 24px 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-card {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 520px;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border: 1px solid var(--border);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-card__title {
|
||||||
|
padding: 14px 20px;
|
||||||
|
font-size: 15px;
|
||||||
|
font-weight: 600;
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
gap: 16px;
|
||||||
|
padding: 13px 20px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item + .gitea-item {
|
||||||
|
border-top: 1px solid var(--border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item:hover {
|
||||||
|
background: #fafbfc;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item__label {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item__link {
|
||||||
|
color: var(--primary);
|
||||||
|
text-decoration: none;
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.gitea-item__link:hover {
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="page-container">
|
||||||
|
<div class="gitea-card">
|
||||||
|
<div class="gitea-card__title">常用入口</div>
|
||||||
|
<div class="gitea-content">
|
||||||
|
<div class="gitea-item">
|
||||||
|
<span class="gitea-item__label">博客地址</span>
|
||||||
|
<a class="gitea-item__link" target="_blank" href="https://ua42.com">点击访问</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gitea-item">
|
||||||
|
<span class="gitea-item__label">博客管理后台(支持游客查看)</span>
|
||||||
|
<a class="gitea-item__link" target="_blank" href="https://admin.ua42.com">点击访问</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gitea-item">
|
||||||
|
<span class="gitea-item__label">仓库地址</span>
|
||||||
|
<a class="gitea-item__link" target="_blank" href="https://git.ua42.com/beggin">点击访问</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gitea-item">
|
||||||
|
<span class="gitea-item__label">博客服务端仓库</span>
|
||||||
|
<a class="gitea-item__link" target="_blank" href="https://git.ua42.com/beggin/blog-server">点击访问</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="gitea-item">
|
||||||
|
<span class="gitea-item__label">博客服务端 API文档</span>
|
||||||
|
<a class="gitea-item__link" target="_blank" href="https://dev.ua42.com/docs/server-documentation.html">点击访问</a>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
@@ -1,33 +1,25 @@
|
|||||||
---
|
---
|
||||||
import Layout from "@/layouts/Layout.astro";
|
import Layout from "@/layouts/Layout.astro";
|
||||||
|
import IndexView from "@/components/IndexView.astro";
|
||||||
|
import type { Post } from "@/types/post";
|
||||||
|
import { createHttp } from "@/lib/request";
|
||||||
|
import { metadata } from "@/consts.ts";
|
||||||
|
|
||||||
const posts = [
|
const http = createHttp(Astro.request.headers);
|
||||||
{
|
|
||||||
title: "First Post",
|
const { list, total } = await http.get<ApiPageResponse<Post>>("posts", {
|
||||||
date: "2024-01-01",
|
searchParams: {
|
||||||
summary: "This is the summary of the first post.",
|
page: 1,
|
||||||
|
page_size: metadata.postPageSize,
|
||||||
},
|
},
|
||||||
];
|
});
|
||||||
|
const totalPage = Math.ceil(total / metadata.postPageSize);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout description="天若有情天亦老,人间正道是沧桑。" title="博客首页">
|
||||||
<div>
|
<IndexView
|
||||||
{
|
posts={list}
|
||||||
posts.map((post) => (
|
page={1}
|
||||||
<a href={`/posts/${post.title.replace(/\s+/g, "-").toLowerCase()}`}>
|
totalPage={totalPage}
|
||||||
<h2>{post.title}</h2>
|
/>
|
||||||
<p>{post.date}</p>
|
|
||||||
<p class="summary">{post.summary}</p>
|
|
||||||
</a>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
</div>
|
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|
||||||
<style>
|
|
||||||
.summary {
|
|
||||||
line-height: 2;
|
|
||||||
font-size: 16px;
|
|
||||||
color: rgb(66, 63, 63);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|||||||
36
src/pages/page/[...page].astro
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
---
|
||||||
|
import Layout from "@/layouts/Layout.astro";
|
||||||
|
import type { Post } from "@/types/post";
|
||||||
|
import { createHttp } from "@/lib/request";
|
||||||
|
import { metadata } from "@/consts.ts";
|
||||||
|
import IndexView from "@/components/IndexView.astro";
|
||||||
|
|
||||||
|
const { page } = Astro.params;
|
||||||
|
|
||||||
|
if (isNaN(Number(page))) {
|
||||||
|
return Astro.redirect("/");
|
||||||
|
}
|
||||||
|
|
||||||
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
|
const { list, total } = await http.get<ApiPageResponse<Post>>("posts", {
|
||||||
|
searchParams: {
|
||||||
|
page,
|
||||||
|
page_size: metadata.postPageSize,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const totalPage = Math.ceil(total / metadata.postPageSize);
|
||||||
|
|
||||||
|
if (totalPage < Number(page)) {
|
||||||
|
return Astro.redirect("/404");
|
||||||
|
}
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout description="天若有情天亦老,人间正道是沧桑。" title="博客首页">
|
||||||
|
<IndexView
|
||||||
|
posts={list}
|
||||||
|
page={Number(page)}
|
||||||
|
totalPage={totalPage}
|
||||||
|
/>
|
||||||
|
</Layout>
|
||||||
212
src/pages/post/[...slug].astro
Normal file
@@ -0,0 +1,212 @@
|
|||||||
|
---
|
||||||
|
import "@/styles/github-markdown.css";
|
||||||
|
import "@/styles/github-markdown-reset.css";
|
||||||
|
import "photoswipe/dist/photoswipe.css";
|
||||||
|
|
||||||
|
import Layout from "@/layouts/Layout.astro";
|
||||||
|
import { createHttp } from "@/lib/request.ts";
|
||||||
|
import { highlightHtmlWithJsdom } from "@/lib/highlight.js";
|
||||||
|
import { formatDatetime } from "@/lib/format.ts";
|
||||||
|
import type { Post } from "@/types";
|
||||||
|
|
||||||
|
const { slug } = Astro.params;
|
||||||
|
|
||||||
|
let data: Post;
|
||||||
|
|
||||||
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await http.get<ApiResponse<Post>>(`posts/${slug}`);
|
||||||
|
data = res.data;
|
||||||
|
} catch (error) {
|
||||||
|
return Astro.redirect("/404");
|
||||||
|
}
|
||||||
|
const content = await highlightHtmlWithJsdom(data.content);
|
||||||
|
const published_at = formatDatetime(data.published_at, "YYYY 年 M 月 D 日");
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title={data.title} description={data.summary}>
|
||||||
|
<div class="page-content">
|
||||||
|
<div class="post">
|
||||||
|
<h1 class="post-title">{data.title}</h1>
|
||||||
|
|
||||||
|
<div class="post-meta">
|
||||||
|
<div class="published-at">
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
width="24"
|
||||||
|
height="24"
|
||||||
|
viewBox="0 0 24 24"
|
||||||
|
fill="none"
|
||||||
|
stroke="currentColor"
|
||||||
|
stroke-width="2"
|
||||||
|
stroke-linecap="round"
|
||||||
|
stroke-linejoin="round"
|
||||||
|
class="lucide lucide-calendar-days-icon lucide-calendar-days"
|
||||||
|
>
|
||||||
|
<path d="M8 2v4"></path>
|
||||||
|
<path d="M16 2v4"></path>
|
||||||
|
<rect width="18" height="18" x="3" y="4" rx="2"></rect>
|
||||||
|
<path d="M3 10h18"></path>
|
||||||
|
<path d="M8 14h.01"></path>
|
||||||
|
<path d="M12 14h.01"></path>
|
||||||
|
<path d="M16 14h.01"></path>
|
||||||
|
<path d="M8 18h.01"></path>
|
||||||
|
<path d="M12 18h.01"></path>
|
||||||
|
<path d="M16 18h.01"></path>
|
||||||
|
</svg>
|
||||||
|
{published_at}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="post-view">
|
||||||
|
<svg
|
||||||
|
viewBox="0 0 1024 1024"
|
||||||
|
version="1.1"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
p-id="5122"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M509.618 415.795c-42.695 0-77.253 38.372-77.253 85.738 0 47.352 34.558 86.22 77.253 86.22 42.667 0 76.716-38.867 76.716-86.22 0-47.352-34.049-85.738-76.716-85.738z m1.9-177.9c-211.548 0-383.265 159.859-383.265 274.587 0 114.727 171.717 273.624 383.266 273.624 212.484 0 384.227-162.522 384.227-273.624 0-111.088-171.743-274.587-384.227-274.587z m-1.446 452.006c-89.7 0-162.134-81.71-162.134-181.903 0-101.157 72.435-182.397 162.134-182.397 90.183 0 163.1 81.241 163.1 182.397 0 100.206-72.917 181.903-163.1 181.903z"
|
||||||
|
p-id="5123"></path>
|
||||||
|
</svg>
|
||||||
|
{data.view_count}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="markdown-body" data-color-mode="dark" set:html={content} />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.post {
|
||||||
|
background: #fff;
|
||||||
|
border-radius: 12px;
|
||||||
|
overflow: auto;
|
||||||
|
padding: 24px;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-title {
|
||||||
|
margin-bottom: 16px;
|
||||||
|
font-size: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-meta {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.published-at {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
color: #6b7280;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.published-at svg {
|
||||||
|
width: 18px;
|
||||||
|
height: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.markdown-body img) {
|
||||||
|
object-fit: contain;
|
||||||
|
height: auto !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-view {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 4px;
|
||||||
|
color: #6b7280;
|
||||||
|
padding-right: 12px;
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post-view svg {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
fill: currentColor; /* 让填充跟随 color */
|
||||||
|
stroke: currentColor; /* 让描边也跟随 color */
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.post-title {
|
||||||
|
font-size: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.post {
|
||||||
|
padding: 12px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .post {
|
||||||
|
background: var(--card-bg);
|
||||||
|
box-shadow: none;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import PhotoSwipeLightbox from "photoswipe/lightbox";
|
||||||
|
|
||||||
|
const init = async () => {
|
||||||
|
const post = document.querySelector(".post")!;
|
||||||
|
const images = Array.from(post.querySelectorAll("img"));
|
||||||
|
|
||||||
|
const waitImageLoaded = (img: HTMLImageElement) => {
|
||||||
|
if (img.complete && img.naturalWidth > 0 && img.naturalHeight > 0) {
|
||||||
|
return Promise.resolve();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise<void>((resolve) => {
|
||||||
|
img.addEventListener("load", () => resolve(), { once: true });
|
||||||
|
img.addEventListener("error", () => resolve(), { once: true });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
images.map(async (img) => {
|
||||||
|
if (img.closest("a")) return;
|
||||||
|
|
||||||
|
await waitImageLoaded(img);
|
||||||
|
|
||||||
|
const link = document.createElement("a");
|
||||||
|
|
||||||
|
link.href = img.currentSrc || img.src;
|
||||||
|
link.target = "_blank";
|
||||||
|
link.rel = "noreferrer";
|
||||||
|
link.dataset.pswpWidth = String(img.naturalWidth || img.width || 1200);
|
||||||
|
link.dataset.pswpHeight = String(
|
||||||
|
img.naturalHeight || img.height || 800,
|
||||||
|
);
|
||||||
|
|
||||||
|
img.parentNode?.insertBefore(link, img);
|
||||||
|
link.appendChild(img);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const lightbox = new PhotoSwipeLightbox({
|
||||||
|
gallery: ".post",
|
||||||
|
children: "a[data-pswp-width]",
|
||||||
|
pswpModule: () => import("photoswipe"),
|
||||||
|
|
||||||
|
padding: {
|
||||||
|
top: 48,
|
||||||
|
right: 24,
|
||||||
|
bottom: 48,
|
||||||
|
left: 24,
|
||||||
|
},
|
||||||
|
bgOpacity: 0.5,
|
||||||
|
tapAction: "close",
|
||||||
|
bgClickAction: "close",
|
||||||
|
});
|
||||||
|
|
||||||
|
lightbox.init();
|
||||||
|
};
|
||||||
|
|
||||||
|
init();
|
||||||
|
</script>
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
---
|
|
||||||
import Layout from "@/layouts/Layout.astro";
|
|
||||||
|
|
||||||
const { slug } = Astro.params;
|
|
||||||
---
|
|
||||||
|
|
||||||
<Layout>
|
|
||||||
<h1>Post Slug: {slug}</h1>
|
|
||||||
</Layout>
|
|
||||||
214
src/pages/search.astro
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
---
|
||||||
|
import Layout from '@/layouts/Layout.astro'
|
||||||
|
import type {CategoriesStats, Post, Tag} from "@/types";
|
||||||
|
import {createHttp} from "@/lib/request.ts";
|
||||||
|
import PostList from "@/components/Post/List.astro";
|
||||||
|
|
||||||
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
|
const searchParams = Astro.url.searchParams;
|
||||||
|
const t = searchParams.get("t") ?? "";
|
||||||
|
const c = searchParams.get("c") ?? "";
|
||||||
|
|
||||||
|
const [{data: categories}, {data: tags}] = await Promise.all([
|
||||||
|
http.get<ApiResponse<CategoriesStats[]>>("categories/stats"),
|
||||||
|
http.get<ApiResponse<Tag[]>>("posts/tags"),
|
||||||
|
] as const)
|
||||||
|
|
||||||
|
let f_count = 0
|
||||||
|
const findCategory = categories.find(item => {
|
||||||
|
if (item.code === c) {
|
||||||
|
f_count++
|
||||||
|
}
|
||||||
|
return item.code === c
|
||||||
|
})
|
||||||
|
|
||||||
|
const findTag = tags.find(item => {
|
||||||
|
if (item.code === t) {
|
||||||
|
f_count++
|
||||||
|
}
|
||||||
|
return item.code === t
|
||||||
|
})
|
||||||
|
|
||||||
|
// 搜索条件必须匹配 不允许非法值
|
||||||
|
const {data:posts} = await http.get<ApiResponse<Post[]>>("posts/search", {
|
||||||
|
searchParams: {
|
||||||
|
category_code: findCategory?.code ?? "",
|
||||||
|
tag_code: findTag?.code ?? "",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const count = posts.length
|
||||||
|
|
||||||
|
const pageTitle =
|
||||||
|
f_count === 0 ? "所有文章" : [findCategory?.name, findTag?.name]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(" · ")
|
||||||
|
|
||||||
|
const pageDescription =
|
||||||
|
f_count === 0
|
||||||
|
? "浏览全部文章,按分类和标签筛选你感兴趣的内容。"
|
||||||
|
: `浏览${pageTitle}相关文章,共 ${count} 篇。`
|
||||||
|
|
||||||
|
const buildSearchUrl = (type: 'category' | 'tag', code: string) => {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
|
||||||
|
if (findTag?.code) {
|
||||||
|
params.set('t', findTag.code)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (findCategory?.code) {
|
||||||
|
params.set('c', findCategory.code)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type === 'category') {
|
||||||
|
if (c === code) {
|
||||||
|
params.delete('c')
|
||||||
|
} else {
|
||||||
|
params.set('c', code)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (t === code) {
|
||||||
|
params.delete('t')
|
||||||
|
} else {
|
||||||
|
params.set('t', code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = params.toString()
|
||||||
|
|
||||||
|
return query ? `/search?${query}` : '/search'
|
||||||
|
}
|
||||||
|
---
|
||||||
|
<Layout title={pageTitle} description={pageDescription}>
|
||||||
|
<div class="page-content search-page">
|
||||||
|
<header class="search-header">
|
||||||
|
<h1 class="search-title">
|
||||||
|
{pageTitle}
|
||||||
|
</h1>
|
||||||
|
<div class="search-count">共 <span>{count}</span> 篇</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div class="filter-group">
|
||||||
|
<div class="nav-group">
|
||||||
|
<div class="nav-label">分类:</div>
|
||||||
|
<div class="nav-chips">
|
||||||
|
{categories.map(item =>
|
||||||
|
<a href={buildSearchUrl("category", item.code)}
|
||||||
|
class={item.code === findCategory?.code ? 'chip active' : 'chip'}>{item.name}</a>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="nav-group">
|
||||||
|
<div class="nav-label">标签:</div>
|
||||||
|
<div class="nav-chips">
|
||||||
|
{tags.map(item =>
|
||||||
|
<a href={buildSearchUrl("tag", item.code)}
|
||||||
|
class={item.code === findTag?.code ? 'chip active' : 'chip'}>{item.name}</a>)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{posts.length > 0 ?
|
||||||
|
<PostList posts={posts}/> :
|
||||||
|
<div class="no-result">没有找到相关文章</div>}
|
||||||
|
</div>
|
||||||
|
</Layout>
|
||||||
|
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.search-page {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 14px;
|
||||||
|
margin: 0 auto;
|
||||||
|
max-width: 860px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
padding: 16px 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-count {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-count span {
|
||||||
|
color: var(--tag-text);
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-title {
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: 700;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.filter-group {
|
||||||
|
background: var(--card-bg);
|
||||||
|
border-radius: 10px;
|
||||||
|
box-shadow: var(--shadow);
|
||||||
|
padding: 14px 18px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 18px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-group {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
min-width: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-label {
|
||||||
|
color: var(--text-secondary);
|
||||||
|
font-size: 14px;
|
||||||
|
line-height: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-chips {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip {
|
||||||
|
color: var(--tag-text);
|
||||||
|
border-radius: 999px;
|
||||||
|
background: var(--tag-bg);
|
||||||
|
padding: 4px 8px;
|
||||||
|
font-size: 12px;
|
||||||
|
user-select: none;
|
||||||
|
transition: background 0.2s;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.chip.active, .chip:hover {
|
||||||
|
background: #3b82f6;
|
||||||
|
color: white;
|
||||||
|
}
|
||||||
|
|
||||||
|
:global(.dark) .chip.active,
|
||||||
|
:global(.dark) .chip:hover {
|
||||||
|
background: #d1d5db;
|
||||||
|
color: black;
|
||||||
|
}
|
||||||
|
|
||||||
|
.no-result {
|
||||||
|
text-align: center;
|
||||||
|
font-size: 14px;
|
||||||
|
margin-top: 32px;
|
||||||
|
color: var(--text-secondary);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
33
src/pages/sitemap-pages.xml.ts
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
import type {APIRoute} from 'astro';
|
||||||
|
import {metadata} from "@/consts";
|
||||||
|
|
||||||
|
const site = metadata.site
|
||||||
|
|
||||||
|
const staticUrls = [
|
||||||
|
'',
|
||||||
|
'/archive',
|
||||||
|
'/search',
|
||||||
|
];
|
||||||
|
|
||||||
|
export const GET: APIRoute = async () => {
|
||||||
|
const urls = staticUrls
|
||||||
|
.filter((url, index, array) => {
|
||||||
|
return array.indexOf(url) === index;
|
||||||
|
});
|
||||||
|
|
||||||
|
const xml = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
${urls.map((url) => `<url>
|
||||||
|
<loc>${site}${url}</loc>
|
||||||
|
</url>`
|
||||||
|
)
|
||||||
|
.join('\n')}
|
||||||
|
</urlset>`;
|
||||||
|
|
||||||
|
return new Response(xml, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/xml; charset=utf-8',
|
||||||
|
'Cache-Control': 'public, max-age=3600, s-maxage=3600',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
35
src/pages/sitemap-posts.xml.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import type {APIRoute} from 'astro';
|
||||||
|
import {metadata} from "@/consts";
|
||||||
|
import {createHttp} from "@/lib/request.ts";
|
||||||
|
import type {PostForSitemap} from "@/types";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
const site = metadata.site
|
||||||
|
|
||||||
|
export const GET: APIRoute = async (context) => {
|
||||||
|
const http = createHttp(context.request.headers);
|
||||||
|
|
||||||
|
const {data} = await http.get<ApiResponse<PostForSitemap[]>>("posts/sitemap")
|
||||||
|
|
||||||
|
const urls = data
|
||||||
|
.filter((url, index, array) => {
|
||||||
|
return array.indexOf(url) === index;
|
||||||
|
});
|
||||||
|
|
||||||
|
const xml = `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
${urls.map((post) => `<url>
|
||||||
|
<loc>${site}/post/${post.slug}</loc>
|
||||||
|
<lastmod>${dayjs(post.updated_at || post.created_at).toISOString()}</lastmod>
|
||||||
|
</url>`
|
||||||
|
)
|
||||||
|
.join('\n')}
|
||||||
|
</urlset>`;
|
||||||
|
|
||||||
|
return new Response(xml, {
|
||||||
|
status: 200,
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/xml; charset=utf-8',
|
||||||
|
'Cache-Control': 'public, max-age=3600, s-maxage=3600',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
21
src/pages/sitemap.xml.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
import type {APIRoute} from 'astro';
|
||||||
|
import {metadata} from "@/consts";
|
||||||
|
|
||||||
|
const site = metadata.site
|
||||||
|
|
||||||
|
export const GET: APIRoute = () => {
|
||||||
|
const xml = `<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||||
|
<sitemap>
|
||||||
|
<loc>${site}/sitemap-pages.xml</loc>
|
||||||
|
</sitemap>
|
||||||
|
<sitemap>
|
||||||
|
<loc>${site}/sitemap-posts.xml</loc>
|
||||||
|
</sitemap>
|
||||||
|
</sitemapindex>`;
|
||||||
|
|
||||||
|
return new Response(xml, {
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/xml; charset=utf-8',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
@import "modern-normalize";
|
|
||||||
@import "./reset.css";
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--layout-width: 1200px;
|
|
||||||
}
|
|
||||||
|
|
||||||
10
src/styles/css-reset.css
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: inherit;
|
||||||
|
text-decoration: none;
|
||||||
|
}
|
||||||
18
src/styles/github-markdown-reset.css
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
.markdown-body pre code{
|
||||||
|
font-size: 1.1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-body h1,
|
||||||
|
.markdown-body h2,
|
||||||
|
.markdown-body h3,
|
||||||
|
.markdown-body h4,
|
||||||
|
.markdown-body h5,
|
||||||
|
.markdown-body h6 {
|
||||||
|
border-bottom: none ;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.markdown-body pre code{
|
||||||
|
font-size: inherit;
|
||||||
|
}
|
||||||
|
}
|
||||||
1245
src/styles/github-markdown.css
Normal file
64
src/styles/global.css
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
@import "modern-normalize";
|
||||||
|
@import "css-reset.css";
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--layout-width: 1080px;
|
||||||
|
--background: #f6f7f9;
|
||||||
|
--shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
|
||||||
|
--shadow-hover: 0 8px 24px rgba(0, 0, 0, 0.10);
|
||||||
|
--card-bg: #ffffff;
|
||||||
|
--text-color: #2b2f36;
|
||||||
|
--text-secondary: #6b7280;
|
||||||
|
--border: #e5e7eb;
|
||||||
|
--primary: #4f6df5;
|
||||||
|
--tag-bg: #eef1fe;
|
||||||
|
--tag-text: #4f6df5;
|
||||||
|
--tag-hover-bg: #dfe6fd;
|
||||||
|
}
|
||||||
|
|
||||||
|
.dark {
|
||||||
|
--background: #0a0a0a;
|
||||||
|
--card-bg: #161b22;
|
||||||
|
--text-color: #ffffff;
|
||||||
|
--text-secondary: #e5e7eb;
|
||||||
|
--border: #e5e7eb;
|
||||||
|
--primary: #1e293b;
|
||||||
|
--tag-bg: #27272a;
|
||||||
|
--tag-text: #f3f4f6;
|
||||||
|
--tag-hover-bg: #334155;
|
||||||
|
}
|
||||||
|
|
||||||
|
html,
|
||||||
|
body {
|
||||||
|
min-height: 100vh;
|
||||||
|
font-size: 16px;
|
||||||
|
background: var(--background);
|
||||||
|
color: var(--text-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.main {
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-content {
|
||||||
|
width: 100%;
|
||||||
|
max-width: var(--layout-width);
|
||||||
|
margin: 0 auto;
|
||||||
|
padding: 32px;
|
||||||
|
flex: 1;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (max-width: 768px) {
|
||||||
|
.page-content {
|
||||||
|
padding: 16px;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
/* css reset */
|
|
||||||
a {
|
|
||||||
text-decoration: none;
|
|
||||||
color: inherit;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul, ol {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
21
src/types/archive.ts
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
type ArchiveYear = {
|
||||||
|
year: number;
|
||||||
|
total: number;
|
||||||
|
list: ArchiveMonth[];
|
||||||
|
};
|
||||||
|
|
||||||
|
type ArchivePost = {
|
||||||
|
id: number;
|
||||||
|
slug: string;
|
||||||
|
title: string;
|
||||||
|
published_at: string;
|
||||||
|
published_at_display: string;
|
||||||
|
category_name: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type ArchiveMonth = {
|
||||||
|
month: number;
|
||||||
|
list: ArchivePost[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Archive = ArchiveYear[];
|
||||||
0
src/types/client.ts
Normal file
29
src/types/global.d.ts
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
/** 基础 API 响应结构 */
|
||||||
|
declare interface ApiResponse<T = unknown> {
|
||||||
|
msg?: string
|
||||||
|
data: T
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 分页响应结构 */
|
||||||
|
declare interface ApiPageResponse<T = unknown> {
|
||||||
|
msg?: string
|
||||||
|
/** 当前页码 */
|
||||||
|
page: number
|
||||||
|
/** 每页数量 */
|
||||||
|
pageSize: number
|
||||||
|
/** 业务数据列表 */
|
||||||
|
list: T[]
|
||||||
|
/** 总记录数 */
|
||||||
|
total: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 错误响应结构 - 当请求失败时的响应格式 */
|
||||||
|
declare interface ApiErrorResponse {
|
||||||
|
msg: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 通用请求参数类型 */
|
||||||
|
declare interface Pagination {
|
||||||
|
page?: number
|
||||||
|
pageSize?: number
|
||||||
|
}
|
||||||
1
src/types/index.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export * from './post.ts'
|
||||||
32
src/types/post.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
export type Tag = {
|
||||||
|
id: number
|
||||||
|
code: string
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Post = {
|
||||||
|
title: string;
|
||||||
|
summary: string;
|
||||||
|
slug: string;
|
||||||
|
cover: string;
|
||||||
|
category_name: string;
|
||||||
|
category_code: string;
|
||||||
|
category_id?: number;
|
||||||
|
published_at: string;
|
||||||
|
view_count: number;
|
||||||
|
content: string;
|
||||||
|
tags: Tag[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CategoriesStats = {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
code: string
|
||||||
|
post_count: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PostForSitemap = {
|
||||||
|
slug: string
|
||||||
|
created_at: string
|
||||||
|
updated_at: string
|
||||||
|
}
|
||||||
@@ -17,4 +17,4 @@
|
|||||||
"jsx": "preserve",
|
"jsx": "preserve",
|
||||||
"jsxImportSource": "solid-js"
|
"jsxImportSource": "solid-js"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||