Compare commits
12 Commits
f7b7f7d320
...
f7929be18d
| Author | SHA1 | Date | |
|---|---|---|---|
| f7929be18d | |||
| 963722996e | |||
| e4c362030d | |||
| d7bbb7b70b | |||
| 555135aedb | |||
| b3038603e8 | |||
| 37d720ebc3 | |||
| 25e5249739 | |||
| a99c165ba3 | |||
| 60131d6fa9 | |||
| 67070e5fc4 | |||
| ecf730bda7 |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -21,3 +21,5 @@ pnpm-debug.log*
|
|||||||
|
|
||||||
*.tar
|
*.tar
|
||||||
*.gz
|
*.gz
|
||||||
|
|
||||||
|
.claude
|
||||||
|
|||||||
34
AGENTS.md
Normal file
34
AGENTS.md
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# Project Scope Rules
|
||||||
|
|
||||||
|
## 文件范围限制
|
||||||
|
|
||||||
|
本项目根目录:
|
||||||
|
|
||||||
|
./
|
||||||
|
|
||||||
|
所有操作必须限制在当前项目目录内。
|
||||||
|
|
||||||
|
禁止:
|
||||||
|
- 访问项目外文件
|
||||||
|
- 修改父级目录文件
|
||||||
|
- 创建项目外文件
|
||||||
|
- 修改用户目录中的其他内容
|
||||||
|
- 禁止访问服务端仓库
|
||||||
|
|
||||||
|
## 修改规则
|
||||||
|
|
||||||
|
修改前必须:
|
||||||
|
1. 列出将修改的文件
|
||||||
|
2. 说明修改原因
|
||||||
|
3. 等待确认
|
||||||
|
|
||||||
|
禁止修改:
|
||||||
|
|
||||||
|
node_modules/
|
||||||
|
.git/
|
||||||
|
build/
|
||||||
|
.env
|
||||||
|
|
||||||
|
## 开发环境
|
||||||
|
|
||||||
|
默认认为已经启动服务,端口为4321
|
||||||
@@ -2,7 +2,6 @@
|
|||||||
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';
|
||||||
import sitemap from "@astrojs/sitemap";
|
|
||||||
|
|
||||||
// https://astro.build/config
|
// https://astro.build/config
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
@@ -11,11 +10,7 @@ export default defineConfig({
|
|||||||
server: {
|
server: {
|
||||||
host: "0.0.0.0",
|
host: "0.0.0.0",
|
||||||
},
|
},
|
||||||
integrations: [solidJs(), sitemap({
|
integrations: [solidJs()],
|
||||||
filter: (page) => {
|
|
||||||
return !page.includes('/embed/');
|
|
||||||
}
|
|
||||||
})],
|
|
||||||
adapter: node({
|
adapter: node({
|
||||||
mode: 'standalone'
|
mode: 'standalone'
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@astrojs/node": "11.0.2",
|
"@astrojs/node": "11.0.2",
|
||||||
"@astrojs/sitemap": "^3.7.3",
|
|
||||||
"@astrojs/solid-js": "^5.1.3",
|
"@astrojs/solid-js": "^5.1.3",
|
||||||
"astro": "^7.0.6",
|
"astro": "^7.0.6",
|
||||||
"dayjs": "^1.11.21",
|
"dayjs": "^1.11.21",
|
||||||
|
|||||||
53
pnpm-lock.yaml
generated
53
pnpm-lock.yaml
generated
@@ -11,9 +11,6 @@ importers:
|
|||||||
'@astrojs/node':
|
'@astrojs/node':
|
||||||
specifier: 11.0.2
|
specifier: 11.0.2
|
||||||
version: 11.0.2(astro@7.0.6(@emnapi/core@1.11.1)(@emnapi/runtime@1.11.2)(@types/node@26.1.0)(rollup@4.62.2))
|
version: 11.0.2(astro@7.0.6(@emnapi/core@1.11.1)(@emnapi/runtime@1.11.2)(@types/node@26.1.0)(rollup@4.62.2))
|
||||||
'@astrojs/sitemap':
|
|
||||||
specifier: ^3.7.3
|
|
||||||
version: 3.7.3
|
|
||||||
'@astrojs/solid-js':
|
'@astrojs/solid-js':
|
||||||
specifier: ^5.1.3
|
specifier: ^5.1.3
|
||||||
version: 5.1.3(@types/node@26.1.0)(lightningcss@1.32.0)(solid-js@1.9.14)
|
version: 5.1.3(@types/node@26.1.0)(lightningcss@1.32.0)(solid-js@1.9.14)
|
||||||
@@ -146,9 +143,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-KTivpmnz6lDsC6o9H4+DNm2SrE/GHzw8cNAvEJwAvUT+eoaEnn/4NtbDNfRRaxaJHdp15gf+tfHAWiXR4wB3BA==}
|
resolution: {integrity: sha512-KTivpmnz6lDsC6o9H4+DNm2SrE/GHzw8cNAvEJwAvUT+eoaEnn/4NtbDNfRRaxaJHdp15gf+tfHAWiXR4wB3BA==}
|
||||||
engines: {node: '>=22.12.0'}
|
engines: {node: '>=22.12.0'}
|
||||||
|
|
||||||
'@astrojs/sitemap@3.7.3':
|
|
||||||
resolution: {integrity: sha512-f8euLVsyeAmAkSm/1M2Kb8sL8byQmfgbvBNaHFItCheTj/IpiJYSEWVcqDHZ/yEHxiS7+w87mQkzwZaPHmk5GA==}
|
|
||||||
|
|
||||||
'@astrojs/solid-js@5.1.3':
|
'@astrojs/solid-js@5.1.3':
|
||||||
resolution: {integrity: sha512-KxfYt4y1d7BuSw6EsN1EaPoGYsIES7bEI6AtTbncuabRUUMZs+mOWOeOdmgnwVLj+jbNbhBjUZsqr77eUviZdw==}
|
resolution: {integrity: sha512-KxfYt4y1d7BuSw6EsN1EaPoGYsIES7bEI6AtTbncuabRUUMZs+mOWOeOdmgnwVLj+jbNbhBjUZsqr77eUviZdw==}
|
||||||
engines: {node: 18.20.8 || ^20.3.0 || >=22.0.0}
|
engines: {node: 18.20.8 || ^20.3.0 || >=22.0.0}
|
||||||
@@ -1177,15 +1171,9 @@ packages:
|
|||||||
'@types/nlcst@2.0.3':
|
'@types/nlcst@2.0.3':
|
||||||
resolution: {integrity: sha512-vSYNSDe6Ix3q+6Z7ri9lyWqgGhJTmzRjZRqyq15N0Z/1/UnVsno9G/N40NBijoYx2seFDIl0+B2mgAb9mezUCA==}
|
resolution: {integrity: sha512-vSYNSDe6Ix3q+6Z7ri9lyWqgGhJTmzRjZRqyq15N0Z/1/UnVsno9G/N40NBijoYx2seFDIl0+B2mgAb9mezUCA==}
|
||||||
|
|
||||||
'@types/node@24.13.2':
|
|
||||||
resolution: {integrity: sha512-fRa09kZTgu8o71KFcDjUFuc7F+dEbZYZmkI0mg5YBTRs0yMKjYHsq/c0urDKeDb+D5qVgXOdFcuu+DZPKOITwA==}
|
|
||||||
|
|
||||||
'@types/node@26.1.0':
|
'@types/node@26.1.0':
|
||||||
resolution: {integrity: sha512-O0A1G3xPGy4w7AgQdAQYUlQ+BKk2Oovw8eRpofyp5KdBZULnbe+WqaOVNrm705SHphCiG4XHsACrSmPu1f+Kgw==}
|
resolution: {integrity: sha512-O0A1G3xPGy4w7AgQdAQYUlQ+BKk2Oovw8eRpofyp5KdBZULnbe+WqaOVNrm705SHphCiG4XHsACrSmPu1f+Kgw==}
|
||||||
|
|
||||||
'@types/sax@1.2.7':
|
|
||||||
resolution: {integrity: sha512-rO73L89PJxeYM3s3pPPjiPgVVcymqU490g0YO5n5By0k2Erzj6tay/4lr1CHAAU4JyOWd1rpQ8bCf6cZfHU96A==}
|
|
||||||
|
|
||||||
'@types/tough-cookie@4.0.5':
|
'@types/tough-cookie@4.0.5':
|
||||||
resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==}
|
resolution: {integrity: sha512-/Ad8+nIOV7Rl++6f1BdKxFSMgmoqEoYbHRpPcx3JEfv8VRsQe9Z4mCXeJBzxs7mbHY/XOZZuXlRNfhpVPbs6ZA==}
|
||||||
|
|
||||||
@@ -1203,9 +1191,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
resolution: {integrity: sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==}
|
||||||
engines: {node: '>= 8'}
|
engines: {node: '>= 8'}
|
||||||
|
|
||||||
arg@5.0.2:
|
|
||||||
resolution: {integrity: sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==}
|
|
||||||
|
|
||||||
argparse@2.0.1:
|
argparse@2.0.1:
|
||||||
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
resolution: {integrity: sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==}
|
||||||
|
|
||||||
@@ -1937,11 +1922,6 @@ packages:
|
|||||||
sisteransi@1.0.5:
|
sisteransi@1.0.5:
|
||||||
resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
|
resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}
|
||||||
|
|
||||||
sitemap@9.0.1:
|
|
||||||
resolution: {integrity: sha512-S6hzjGJSG3d6if0YoF5kTyeRJvia6FSTBroE5fQ0bu1QNxyJqhhinfUsXi9fH3MgtXODWvwo2BDyQSnhPQ88uQ==}
|
|
||||||
engines: {node: '>=20.19.5', npm: '>=10.8.2'}
|
|
||||||
hasBin: true
|
|
||||||
|
|
||||||
smol-toml@1.7.0:
|
smol-toml@1.7.0:
|
||||||
resolution: {integrity: sha512-aqVvWoyO21L23mb+drl4RmMXbf6N7FdHjAhTRA9ZBL7apWBgfWC16KjrASI+1p9GAroljyMHj6fK67i0UiTNvQ==}
|
resolution: {integrity: sha512-aqVvWoyO21L23mb+drl4RmMXbf6N7FdHjAhTRA9ZBL7apWBgfWC16KjrASI+1p9GAroljyMHj6fK67i0UiTNvQ==}
|
||||||
engines: {node: '>= 18'}
|
engines: {node: '>= 18'}
|
||||||
@@ -1965,9 +1945,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==}
|
resolution: {integrity: sha512-DvEy55V3DB7uknRo+4iOGT5fP1slR8wQohVdknigZPMpMstaKJQWhwiYBACJE3Ul2pTnATihhBYnRhZQHGBiRw==}
|
||||||
engines: {node: '>= 0.8'}
|
engines: {node: '>= 0.8'}
|
||||||
|
|
||||||
stream-replace-string@2.0.0:
|
|
||||||
resolution: {integrity: sha512-TlnjJ1C0QrmxRNrON00JvaFFlNh5TTG00APw23j74ET7gkQpTASi6/L2fuiav8pzK715HXtUeClpBTw2NPSn6w==}
|
|
||||||
|
|
||||||
stringify-entities@4.0.4:
|
stringify-entities@4.0.4:
|
||||||
resolution: {integrity: sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==}
|
resolution: {integrity: sha512-IwfBptatlO+QCJUo19AqvrPNqlVMpW9YEL2LIVY+Rpv2qsjCGxaDLNRgeGsQWJhfItebuJhsGSLjaBbNSQ+ieg==}
|
||||||
|
|
||||||
@@ -2031,9 +2008,6 @@ packages:
|
|||||||
uncrypto@0.1.3:
|
uncrypto@0.1.3:
|
||||||
resolution: {integrity: sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==}
|
resolution: {integrity: sha512-Ql87qFHB3s/De2ClA9e0gsnS6zXG27SkTiSJwjCc9MebbfapQfuPzumMIUMi38ezPZVNFcHI9sUIepeQfw8J8Q==}
|
||||||
|
|
||||||
undici-types@7.18.2:
|
|
||||||
resolution: {integrity: sha512-AsuCzffGHJybSaRrmr5eHr81mwJU3kjw6M+uprWvCXiNeN9SOGwQ3Jn8jb8m3Z6izVgknn1R0FTCEAP2QrLY/w==}
|
|
||||||
|
|
||||||
undici-types@7.28.0:
|
undici-types@7.28.0:
|
||||||
resolution: {integrity: sha512-LJAfY+2w6HGeT8d8J1wNQsUGUEGio6NWWpwdwurQe4f6oojzCFuGLizl1KSve4irsTxyLly1QhEeE6iapdaIvQ==}
|
resolution: {integrity: sha512-LJAfY+2w6HGeT8d8J1wNQsUGUEGio6NWWpwdwurQe4f6oojzCFuGLizl1KSve4irsTxyLly1QhEeE6iapdaIvQ==}
|
||||||
|
|
||||||
@@ -2394,12 +2368,6 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
prismjs: 1.30.0
|
prismjs: 1.30.0
|
||||||
|
|
||||||
'@astrojs/sitemap@3.7.3':
|
|
||||||
dependencies:
|
|
||||||
sitemap: 9.0.1
|
|
||||||
stream-replace-string: 2.0.0
|
|
||||||
zod: 4.4.3
|
|
||||||
|
|
||||||
'@astrojs/solid-js@5.1.3(@types/node@26.1.0)(lightningcss@1.32.0)(solid-js@1.9.14)':
|
'@astrojs/solid-js@5.1.3(@types/node@26.1.0)(lightningcss@1.32.0)(solid-js@1.9.14)':
|
||||||
dependencies:
|
dependencies:
|
||||||
solid-js: 1.9.14
|
solid-js: 1.9.14
|
||||||
@@ -3162,18 +3130,10 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
'@types/unist': 3.0.3
|
'@types/unist': 3.0.3
|
||||||
|
|
||||||
'@types/node@24.13.2':
|
|
||||||
dependencies:
|
|
||||||
undici-types: 7.18.2
|
|
||||||
|
|
||||||
'@types/node@26.1.0':
|
'@types/node@26.1.0':
|
||||||
dependencies:
|
dependencies:
|
||||||
undici-types: 8.3.0
|
undici-types: 8.3.0
|
||||||
|
|
||||||
'@types/sax@1.2.7':
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 26.1.0
|
|
||||||
|
|
||||||
'@types/tough-cookie@4.0.5': {}
|
'@types/tough-cookie@4.0.5': {}
|
||||||
|
|
||||||
'@types/unist@3.0.3': {}
|
'@types/unist@3.0.3': {}
|
||||||
@@ -3189,8 +3149,6 @@ snapshots:
|
|||||||
normalize-path: 3.0.0
|
normalize-path: 3.0.0
|
||||||
picomatch: 2.3.2
|
picomatch: 2.3.2
|
||||||
|
|
||||||
arg@5.0.2: {}
|
|
||||||
|
|
||||||
argparse@2.0.1: {}
|
argparse@2.0.1: {}
|
||||||
|
|
||||||
aria-query@5.3.2: {}
|
aria-query@5.3.2: {}
|
||||||
@@ -4050,13 +4008,6 @@ snapshots:
|
|||||||
|
|
||||||
sisteransi@1.0.5: {}
|
sisteransi@1.0.5: {}
|
||||||
|
|
||||||
sitemap@9.0.1:
|
|
||||||
dependencies:
|
|
||||||
'@types/node': 24.13.2
|
|
||||||
'@types/sax': 1.2.7
|
|
||||||
arg: 5.0.2
|
|
||||||
sax: 1.6.0
|
|
||||||
|
|
||||||
smol-toml@1.7.0: {}
|
smol-toml@1.7.0: {}
|
||||||
|
|
||||||
solid-js@1.9.14:
|
solid-js@1.9.14:
|
||||||
@@ -4080,8 +4031,6 @@ snapshots:
|
|||||||
|
|
||||||
statuses@2.0.2: {}
|
statuses@2.0.2: {}
|
||||||
|
|
||||||
stream-replace-string@2.0.0: {}
|
|
||||||
|
|
||||||
stringify-entities@4.0.4:
|
stringify-entities@4.0.4:
|
||||||
dependencies:
|
dependencies:
|
||||||
character-entities-html4: 2.1.0
|
character-entities-html4: 2.1.0
|
||||||
@@ -4139,8 +4088,6 @@ snapshots:
|
|||||||
|
|
||||||
uncrypto@0.1.3: {}
|
uncrypto@0.1.3: {}
|
||||||
|
|
||||||
undici-types@7.18.2: {}
|
|
||||||
|
|
||||||
undici-types@7.28.0: {}
|
undici-types@7.28.0: {}
|
||||||
|
|
||||||
undici-types@8.3.0: {}
|
undici-types@8.3.0: {}
|
||||||
|
|||||||
@@ -1,2 +1,4 @@
|
|||||||
User-agent: *
|
User-agent: *
|
||||||
Allow: /
|
Allow: /
|
||||||
|
|
||||||
|
Sitemap: https://ua42.com/sitemap.xml
|
||||||
|
|||||||
@@ -1,12 +1,15 @@
|
|||||||
---
|
---
|
||||||
import Folder from "@/assets/icon/folder.png?url";
|
import Folder from "@/assets/icon/folder.png?url";
|
||||||
import Tag from "@/assets/icon/tag.png?url";
|
import TagIcon from "@/assets/icon/tag.png?url";
|
||||||
import type { CategoriesStats } from "@/types";
|
import type { CategoriesStats,Tag } from "@/types";
|
||||||
import { createHttp } from "@/lib/request";
|
import { createHttp } from "@/lib/request";
|
||||||
const http = createHttp(Astro.request.headers);
|
const http = createHttp(Astro.request.headers);
|
||||||
|
|
||||||
const { data: categories } =
|
const { data: categories } =
|
||||||
await http.get<ApiResponse<CategoriesStats[]>>("categories/stats");
|
await http.get<ApiResponse<CategoriesStats[]>>("categories/stats");
|
||||||
|
|
||||||
|
const { data: tags } =
|
||||||
|
await http.get<ApiResponse<Tag[]>>("posts/tags");
|
||||||
---
|
---
|
||||||
|
|
||||||
<aside class="sidebar">
|
<aside class="sidebar">
|
||||||
@@ -19,7 +22,12 @@ const { data: categories } =
|
|||||||
{
|
{
|
||||||
categories.map((category) => (
|
categories.map((category) => (
|
||||||
<li>
|
<li>
|
||||||
<a>{category.name}</a>
|
<a
|
||||||
|
href={`/search?c=${encodeURIComponent(category.code)}`}
|
||||||
|
title={`${category.name} · ${category.post_count} 篇`}
|
||||||
|
>
|
||||||
|
{category.name}
|
||||||
|
</a>
|
||||||
<span class="count">{category.post_count}</span>
|
<span class="count">{category.post_count}</span>
|
||||||
</li>
|
</li>
|
||||||
))
|
))
|
||||||
@@ -29,20 +37,20 @@ const { data: categories } =
|
|||||||
|
|
||||||
<div class="widget">
|
<div class="widget">
|
||||||
<h3 class="widget-title">
|
<h3 class="widget-title">
|
||||||
<img src={Tag} alt="Folder" />
|
<img src={TagIcon} alt="Tag" />
|
||||||
标签云
|
标签云
|
||||||
</h3>
|
</h3>
|
||||||
<div class="tag-cloud">
|
<div class="tag-cloud">
|
||||||
<a class="tag" href="#">HTML</a>
|
{
|
||||||
<a class="tag" href="#">CSS</a>
|
tags.map((tag) => (
|
||||||
<a class="tag" href="#">JavaScript</a>
|
<a
|
||||||
<a class="tag" href="#">响应式</a>
|
class="tag"
|
||||||
<a class="tag" href="#">随笔</a>
|
href={`/search?t=${encodeURIComponent(tag.code)}`}
|
||||||
<a class="tag" href="#">读书</a>
|
>
|
||||||
<a class="tag" href="#">效率</a>
|
{tag.name}
|
||||||
<a class="tag" href="#">设计</a>
|
</a>
|
||||||
<a class="tag" href="#">工具</a>
|
))
|
||||||
<a class="tag" href="#">深色模式</a>
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
@@ -126,7 +134,7 @@ const { data: categories } =
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tag:hover {
|
.tag:hover {
|
||||||
background: #dfe6fd;
|
background: var(--tag-hover-bg);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 860px) {
|
@media (max-width: 860px) {
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
---
|
---
|
||||||
import type { Post } from "@/types/post";
|
import type {Post} from "@/types/post";
|
||||||
import IndexSidebar from "@/components/IndexSidebar.astro";
|
import IndexSidebar from "@/components/IndexSidebar.astro";
|
||||||
import PostList from "@/components/PostList.astro";
|
import PostList from "@/components/Post/List.astro";
|
||||||
|
import Pagination from "@/components/Post/Pagination.astro";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
posts: Post[];
|
posts: Post[];
|
||||||
@@ -9,13 +10,16 @@ interface Props {
|
|||||||
totalPage: number;
|
totalPage: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
const { posts, page, totalPage } = Astro.props;
|
const {posts, page, totalPage} = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
<div class="page-content">
|
<div class="page-content">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<PostList posts={posts} page={page} totalPage={totalPage} />
|
<div class="post-container">
|
||||||
<IndexSidebar />
|
<PostList posts={posts}/>
|
||||||
|
<Pagination page={page} totalPage={totalPage}/>
|
||||||
|
</div>
|
||||||
|
<IndexSidebar/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -26,6 +30,12 @@ const { posts, page, totalPage } = Astro.props;
|
|||||||
gap: 28px;
|
gap: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.post-container{
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 32px;
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 860px) {
|
@media (max-width: 860px) {
|
||||||
.container {
|
.container {
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
|||||||
131
src/components/LazyImage.astro
Normal file
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
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
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
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>
|
||||||
@@ -1,272 +0,0 @@
|
|||||||
---
|
|
||||||
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 type {Post} from "@/types/post";
|
|
||||||
import {formatDatetime} from "@/lib/format.ts";
|
|
||||||
|
|
||||||
interface Props {
|
|
||||||
posts: Post[]
|
|
||||||
page: number
|
|
||||||
totalPage: number
|
|
||||||
}
|
|
||||||
|
|
||||||
const {posts, page, totalPage} = Astro.props
|
|
||||||
|
|
||||||
posts.map((post) => {
|
|
||||||
post.published_at = formatDatetime(post.published_at, 'YYYY-MM-DD')
|
|
||||||
})
|
|
||||||
---
|
|
||||||
<section class="section">
|
|
||||||
<div class="post-list">
|
|
||||||
{posts.map(post => (
|
|
||||||
<a href={`/post/${post.slug}`}>
|
|
||||||
<article class="post-card">
|
|
||||||
<div class="post-cover">
|
|
||||||
<img src={post.cover} alt={post.title} loading="lazy"/>
|
|
||||||
</div>
|
|
||||||
<div class="post-body">
|
|
||||||
<div class="post-meta">
|
|
||||||
<span>
|
|
||||||
<img src={Calendar} alt="Calendar"/>
|
|
||||||
{post.published_at}
|
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
<img src={Folder} alt="Folder"/>
|
|
||||||
{post.category_name}
|
|
||||||
</span>
|
|
||||||
<span>
|
|
||||||
<img src={Eye} alt="Eye"/>
|
|
||||||
{post.view}
|
|
||||||
</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>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!--分页器-->
|
|
||||||
{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>}
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.section {
|
|
||||||
flex: 1;
|
|
||||||
height: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-list {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 20px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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: 110px;
|
|
||||||
border-radius: 8px;
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: center;
|
|
||||||
font-size: 40px;
|
|
||||||
color: #fff;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-cover img {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
object-fit: cover;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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: #dfe6fd;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========== 分页 ========== */
|
|
||||||
.pagination {
|
|
||||||
display: flex;
|
|
||||||
justify-content: center;
|
|
||||||
gap: 8px;
|
|
||||||
margin-top: 32px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@media (max-width: 860px) {
|
|
||||||
.post-list{
|
|
||||||
gap: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-card {
|
|
||||||
padding: 16px;
|
|
||||||
gap: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-cover {
|
|
||||||
width: 128px;
|
|
||||||
height: 88px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-title {
|
|
||||||
font-size: 18px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-meta{
|
|
||||||
gap: 8px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@media (max-width: 560px) {
|
|
||||||
.post-card {
|
|
||||||
padding: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-title {
|
|
||||||
font-size: 16px;
|
|
||||||
margin-bottom: 4px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-meta{
|
|
||||||
gap: 6px;
|
|
||||||
font-size: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-cover {
|
|
||||||
width: 100px;
|
|
||||||
height: 70px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.post-summary{
|
|
||||||
font-size: 12px;
|
|
||||||
margin-bottom: 6px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
export const metadata = {
|
export const metadata = {
|
||||||
|
site: "https://ua42.com",
|
||||||
siteTitle: "Uroboros",
|
siteTitle: "Uroboros",
|
||||||
|
|
||||||
postPageSize: 6
|
postPageSize: 6
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,10 +42,11 @@ import {metadata} from '@/consts.ts'
|
|||||||
}
|
}
|
||||||
|
|
||||||
.page-container {
|
.page-container {
|
||||||
|
height: 100vh;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: 200px 24px 24px 24px;
|
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
padding: 24px 24px 24px 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gitea-card {
|
.gitea-card {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const { list, total } = await http.get<ApiPageResponse<Post>>("posts", {
|
|||||||
const totalPage = Math.ceil(total / metadata.postPageSize);
|
const totalPage = Math.ceil(total / metadata.postPageSize);
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout description="天若有情天亦老,人间正道是沧桑。" title="博客首页">
|
||||||
<IndexView
|
<IndexView
|
||||||
posts={list}
|
posts={list}
|
||||||
page={1}
|
page={1}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ if (totalPage < Number(page)) {
|
|||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout description="天若有情天亦老,人间正道是沧桑。" title="博客首页">
|
||||||
<IndexView
|
<IndexView
|
||||||
posts={list}
|
posts={list}
|
||||||
page={Number(page)}
|
page={Number(page)}
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ const published_at = formatDatetime(data.published_at, "YYYY 年 M 月 D 日");
|
|||||||
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"
|
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>
|
p-id="5123"></path>
|
||||||
</svg>
|
</svg>
|
||||||
{data.view}
|
{data.view_count}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
213
src/pages/search.astro
Normal file
213
src/pages/search.astro
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
---
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
.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
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
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
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,6 +1,7 @@
|
|||||||
* {
|
* {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
box-sizing: border-box;
|
||||||
}
|
}
|
||||||
|
|
||||||
a {
|
a {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
--primary: #4f6df5;
|
--primary: #4f6df5;
|
||||||
--tag-bg: #eef1fe;
|
--tag-bg: #eef1fe;
|
||||||
--tag-text: #4f6df5;
|
--tag-text: #4f6df5;
|
||||||
|
--tag-hover-bg: #dfe6fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dark {
|
.dark {
|
||||||
@@ -24,6 +25,7 @@
|
|||||||
--primary: #1e293b;
|
--primary: #1e293b;
|
||||||
--tag-bg: #27272a;
|
--tag-bg: #27272a;
|
||||||
--tag-text: #f3f4f6;
|
--tag-text: #f3f4f6;
|
||||||
|
--tag-hover-bg: #334155;
|
||||||
}
|
}
|
||||||
|
|
||||||
html,
|
html,
|
||||||
|
|||||||
@@ -3,14 +3,17 @@ export type Tag = {
|
|||||||
code: string
|
code: string
|
||||||
name: string
|
name: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Post = {
|
export type Post = {
|
||||||
title: string;
|
title: string;
|
||||||
summary: string;
|
summary: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
cover: string;
|
cover: string;
|
||||||
category_name: string;
|
category_name: string;
|
||||||
|
category_code: string;
|
||||||
|
category_id?: number;
|
||||||
published_at: string;
|
published_at: string;
|
||||||
view: number;
|
view_count: number;
|
||||||
content: string;
|
content: string;
|
||||||
tags: Tag[]
|
tags: Tag[]
|
||||||
}
|
}
|
||||||
@@ -18,6 +21,12 @@ export type Post = {
|
|||||||
export type CategoriesStats = {
|
export type CategoriesStats = {
|
||||||
id: number;
|
id: number;
|
||||||
name: string;
|
name: string;
|
||||||
|
code: string
|
||||||
post_count: number;
|
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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user