完成基础
This commit is contained in:
parent
21202b34c8
commit
e3b7a06b39
48
README.md
48
README.md
@ -1,48 +0,0 @@
|
||||
# Astro Starter Kit: Basics
|
||||
|
||||
```sh
|
||||
npm create astro@latest -- --template basics
|
||||
```
|
||||
|
||||
[](https://stackblitz.com/github/withastro/astro/tree/latest/examples/basics)
|
||||
[](https://codesandbox.io/p/sandbox/github/withastro/astro/tree/latest/examples/basics)
|
||||
[](https://codespaces.new/withastro/astro?devcontainer_path=.devcontainer/basics/devcontainer.json)
|
||||
|
||||
> 🧑🚀 **Seasoned astronaut?** Delete this file. Have fun!
|
||||
|
||||

|
||||
|
||||
## 🚀 Project Structure
|
||||
|
||||
Inside of your Astro project, you'll see the following folders and files:
|
||||
|
||||
```text
|
||||
/
|
||||
├── public/
|
||||
│ └── favicon.svg
|
||||
├── src/
|
||||
│ ├── layouts/
|
||||
│ │ └── Layout.astro
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
|
||||
To learn more about the folder structure of an Astro project, refer to [our guide on project structure](https://docs.astro.build/en/basics/project-structure/).
|
||||
|
||||
## 🧞 Commands
|
||||
|
||||
All commands are run from the root of the project, from a terminal:
|
||||
|
||||
| Command | Action |
|
||||
| :------------------------ | :----------------------------------------------- |
|
||||
| `npm install` | Installs dependencies |
|
||||
| `npm run dev` | Starts local dev server at `localhost:4321` |
|
||||
| `npm run build` | Build your production site to `./dist/` |
|
||||
| `npm run preview` | Preview your build locally, before deploying |
|
||||
| `npm run astro ...` | Run CLI commands like `astro add`, `astro check` |
|
||||
| `npm run astro -- --help` | Get help using the Astro CLI |
|
||||
|
||||
## 👀 Want to learn more?
|
||||
|
||||
Feel free to check [our documentation](https://docs.astro.build) or jump into our [Discord server](https://astro.build/chat).
|
@ -1,5 +1,44 @@
|
||||
// @ts-check
|
||||
import { defineConfig } from 'astro/config';
|
||||
|
||||
import tailwindcss from '@tailwindcss/vite';
|
||||
|
||||
import react from '@astrojs/react';
|
||||
import node from '@astrojs/node';
|
||||
import remarkEmoji from 'remark-emoji';
|
||||
import rehypeExternalLinks from 'rehype-external-links';
|
||||
|
||||
// https://astro.build/config
|
||||
export default defineConfig({});
|
||||
export default defineConfig({
|
||||
output: 'server',
|
||||
vite: {
|
||||
plugins: [tailwindcss()]
|
||||
},
|
||||
|
||||
integrations: [react()],
|
||||
|
||||
// 添加 Node.js 适配器配置
|
||||
adapter: node({
|
||||
mode: 'standalone' // 独立模式,适合大多数部署环境
|
||||
}),
|
||||
|
||||
// Markdown 配置
|
||||
markdown: {
|
||||
syntaxHighlight: 'prism',
|
||||
remarkPlugins: [
|
||||
[remarkEmoji, { emoticon: true }] // 启用表情符号和情感符号
|
||||
],
|
||||
rehypePlugins: [
|
||||
[rehypeExternalLinks, { target: '_blank', rel: ['nofollow', 'noopener', 'noreferrer'] }]
|
||||
],
|
||||
gfm: true, // GitHub Flavored Markdown
|
||||
shikiConfig: {
|
||||
// 选择一个主题 (可选)
|
||||
theme: 'github-dark',
|
||||
// 添加自定义语言
|
||||
langs: [],
|
||||
// 启用自动换行,防止水平滚动
|
||||
wrap: true,
|
||||
}
|
||||
}
|
||||
});
|
2549
package-lock.json
generated
2549
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
22
package.json
22
package.json
@ -9,6 +9,24 @@
|
||||
"astro": "astro"
|
||||
},
|
||||
"dependencies": {
|
||||
"astro": "^5.3.0"
|
||||
"@astrojs/node": "^9.1.2",
|
||||
"@astrojs/react": "^4.2.0",
|
||||
"@tailwindcss/vite": "^4.0.9",
|
||||
"@types/react": "^19.0.10",
|
||||
"@types/react-dom": "^19.0.4",
|
||||
"astro": "^5.3.0",
|
||||
"cheerio": "^1.0.0-rc.12",
|
||||
"echarts": "^5.6.0",
|
||||
"node-fetch": "^3.3.0",
|
||||
"octokit": "^3.1.2",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"react-masonry-css": "^1.0.16",
|
||||
"tailwindcss": "^4.0.9"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@tailwindcss/typography": "^0.5.16",
|
||||
"rehype-external-links": "^3.0.0",
|
||||
"remark-emoji": "^5.0.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" width="115" height="48"><path fill="#17191E" d="M7.77 36.35C6.4 35.11 6 32.51 6.57 30.62c.99 1.2 2.35 1.57 3.75 1.78 2.18.33 4.31.2 6.33-.78.23-.12.44-.27.7-.42.18.55.23 1.1.17 1.67a4.56 4.56 0 0 1-1.94 3.23c-.43.32-.9.61-1.34.91-1.38.94-1.76 2.03-1.24 3.62l.05.17a3.63 3.63 0 0 1-1.6-1.38 3.87 3.87 0 0 1-.63-2.1c0-.37 0-.74-.05-1.1-.13-.9-.55-1.3-1.33-1.32a1.56 1.56 0 0 0-1.63 1.26c0 .06-.03.12-.05.2Z"/><path fill="url(#a)" d="M7.77 36.35C6.4 35.11 6 32.51 6.57 30.62c.99 1.2 2.35 1.57 3.75 1.78 2.18.33 4.31.2 6.33-.78.23-.12.44-.27.7-.42.18.55.23 1.1.17 1.67a4.56 4.56 0 0 1-1.94 3.23c-.43.32-.9.61-1.34.91-1.38.94-1.76 2.03-1.24 3.62l.05.17a3.63 3.63 0 0 1-1.6-1.38 3.87 3.87 0 0 1-.63-2.1c0-.37 0-.74-.05-1.1-.13-.9-.55-1.3-1.33-1.32a1.56 1.56 0 0 0-1.63 1.26c0 .06-.03.12-.05.2Z"/><path fill="#17191E" d="M.02 30.31s4.02-1.95 8.05-1.95l3.04-9.4c.11-.45.44-.76.82-.76.37 0 .7.31.82.76l3.04 9.4c4.77 0 8.05 1.95 8.05 1.95L17 11.71c-.2-.56-.53-.91-.98-.91H7.83c-.44 0-.76.35-.97.9L.02 30.31Zm42.37-5.97c0 1.64-2.05 2.62-4.88 2.62-1.85 0-2.5-.45-2.5-1.41 0-1 .8-1.49 2.65-1.49 1.67 0 3.09.03 4.73.23v.05Zm.03-2.04a21.37 21.37 0 0 0-4.37-.36c-5.32 0-7.82 1.25-7.82 4.18 0 3.04 1.71 4.2 5.68 4.2 3.35 0 5.63-.84 6.46-2.92h.14c-.03.5-.05 1-.05 1.4 0 1.07.18 1.16 1.06 1.16h4.15a16.9 16.9 0 0 1-.36-4c0-1.67.06-2.93.06-4.62 0-3.45-2.07-5.64-8.56-5.64-2.8 0-5.9.48-8.26 1.19.22.93.54 2.83.7 4.06 2.04-.96 4.95-1.37 7.2-1.37 3.11 0 3.97.71 3.97 2.15v.57Zm11.37 3c-.56.07-1.33.07-2.12.07-.83 0-1.6-.03-2.12-.1l-.02.58c0 2.85 1.87 4.52 8.45 4.52 6.2 0 8.2-1.64 8.2-4.55 0-2.74-1.33-4.09-7.2-4.39-4.58-.2-4.99-.7-4.99-1.28 0-.66.59-1 3.65-1 3.18 0 4.03.43 4.03 1.35v.2a46.13 46.13 0 0 1 4.24.03l.02-.55c0-3.36-2.8-4.46-8.2-4.46-6.08 0-8.13 1.49-8.13 4.39 0 2.6 1.64 4.23 7.48 4.48 4.3.14 4.77.62 4.77 1.28 0 .7-.7 1.03-3.71 1.03-3.47 0-4.35-.48-4.35-1.47v-.13Zm19.82-12.05a17.5 17.5 0 0 1-6.24 3.48c.03.84.03 2.4.03 3.24l1.5.02c-.02 1.63-.04 3.6-.04 4.9 0 3.04 1.6 5.32 6.58 5.32 2.1 0 3.5-.23 5.23-.6a43.77 43.77 0 0 1-.46-4.13c-1.03.34-2.34.53-3.78.53-2 0-2.82-.55-2.82-2.13 0-1.37 0-2.65.03-3.84 2.57.02 5.13.07 6.64.11-.02-1.18.03-2.9.1-4.04-2.2.04-4.65.07-6.68.07l.07-2.93h-.16Zm13.46 6.04a767.33 767.33 0 0 1 .07-3.18H82.6c.07 1.96.07 3.98.07 6.92 0 2.95-.03 4.99-.07 6.93h5.18c-.09-1.37-.11-3.68-.11-5.65 0-3.1 1.26-4 4.12-4 1.33 0 2.28.16 3.1.46.03-1.16.26-3.43.4-4.43-.86-.25-1.81-.41-2.96-.41-2.46-.03-4.26.98-5.1 3.38l-.17-.02Zm22.55 3.65c0 2.5-1.8 3.66-4.64 3.66-2.81 0-4.61-1.1-4.61-3.66s1.82-3.52 4.61-3.52c2.82 0 4.64 1.03 4.64 3.52Zm4.71-.11c0-4.96-3.87-7.18-9.35-7.18-5.5 0-9.23 2.22-9.23 7.18 0 4.94 3.49 7.59 9.21 7.59 5.77 0 9.37-2.65 9.37-7.6Z"/><defs><linearGradient id="a" x1="6.33" x2="19.43" y1="40.8" y2="34.6" gradientUnits="userSpaceOnUse"><stop stop-color="#D83333"/><stop offset="1" stop-color="#F041FF"/></linearGradient></defs></svg>
|
Before Width: | Height: | Size: 2.8 KiB |
@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="1440" height="1024" fill="none"><path fill="url(#a)" fill-rule="evenodd" d="M-217.58 475.75c91.82-72.02 225.52-29.38 341.2-44.74C240 415.56 372.33 315.14 466.77 384.9c102.9 76.02 44.74 246.76 90.31 366.31 29.83 78.24 90.48 136.14 129.48 210.23 57.92 109.99 169.67 208.23 155.9 331.77-13.52 121.26-103.42 264.33-224.23 281.37-141.96 20.03-232.72-220.96-374.06-196.99-151.7 25.73-172.68 330.24-325.85 315.72-128.6-12.2-110.9-230.73-128.15-358.76-12.16-90.14 65.87-176.25 44.1-264.57-26.42-107.2-167.12-163.46-176.72-273.45-10.15-116.29 33.01-248.75 124.87-320.79Z" clip-rule="evenodd" style="opacity:.154"/><path fill="url(#b)" fill-rule="evenodd" d="M1103.43 115.43c146.42-19.45 275.33-155.84 413.5-103.59 188.09 71.13 409 212.64 407.06 413.88-1.94 201.25-259.28 278.6-414.96 405.96-130 106.35-240.24 294.39-405.6 265.3-163.7-28.8-161.93-274.12-284.34-386.66-134.95-124.06-436-101.46-445.82-284.6-9.68-180.38 247.41-246.3 413.54-316.9 101.01-42.93 207.83 21.06 316.62 6.61Z" clip-rule="evenodd" style="opacity:.154"/><defs><linearGradient id="b" x1="373" x2="1995.44" y1="1100" y2="118.03" gradientUnits="userSpaceOnUse"><stop stop-color="#D83333"/><stop offset="1" stop-color="#F041FF"/></linearGradient><linearGradient id="a" x1="107.37" x2="1130.66" y1="1993.35" y2="1026.31" gradientUnits="userSpaceOnUse"><stop stop-color="#3245FF"/><stop offset="1" stop-color="#BC52EE"/></linearGradient></defs></svg>
|
Before Width: | Height: | Size: 1.4 KiB |
1
src/assets/china.json
Normal file
1
src/assets/china.json
Normal file
File diff suppressed because one or more lines are too long
241
src/assets/world.zh.json
Normal file
241
src/assets/world.zh.json
Normal file
File diff suppressed because one or more lines are too long
31
src/components/ArticleList.astro
Normal file
31
src/components/ArticleList.astro
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import type { CollectionEntry } from 'astro:content';
|
||||
|
||||
// 获取所有文章,并按日期排序
|
||||
const articles: CollectionEntry<'articles'>[] = await getCollection('articles');
|
||||
const sortedArticles = articles.sort(
|
||||
(a, b) => b.data.date.getTime() - a.data.date.getTime()
|
||||
);
|
||||
---
|
||||
<div class="my-8">
|
||||
<h2 class="text-2xl font-bold mb-6 text-primary-900 dark:text-primary-100">文章列表</h2>
|
||||
<ul>
|
||||
{sortedArticles.map((article: CollectionEntry<'articles'>) => (
|
||||
<li class="mb-6 list-none">
|
||||
<a href={`/articles/${article.id}`} class="block p-4 rounded-lg no-underline text-inherit bg-white dark:bg-dark-card border border-secondary-200 dark:border-dark-border hover:border-primary-300 dark:hover:border-primary-700 transition-all duration-300 hover:shadow-md">
|
||||
<h3 class="m-0 mb-2 text-primary-800 dark:text-primary-200">{article.data.title}</h3>
|
||||
<p class="text-sm text-secondary-500 dark:text-secondary-400 my-1">{article.data.date.toLocaleDateString('zh-CN')}</p>
|
||||
{article.data.summary && <p class="my-2 leading-relaxed text-secondary-700 dark:text-secondary-300">{article.data.summary}</p>}
|
||||
{article.data.tags && (
|
||||
<div class="flex flex-wrap gap-2 mt-2">
|
||||
{article.data.tags.map((tag: string) => (
|
||||
<span class="text-xs bg-primary-50 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 py-1 px-2 rounded-full">{tag}</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</a>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
177
src/components/ArticleTimeline.astro
Normal file
177
src/components/ArticleTimeline.astro
Normal file
@ -0,0 +1,177 @@
|
||||
---
|
||||
interface Props {
|
||||
title?: string;
|
||||
itemsPerPage?: number;
|
||||
}
|
||||
|
||||
const {
|
||||
title = "文章时间线",
|
||||
itemsPerPage = 10
|
||||
} = Astro.props;
|
||||
---
|
||||
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
{title && <h1 class="text-3xl font-bold mb-6 text-primary-900 dark:text-primary-100">{title}</h1>}
|
||||
|
||||
<div id="article-timeline" class="space-y-6">
|
||||
<!-- 内容将通过JS动态加载 -->
|
||||
</div>
|
||||
|
||||
<div id="loading" class="text-center py-8">
|
||||
<div class="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-primary-500 dark:border-primary-400 border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"></div>
|
||||
<p class="mt-2 text-secondary-600 dark:text-secondary-400">加载更多...</p>
|
||||
</div>
|
||||
|
||||
<div id="end-message" class="text-center py-8 hidden">
|
||||
<p class="text-secondary-600 dark:text-secondary-400">已加载全部内容</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script is:inline define:vars={{ itemsPerPage }}>
|
||||
let currentPage = 1;
|
||||
let isLoading = false;
|
||||
let hasMoreContent = true;
|
||||
|
||||
async function fetchArticles(page = 1, append = false) {
|
||||
if (isLoading || (!append && !hasMoreContent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
showLoading(true);
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/articles?page=${page}&limit=${itemsPerPage}`);
|
||||
if (!response.ok) {
|
||||
throw new Error('获取文章数据失败');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
renderArticles(data.articles, append);
|
||||
|
||||
// 更新分页状态
|
||||
currentPage = data.pagination.current;
|
||||
hasMoreContent = data.pagination.hasNext;
|
||||
|
||||
if (!hasMoreContent) {
|
||||
showEndMessage(true);
|
||||
}
|
||||
} catch (error) {
|
||||
const articleTimeline = document.getElementById('article-timeline');
|
||||
if (articleTimeline && !append) {
|
||||
articleTimeline.innerHTML = '<div class="text-center text-red-500 py-4">获取数据失败,请稍后再试</div>';
|
||||
}
|
||||
} finally {
|
||||
isLoading = false;
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function renderArticles(articles, append = false) {
|
||||
const articleTimeline = document.getElementById('article-timeline');
|
||||
if (!articleTimeline) return;
|
||||
|
||||
if (!articles || articles.length === 0) {
|
||||
if (!append) {
|
||||
articleTimeline.innerHTML = '<div class="text-center py-4 text-secondary-600 dark:text-secondary-400">暂无文章数据</div>';
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const articlesHTML = articles.map(article => `
|
||||
<div class="bg-white dark:bg-dark-card rounded-xl shadow-sm hover:shadow-md overflow-hidden border border-secondary-200 dark:border-dark-border transition-all duration-300">
|
||||
<a href="/articles/${article.id}" class="block p-6 no-underline text-inherit">
|
||||
<div class="flex flex-col md:flex-row md:items-center gap-4">
|
||||
<div class="flex-1">
|
||||
<h3 class="text-xl font-bold text-primary-800 dark:text-primary-200 mb-2 hover:text-primary-600 dark:hover:text-primary-400 transition-colors">${article.title}</h3>
|
||||
<div class="flex items-center text-sm text-secondary-500 dark:text-secondary-400 mb-2">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
</svg>
|
||||
<time datetime="${article.date}">${new Date(article.date).toLocaleDateString('zh-CN')}</time>
|
||||
|
||||
${article.section ? `
|
||||
<span class="mx-2 text-secondary-300 dark:text-secondary-600">•</span>
|
||||
<span class="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
|
||||
</svg>
|
||||
${article.section}
|
||||
</span>
|
||||
` : ''}
|
||||
</div>
|
||||
|
||||
${article.summary ? `<p class="text-secondary-600 dark:text-secondary-300 line-clamp-2 mb-3">${article.summary}</p>` : ''}
|
||||
|
||||
${article.tags && article.tags.length > 0 ? `
|
||||
<div class="flex flex-wrap gap-2">
|
||||
${article.tags.map(tag => `
|
||||
<span class="text-xs bg-primary-50 dark:bg-primary-900/30 text-primary-700 dark:text-primary-300 py-1 px-2 rounded-full">
|
||||
#${tag}
|
||||
</span>
|
||||
`).join('')}
|
||||
</div>
|
||||
` : ''}
|
||||
</div>
|
||||
|
||||
<div class="text-primary-500 dark:text-primary-400 hidden md:block">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 5l7 7m0 0l-7 7m7-7H3" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
if (append) {
|
||||
articleTimeline.innerHTML += articlesHTML;
|
||||
} else {
|
||||
articleTimeline.innerHTML = articlesHTML;
|
||||
}
|
||||
}
|
||||
|
||||
function showLoading(show) {
|
||||
const loading = document.getElementById('loading');
|
||||
if (loading) {
|
||||
loading.classList.toggle('hidden', !show);
|
||||
}
|
||||
}
|
||||
|
||||
function showEndMessage(show) {
|
||||
const endMessage = document.getElementById('end-message');
|
||||
if (endMessage) {
|
||||
endMessage.classList.toggle('hidden', !show);
|
||||
}
|
||||
}
|
||||
|
||||
function setupInfiniteScroll() {
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
|
||||
setTimeout(() => {
|
||||
handleScroll();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function handleScroll() {
|
||||
if (isLoading || !hasMoreContent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollY = window.scrollY;
|
||||
const windowHeight = window.innerHeight;
|
||||
const documentHeight = document.documentElement.scrollHeight;
|
||||
|
||||
if (scrollY + windowHeight >= documentHeight - 300) {
|
||||
fetchArticles(currentPage + 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchArticles(1, false).then(() => {
|
||||
setupInfiniteScroll();
|
||||
}).catch(err => {
|
||||
// 错误已在fetchArticles中处理
|
||||
});
|
||||
});
|
||||
</script>
|
69
src/components/Breadcrumb.astro
Normal file
69
src/components/Breadcrumb.astro
Normal file
@ -0,0 +1,69 @@
|
||||
---
|
||||
// 面包屑导航组件
|
||||
// 接收当前页面类型、路径段和标签过滤器作为参数
|
||||
|
||||
interface Breadcrumb {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
export interface Props {
|
||||
pageType: 'articles' | 'article' | 'timeline'; // 页面类型
|
||||
pathSegments?: string[]; // 路径段数组
|
||||
tagFilter?: string; // 标签过滤器
|
||||
articleTitle?: string; // 文章标题(仅在文章详情页使用)
|
||||
}
|
||||
|
||||
const { pageType, pathSegments = [], tagFilter = '', articleTitle = '' } = Astro.props;
|
||||
|
||||
// 将路径段转换为面包屑对象
|
||||
const breadcrumbs: Breadcrumb[] = pathSegments
|
||||
.filter(segment => segment.trim() !== '')
|
||||
.map((segment, index, array) => {
|
||||
const path = array.slice(0, index + 1).join('/');
|
||||
return { name: segment, path };
|
||||
});
|
||||
|
||||
---
|
||||
|
||||
<div class="flex items-center text-sm">
|
||||
<!-- 文章列表链接 -->
|
||||
<a href="/articles" class="text-secondary-600 dark:text-secondary-400 hover:text-primary-600 dark:hover:text-primary-400 flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M4 4a2 2 0 012-2h4.586A2 2 0 0112 2.586L15.414 6A2 2 0 0116 7.414V16a2 2 0 01-2 2H6a2 2 0 01-2-2V4zm2 6a1 1 0 011-1h6a1 1 0 110 2H7a1 1 0 01-1-1zm1 3a1 1 0 100 2h6a1 1 0 100-2H7z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
文章
|
||||
</a>
|
||||
|
||||
{/* 标签过滤 */}
|
||||
{tagFilter && (
|
||||
<>
|
||||
<span class="mx-2 text-secondary-300 dark:text-secondary-600">/</span>
|
||||
<span class="text-secondary-600 dark:text-secondary-400 flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M17.707 9.293a1 1 0 010 1.414l-7 7a1 1 0 01-1.414 0l-7-7A.997.997 0 012 10V5a3 3 0 013-3h5c.256 0 .512.098.707.293l7 7zM5 6a1 1 0 100-2 1 1 0 000 2z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
{tagFilter}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* 目录路径 */}
|
||||
{!tagFilter && breadcrumbs.map((crumb: Breadcrumb, index: number) => {
|
||||
const crumbPath = breadcrumbs.slice(0, index + 1).map((b: Breadcrumb) => b.name).join('/');
|
||||
return (
|
||||
<span>
|
||||
<span class="mx-2 text-secondary-300 dark:text-secondary-600">/</span>
|
||||
<a href={`/articles?path=${encodeURIComponent(crumbPath)}`} class="text-secondary-600 dark:text-secondary-400 hover:text-primary-600 dark:hover:text-primary-400">{crumb.name}</a>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* 文章标题 */}
|
||||
{pageType === 'article' && articleTitle && (
|
||||
<>
|
||||
<span class="mx-2 text-secondary-300 dark:text-secondary-600">/</span>
|
||||
<span class="text-secondary-600 dark:text-secondary-400 truncate max-w-[150px] sm:max-w-[300px]">{articleTitle}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
215
src/components/DoubanCollection.tsx
Normal file
215
src/components/DoubanCollection.tsx
Normal file
@ -0,0 +1,215 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import ReactMasonryCss from 'react-masonry-css';
|
||||
|
||||
interface DoubanItem {
|
||||
imageUrl: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
link: string;
|
||||
intro: string;
|
||||
rating: number;
|
||||
date: string;
|
||||
}
|
||||
|
||||
interface Pagination {
|
||||
current: number;
|
||||
total: number;
|
||||
hasNext: boolean;
|
||||
hasPrev: boolean;
|
||||
}
|
||||
|
||||
interface DoubanCollectionProps {
|
||||
type: 'movie' | 'book';
|
||||
}
|
||||
|
||||
const DoubanCollection: React.FC<DoubanCollectionProps> = ({ type }) => {
|
||||
const [items, setItems] = useState<DoubanItem[]>([]);
|
||||
const [pagination, setPagination] = useState<Pagination>({ current: 1, total: 1, hasNext: false, hasPrev: false });
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isPageChanging, setIsPageChanging] = useState(false);
|
||||
|
||||
const fetchData = async (start = 0) => {
|
||||
setLoading(true);
|
||||
const params = new URLSearchParams();
|
||||
params.append('type', type);
|
||||
params.append('start', start.toString());
|
||||
|
||||
const url = `/api/douban?${params.toString()}`;
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error('获取数据失败');
|
||||
}
|
||||
const data = await response.json();
|
||||
setItems(data.items);
|
||||
setPagination(data.pagination);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '未知错误');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
}, [type]);
|
||||
|
||||
const updatePage = (page: number) => {
|
||||
const start = (page - 1) * 15;
|
||||
fetchData(start);
|
||||
};
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
const start = (page - 1) * 15;
|
||||
|
||||
// 手动更新分页状态,不等待API响应
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: page
|
||||
}));
|
||||
|
||||
// 重置当前状态,显示加载中
|
||||
setItems([]);
|
||||
setLoading(true);
|
||||
|
||||
fetchData(start);
|
||||
};
|
||||
|
||||
const renderStars = (rating: number) => {
|
||||
return (
|
||||
<div className="flex">
|
||||
{[1, 2, 3, 4, 5].map((star) => (
|
||||
<svg
|
||||
key={star}
|
||||
className={`w-4 h-4 ${star <= rating ? 'text-accent-400' : 'text-secondary-300'}`}
|
||||
fill="currentColor"
|
||||
viewBox="0 0 20 20"
|
||||
>
|
||||
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
|
||||
</svg>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const breakpointColumnsObj = {
|
||||
default: 3,
|
||||
1100: 2,
|
||||
700: 1
|
||||
};
|
||||
|
||||
if (loading && items.length === 0) {
|
||||
return <div className="flex justify-center p-8">加载中...</div>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className="text-red-500 p-4">错误: {error}</div>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="douban-collection">
|
||||
<h2 className="text-2xl font-bold mb-6 text-primary-700">{type === 'movie' ? '观影记录' : '读书记录'}</h2>
|
||||
|
||||
<ReactMasonryCss
|
||||
breakpointCols={breakpointColumnsObj}
|
||||
className="flex -ml-4 w-auto"
|
||||
columnClassName="pl-4 bg-clip-padding"
|
||||
>
|
||||
{items.map((item, index) => (
|
||||
<div key={index} className="mb-6 bg-white rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow duration-300">
|
||||
<a href={item.link} target="_blank" rel="noopener noreferrer" className="block">
|
||||
<div className="relative pb-[140%] overflow-hidden">
|
||||
<img
|
||||
src={item.imageUrl}
|
||||
alt={item.title}
|
||||
className="absolute inset-0 w-full h-full object-cover transition-transform duration-300 hover:scale-105"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-4">
|
||||
<h3 className="font-bold text-lg mb-1 line-clamp-1 text-primary-800">{item.title}</h3>
|
||||
{item.subtitle && <p className="text-secondary-600 text-sm mb-2 line-clamp-1">{item.subtitle}</p>}
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
{renderStars(item.rating)}
|
||||
<span className="text-sm text-secondary-500">{item.date}</span>
|
||||
</div>
|
||||
<p className="text-secondary-700 text-sm line-clamp-3">{item.intro}</p>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
))}
|
||||
</ReactMasonryCss>
|
||||
|
||||
{/* 分页 */}
|
||||
{pagination.total > 1 && (
|
||||
<div className="flex justify-center mt-8 space-x-2">
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
if (isPageChanging) return;
|
||||
|
||||
const prevPage = pagination.current - 1;
|
||||
|
||||
if (prevPage > 0) {
|
||||
setIsPageChanging(true);
|
||||
const prevStart = (prevPage - 1) * 15;
|
||||
|
||||
// 直接调用fetchData
|
||||
fetchData(prevStart);
|
||||
|
||||
// 手动更新分页状态
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: prevPage
|
||||
}));
|
||||
|
||||
setTimeout(() => setIsPageChanging(false), 2000);
|
||||
}
|
||||
}}
|
||||
disabled={!pagination.hasPrev || pagination.current <= 1 || isPageChanging}
|
||||
className={`px-4 py-2 rounded ${!pagination.hasPrev || pagination.current <= 1 || isPageChanging ? 'bg-secondary-200 text-secondary-500 cursor-not-allowed' : 'bg-primary-600 text-white hover:bg-primary-700'}`}
|
||||
>
|
||||
{isPageChanging ? '加载中...' : '上一页'}
|
||||
</button>
|
||||
|
||||
<span className="px-4 py-2 bg-secondary-100 rounded">
|
||||
{pagination.current} / {pagination.total}
|
||||
</span>
|
||||
|
||||
<button
|
||||
onClick={(e) => {
|
||||
e.preventDefault(); // 防止默认行为
|
||||
if (isPageChanging) return;
|
||||
|
||||
// 明确记录当前操作
|
||||
const nextPage = pagination.current + 1;
|
||||
|
||||
// 直接使用明确的页码而不是依赖state
|
||||
if (pagination.current < pagination.total) {
|
||||
setIsPageChanging(true);
|
||||
const nextStart = (nextPage - 1) * 15; // 修正计算方式
|
||||
|
||||
// 直接调用fetchData而不是通过handlePageChange
|
||||
fetchData(nextStart);
|
||||
|
||||
// 手动更新分页状态
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: nextPage
|
||||
}));
|
||||
|
||||
setTimeout(() => setIsPageChanging(false), 2000);
|
||||
}
|
||||
}}
|
||||
disabled={!pagination.hasNext || pagination.current >= pagination.total || isPageChanging}
|
||||
className={`px-4 py-2 rounded ${!pagination.hasNext || pagination.current >= pagination.total || isPageChanging ? 'bg-secondary-200 text-secondary-500 cursor-not-allowed' : 'bg-primary-600 text-white hover:bg-primary-700'}`}
|
||||
>
|
||||
{isPageChanging ? '加载中...' : '下一页'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default DoubanCollection;
|
321
src/components/GitProjectCollection.tsx
Normal file
321
src/components/GitProjectCollection.tsx
Normal file
@ -0,0 +1,321 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import ReactMasonryCss from 'react-masonry-css';
|
||||
import { GIT_CONFIG } from '@/consts';
|
||||
|
||||
// Git 平台类型枚举
|
||||
export enum GitPlatform {
|
||||
GITHUB = 'github',
|
||||
GITEA = 'gitea',
|
||||
GITEE = 'gitee'
|
||||
}
|
||||
|
||||
// 内部使用的平台配置 - 用户不需要修改
|
||||
export const GIT_PLATFORM_CONFIG = {
|
||||
platforms: {
|
||||
[GitPlatform.GITHUB]: {
|
||||
...GIT_CONFIG.github,
|
||||
apiUrl: 'https://api.github.com'
|
||||
},
|
||||
[GitPlatform.GITEA]: {
|
||||
...GIT_CONFIG.gitea
|
||||
},
|
||||
[GitPlatform.GITEE]: {
|
||||
...GIT_CONFIG.gitee,
|
||||
apiUrl: 'https://gitee.com/api/v5'
|
||||
}
|
||||
},
|
||||
enabledPlatforms: [GitPlatform.GITHUB, GitPlatform.GITEA, GitPlatform.GITEE],
|
||||
platformNames: {
|
||||
[GitPlatform.GITHUB]: 'GitHub',
|
||||
[GitPlatform.GITEA]: 'Gitea',
|
||||
[GitPlatform.GITEE]: 'Gitee'
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
interface GitProject {
|
||||
name: string;
|
||||
description: string;
|
||||
url: string;
|
||||
stars: number;
|
||||
forks: number;
|
||||
language: string;
|
||||
updatedAt: string;
|
||||
owner: string;
|
||||
avatarUrl: string;
|
||||
platform: GitPlatform;
|
||||
}
|
||||
|
||||
interface Pagination {
|
||||
current: number;
|
||||
total: number;
|
||||
hasNext: boolean;
|
||||
hasPrev: boolean;
|
||||
}
|
||||
|
||||
interface GitProjectCollectionProps {
|
||||
platform: GitPlatform;
|
||||
username?: string;
|
||||
organization?: string;
|
||||
title?: string;
|
||||
}
|
||||
|
||||
const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
||||
platform,
|
||||
username,
|
||||
organization,
|
||||
title
|
||||
}) => {
|
||||
const [projects, setProjects] = useState<GitProject[]>([]);
|
||||
const [pagination, setPagination] = useState<Pagination>({ current: 1, total: 1, hasNext: false, hasPrev: false });
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [isPageChanging, setIsPageChanging] = useState(false);
|
||||
|
||||
// 获取默认用户名
|
||||
const defaultUsername = GIT_PLATFORM_CONFIG.platforms[platform].username;
|
||||
// 使用提供的用户名或默认用户名
|
||||
const effectiveUsername = username || defaultUsername;
|
||||
|
||||
const fetchData = async (page = 1) => {
|
||||
setLoading(true);
|
||||
const params = new URLSearchParams();
|
||||
params.append('platform', platform);
|
||||
params.append('page', page.toString());
|
||||
|
||||
if (effectiveUsername) {
|
||||
params.append('username', effectiveUsername);
|
||||
}
|
||||
|
||||
if (organization) {
|
||||
params.append('organization', organization);
|
||||
}
|
||||
|
||||
const url = `/api/git-projects?${params.toString()}`;
|
||||
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
if (!response.ok) {
|
||||
throw new Error(`获取数据失败: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
setProjects(data.projects);
|
||||
setPagination(data.pagination);
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : '未知错误');
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
fetchData(1);
|
||||
}, [platform, effectiveUsername, organization]);
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
if (isPageChanging) return;
|
||||
|
||||
setIsPageChanging(true);
|
||||
|
||||
// 重置当前状态,显示加载中
|
||||
setProjects([]);
|
||||
setLoading(true);
|
||||
|
||||
// 手动更新分页状态
|
||||
setPagination(prev => ({
|
||||
...prev,
|
||||
current: page
|
||||
}));
|
||||
|
||||
fetchData(page);
|
||||
setTimeout(() => setIsPageChanging(false), 2000);
|
||||
};
|
||||
|
||||
const getPlatformIcon = (platform: GitPlatform) => {
|
||||
switch (platform) {
|
||||
case GitPlatform.GITHUB:
|
||||
return (
|
||||
<svg className="w-5 h-5" fill="currentColor" viewBox="0 0 24 24">
|
||||
<path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z"/>
|
||||
</svg>
|
||||
);
|
||||
case GitPlatform.GITEA:
|
||||
return (
|
||||
<svg className="w-5 h-5" viewBox="0 0 16 16" fill="currentColor">
|
||||
<path d="M8.948.291c-1.412.274-2.223 1.793-2.223 1.793S4.22 3.326 2.4 5.469c-1.82 2.142-1.415 5.481-1.415 5.481s1.094 3.61 5.061 3.61c3.967 0 5.681-1.853 5.681-1.853s1.225-1.087 1.225-3.718c0-2.632-1.946-3.598-1.946-3.598s.324-1.335-1.061-3.118C8.59.49 8.948.291 8.948.291zM8.13 2.577c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm-3.366.699c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm6.033 0c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm-4.764 2.1c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm3.366 0c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm-5.049 2.1c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm6.732 0c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm-3.366.699c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699zm-1.683 1.4c.386 0 .699.313.699.699 0 .386-.313.699-.699.699-.386 0-.699-.313-.699-.699 0-.386.313-.699.699-.699z"/>
|
||||
</svg>
|
||||
);
|
||||
case GitPlatform.GITEE:
|
||||
return (
|
||||
<svg className="w-5 h-5" viewBox="0 0 1024 1024" fill="currentColor">
|
||||
<path d="M512 1024C229.222 1024 0 794.778 0 512S229.222 0 512 0s512 229.222 512 512-229.222 512-512 512z m259.149-568.883h-290.74a25.293 25.293 0 0 0-25.292 25.293l-0.026 63.206c0 13.952 11.315 25.293 25.267 25.293h177.024c13.978 0 25.293 11.315 25.293 25.267v12.646a75.853 75.853 0 0 1-75.853 75.853h-240.23a25.293 25.293 0 0 1-25.267-25.293V417.203a75.853 75.853 0 0 1 75.827-75.853h353.946a25.293 25.293 0 0 0 25.267-25.292l0.077-63.207a25.293 25.293 0 0 0-25.268-25.293H417.152a189.62 189.62 0 0 0-189.62 189.645V771.15c0 13.977 11.316 25.293 25.294 25.293h372.94a170.65 170.65 0 0 0 170.65-170.65V480.384a25.293 25.293 0 0 0-25.293-25.267z" />
|
||||
</svg>
|
||||
);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const getLanguageColor = (language: string) => {
|
||||
const colors: Record<string, string> = {
|
||||
JavaScript: 'bg-yellow-300',
|
||||
TypeScript: 'bg-blue-400',
|
||||
Python: 'bg-blue-600',
|
||||
Java: 'bg-red-500',
|
||||
Go: 'bg-blue-300',
|
||||
Rust: 'bg-orange-600',
|
||||
C: 'bg-gray-500',
|
||||
'C++': 'bg-pink-500',
|
||||
'C#': 'bg-green-500',
|
||||
PHP: 'bg-purple-500',
|
||||
Ruby: 'bg-red-600',
|
||||
Swift: 'bg-orange-500',
|
||||
Kotlin: 'bg-purple-400',
|
||||
Dart: 'bg-blue-500',
|
||||
HTML: 'bg-orange-400',
|
||||
CSS: 'bg-blue-400',
|
||||
Shell: 'bg-green-600',
|
||||
};
|
||||
|
||||
return colors[language] || 'bg-gray-400';
|
||||
};
|
||||
|
||||
const breakpointColumnsObj = {
|
||||
default: 3,
|
||||
1100: 2,
|
||||
700: 1
|
||||
};
|
||||
|
||||
if (loading && projects.length === 0) {
|
||||
return <div className="flex justify-center p-8">加载中...</div>;
|
||||
}
|
||||
|
||||
if (error) {
|
||||
return <div className="text-red-500 p-4">错误: {error}</div>;
|
||||
}
|
||||
|
||||
const getPlatformName = (platform: GitPlatform) => {
|
||||
return GIT_PLATFORM_CONFIG.platformNames[platform];
|
||||
};
|
||||
|
||||
// 自定义标题或使用默认标题
|
||||
const displayTitle = title || `${getPlatformName(platform)} 项目`;
|
||||
|
||||
return (
|
||||
<div className="git-project-collection">
|
||||
<h2 className="text-2xl font-bold mb-6 text-primary-700">
|
||||
{displayTitle}
|
||||
{effectiveUsername && <span className="ml-2 text-secondary-500">(@{effectiveUsername})</span>}
|
||||
{organization && <span className="ml-2 text-secondary-500">(组织: {organization})</span>}
|
||||
</h2>
|
||||
|
||||
{loading && projects.length === 0 ? (
|
||||
<div className="flex justify-center p-8">加载中...</div>
|
||||
) : error ? (
|
||||
<div className="text-red-500 p-4">错误: {error}</div>
|
||||
) : projects.length === 0 ? (
|
||||
<div className="text-secondary-500 p-4">
|
||||
{platform === GitPlatform.GITEE ?
|
||||
"无法获取 Gitee 项目数据,可能需要配置访问令牌。" :
|
||||
"没有找到项目数据。"}
|
||||
</div>
|
||||
) : (
|
||||
<ReactMasonryCss
|
||||
breakpointCols={breakpointColumnsObj}
|
||||
className="flex -ml-4 w-auto"
|
||||
columnClassName="pl-4 bg-clip-padding"
|
||||
>
|
||||
{projects.map((project, index) => (
|
||||
<div key={`${project.platform}-${project.owner}-${project.name}-${index}`} className="mb-4 overflow-hidden rounded-lg border border-secondary-200 bg-white shadow-sm transition-shadow hover:shadow-md">
|
||||
<a href={project.url} target="_blank" rel="noopener noreferrer" className="block p-4">
|
||||
<div className="flex items-center mb-2">
|
||||
<div className="mr-2 text-secondary-600">
|
||||
{getPlatformIcon(project.platform as GitPlatform)}
|
||||
</div>
|
||||
<div className="flex-1 truncate">
|
||||
<div className="flex items-center">
|
||||
<img
|
||||
src={project.avatarUrl}
|
||||
alt={`${project.owner}'s avatar`}
|
||||
className="w-5 h-5 rounded-full mr-2"
|
||||
onError={(e) => {
|
||||
const target = e.target as HTMLImageElement;
|
||||
target.onerror = null;
|
||||
target.src = 'https://via.placeholder.com/40';
|
||||
}}
|
||||
/>
|
||||
<span className="text-sm text-secondary-600 truncate">{project.owner}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 className="text-lg font-semibold mb-1 text-primary-800 line-clamp-1">{project.name}</h3>
|
||||
|
||||
{project.description && (
|
||||
<p className="text-secondary-700 text-sm mb-3 line-clamp-2">{project.description}</p>
|
||||
)}
|
||||
|
||||
<div className="flex flex-wrap items-center text-xs mt-2">
|
||||
{project.language && (
|
||||
<div className="flex items-center mr-4 mb-1">
|
||||
<span className={`w-3 h-3 rounded-full mr-1 ${getLanguageColor(project.language)}`}></span>
|
||||
<span className="text-secondary-600">{project.language}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="flex items-center mr-4 mb-1">
|
||||
<svg className="w-4 h-4 mr-1 text-secondary-500" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fillRule="evenodd" d="M10 2a1 1 0 011 1v1.323l3.954 1.582 1.599-.8a1 1 0 01.894 1.79l-1.233.616 1.738 5.42a1 1 0 01-.285 1.05A3.989 3.989 0 0115 15a3.989 3.989 0 01-2.667-1.019 1 1 0 01-.285-1.05l1.715-5.349L11 6.477V16h2a1 1 0 110 2H7a1 1 0 110-2h2V6.477L6.237 7.582l1.715 5.349a1 1 0 01-.285 1.05A3.989 3.989 0 015 15a3.989 3.989 0 01-2.667-1.019 1 1 0 01-.285-1.05l1.738-5.42-1.233-.617a1 1 0 01.894-1.788l1.599.799L9 4.323V3a1 1 0 011-1zm-5 8.274l-.818 2.552c.25.112.526.174.818.174.292 0 .569-.062.818-.174L5 10.274zm10 0l-.818 2.552c.25.112.526.174.818.174.292 0 .569-.062.818-.174L15 10.274z" clipRule="evenodd" />
|
||||
</svg>
|
||||
<span className="text-secondary-600">{project.stars}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center mr-4 mb-1">
|
||||
<svg className="w-4 h-4 mr-1 text-secondary-500" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fillRule="evenodd" d="M12.316 3.051a1 1 0 01.633 1.265l-4 12a1 1 0 11-1.898-.632l4-12a1 1 0 011.265-.633zM5.707 6.293a1 1 0 010 1.414L3.414 10l2.293 2.293a1 1 0 11-1.414 1.414l-3-3a1 1 0 010-1.414l3-3a1 1 0 011.414 0zm8.586 0a1 1 0 011.414 0l3 3a1 1 0 010 1.414l-3 3a1 1 0 11-1.414-1.414L16.586 10l-2.293-2.293a1 1 0 010-1.414z" clipRule="evenodd" />
|
||||
</svg>
|
||||
<span className="text-secondary-600">{project.forks}</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center mb-1 ml-auto">
|
||||
<svg className="w-4 h-4 mr-1 text-secondary-500" fill="currentColor" viewBox="0 0 20 20">
|
||||
<path fillRule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm1-12a1 1 0 10-2 0v4a1 1 0 00.293.707l2.828 2.829a1 1 0 101.415-1.415L11 9.586V6z" clipRule="evenodd" />
|
||||
</svg>
|
||||
<span className="text-secondary-500">{new Date(project.updatedAt).toLocaleDateString('zh-CN')}</span>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</div>
|
||||
))}
|
||||
</ReactMasonryCss>
|
||||
)}
|
||||
|
||||
{pagination.total > 1 && (
|
||||
<div className="flex justify-center mt-8 space-x-2">
|
||||
<button
|
||||
onClick={() => handlePageChange(pagination.current - 1)}
|
||||
disabled={!pagination.hasPrev || pagination.current <= 1 || isPageChanging}
|
||||
className={`px-4 py-2 rounded ${!pagination.hasPrev || pagination.current <= 1 || isPageChanging ? 'bg-secondary-200 text-secondary-500 cursor-not-allowed' : 'bg-primary-600 text-white hover:bg-primary-700'}`}
|
||||
>
|
||||
{isPageChanging ? '加载中...' : '上一页'}
|
||||
</button>
|
||||
|
||||
<span className="px-4 py-2 bg-secondary-100 rounded">
|
||||
{pagination.current} / {pagination.total}
|
||||
</span>
|
||||
|
||||
<button
|
||||
onClick={() => handlePageChange(pagination.current + 1)}
|
||||
disabled={!pagination.hasNext || pagination.current >= pagination.total || isPageChanging}
|
||||
className={`px-4 py-2 rounded ${!pagination.hasNext || pagination.current >= pagination.total || isPageChanging ? 'bg-secondary-200 text-secondary-500 cursor-not-allowed' : 'bg-primary-600 text-white hover:bg-primary-700'}`}
|
||||
>
|
||||
{isPageChanging ? '加载中...' : '下一页'}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default GitProjectCollection;
|
34
src/components/Layout.astro
Normal file
34
src/components/Layout.astro
Normal file
@ -0,0 +1,34 @@
|
||||
---
|
||||
import "@/styles/global.css";
|
||||
import Header from "@/components/header.astro";
|
||||
---
|
||||
<!doctype html>
|
||||
<html lang="en" class="m-0 w-full h-full">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<meta name="referrer" content="no-referrer" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>New Echoes</title>
|
||||
<script is:inline>
|
||||
// 立即执行主题初始化
|
||||
const theme = (() => {
|
||||
if (typeof localStorage !== 'undefined' && localStorage.getItem('theme')) {
|
||||
return localStorage.getItem('theme');
|
||||
}
|
||||
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
return 'dark';
|
||||
}
|
||||
return 'light';
|
||||
})();
|
||||
document.documentElement.dataset.theme = theme;
|
||||
</script>
|
||||
</head>
|
||||
<body class="m-0 w-full h-full bg-white dark:bg-dark-bg transition-colors duration-300">
|
||||
<Header />
|
||||
<main class="pt-16">
|
||||
<slot />
|
||||
</main>
|
||||
</body>
|
||||
</html>
|
155
src/components/MediaGrid.astro
Normal file
155
src/components/MediaGrid.astro
Normal file
@ -0,0 +1,155 @@
|
||||
---
|
||||
interface Props {
|
||||
type: 'movie' | 'book';
|
||||
title: string;
|
||||
}
|
||||
|
||||
const { type, title } = Astro.props;
|
||||
---
|
||||
|
||||
<div class="container mx-auto px-4 py-8">
|
||||
<h1 class="text-3xl font-bold mb-6">{title}</h1>
|
||||
|
||||
<div id="media-list" class="grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-4">
|
||||
<!-- 内容将通过JS动态加载 -->
|
||||
</div>
|
||||
|
||||
<div id="loading" class="text-center py-8">
|
||||
<div class="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"></div>
|
||||
<p class="mt-2 text-gray-600">加载更多...</p>
|
||||
</div>
|
||||
|
||||
<div id="end-message" class="text-center py-8 hidden">
|
||||
<p class="text-gray-600">已加载全部内容</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script is:inline define:vars={{ type }}>
|
||||
|
||||
let currentPage = 1;
|
||||
let isLoading = false;
|
||||
let hasMoreContent = true;
|
||||
const itemsPerPage = 15; // 豆瓣每页显示的数量
|
||||
|
||||
async function fetchMedia(page = 1, append = false) {
|
||||
if (isLoading || (!append && !hasMoreContent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
isLoading = true;
|
||||
showLoading(true);
|
||||
|
||||
const start = (page - 1) * itemsPerPage;
|
||||
try {
|
||||
const response = await fetch(`/api/douban?type=${type}&start=${start}`);
|
||||
if (!response.ok) {
|
||||
throw new Error(`获取${type === 'movie' ? '电影' : '图书'}数据失败`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
renderMedia(data.items, append);
|
||||
|
||||
// 更新分页状态
|
||||
currentPage = data.pagination.current;
|
||||
hasMoreContent = data.pagination.hasNext;
|
||||
|
||||
if (!hasMoreContent) {
|
||||
showEndMessage(true);
|
||||
}
|
||||
} catch (error) {
|
||||
const mediaList = document.getElementById('media-list');
|
||||
if (mediaList && !append) {
|
||||
mediaList.innerHTML = '<div class="col-span-full text-center text-red-500">获取数据失败,请稍后再试</div>';
|
||||
}
|
||||
} finally {
|
||||
isLoading = false;
|
||||
showLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
function renderMedia(items, append = false) {
|
||||
const mediaList = document.getElementById('media-list');
|
||||
if (!mediaList) return;
|
||||
|
||||
if (!items || items.length === 0) {
|
||||
if (!append) {
|
||||
mediaList.innerHTML = `<div class="col-span-full text-center">暂无${type === 'movie' ? '电影' : '图书'}数据</div>`;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
const mediaHTML = items.map(item => `
|
||||
<div class="bg-white rounded-lg overflow-hidden shadow-md hover:shadow-xl transition-shadow duration-300">
|
||||
<div class="relative pb-[150%] overflow-hidden">
|
||||
<img src="${item.imageUrl}" alt="${item.title}" class="absolute top-0 left-0 w-full h-full object-cover transition-transform duration-300 hover:scale-105">
|
||||
<div class="absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/80 to-transparent">
|
||||
<h3 class="font-bold text-white text-sm line-clamp-2">
|
||||
<a href="${item.link}" target="_blank" class="hover:text-blue-300 transition-colors">${item.title}</a>
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
`).join('');
|
||||
|
||||
if (append) {
|
||||
mediaList.innerHTML += mediaHTML;
|
||||
} else {
|
||||
mediaList.innerHTML = mediaHTML;
|
||||
}
|
||||
}
|
||||
|
||||
function showLoading(show) {
|
||||
const loading = document.getElementById('loading');
|
||||
if (loading) {
|
||||
if (show) {
|
||||
loading.innerHTML = `
|
||||
<div class="inline-block h-8 w-8 animate-spin rounded-full border-4 border-solid border-current border-r-transparent align-[-0.125em] motion-reduce:animate-[spin_1.5s_linear_infinite]"></div>
|
||||
<p class="mt-2 text-gray-600">加载更多...</p>
|
||||
`;
|
||||
} else {
|
||||
loading.innerHTML = `<div class="h-8"></div>`; // 保持元素可见但内容为空
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function showEndMessage(show) {
|
||||
const endMessage = document.getElementById('end-message');
|
||||
if (endMessage) {
|
||||
endMessage.classList.toggle('hidden', !show);
|
||||
}
|
||||
}
|
||||
|
||||
function setupInfiniteScroll() {
|
||||
// 直接使用滚动事件
|
||||
window.addEventListener('scroll', handleScroll);
|
||||
|
||||
// 初始检查一次,以防内容不足一屏
|
||||
setTimeout(() => {
|
||||
handleScroll();
|
||||
}, 500);
|
||||
}
|
||||
|
||||
function handleScroll() {
|
||||
if (isLoading || !hasMoreContent) {
|
||||
return;
|
||||
}
|
||||
|
||||
const scrollY = window.scrollY;
|
||||
const windowHeight = window.innerHeight;
|
||||
const documentHeight = document.documentElement.scrollHeight;
|
||||
|
||||
// 当滚动到距离底部300px时加载更多
|
||||
if (scrollY + windowHeight >= documentHeight - 300) {
|
||||
fetchMedia(currentPage + 1, true);
|
||||
}
|
||||
}
|
||||
|
||||
// 初始加载
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
fetchMedia(1, false).then(() => {
|
||||
setupInfiniteScroll();
|
||||
}).catch(err => {
|
||||
// 错误已在fetchMedia中处理
|
||||
});
|
||||
});
|
||||
</script>
|
64
src/components/ThemeToggle.jsx
Normal file
64
src/components/ThemeToggle.jsx
Normal file
@ -0,0 +1,64 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
export function ThemeToggle({ height = 20, width = 20, fill = "currentColor" }) {
|
||||
// 从 document.documentElement.dataset.theme 获取初始主题
|
||||
const [theme, setTheme] = useState(() => {
|
||||
if (typeof document !== 'undefined') {
|
||||
return document.documentElement.dataset.theme || 'light';
|
||||
}
|
||||
return 'light';
|
||||
});
|
||||
const [mounted, setMounted] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted) return;
|
||||
|
||||
// 当主题改变时更新 DOM 和 localStorage
|
||||
const root = document.documentElement;
|
||||
root.dataset.theme = theme;
|
||||
|
||||
if (theme === getSystemTheme()) {
|
||||
localStorage.removeItem('theme');
|
||||
} else {
|
||||
localStorage.setItem('theme', theme);
|
||||
}
|
||||
}, [theme, mounted]);
|
||||
|
||||
function getSystemTheme() {
|
||||
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
|
||||
}
|
||||
|
||||
function toggleTheme() {
|
||||
setTheme(prevTheme => prevTheme === 'light' ? 'dark' : 'light');
|
||||
}
|
||||
|
||||
return (
|
||||
<div
|
||||
className="inline-flex items-center justify-center cursor-pointer"
|
||||
style={{ height: `${height}px`, width: `${width}px` }}
|
||||
onClick={toggleTheme}
|
||||
>
|
||||
{theme === 'dark' ? (
|
||||
<svg
|
||||
style={{ height: `${height * 2/3}px`, width: `${width * 2/3}px` }}
|
||||
fill={fill}
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path d="M6 .278a.768.768 0 0 1 .08.858 7.208 7.208 0 0 0-.878 3.46c0 4.021 3.278 7.277 7.318 7.277.527 0 1.04-.055 1.533-.16a.787.787 0 0 1 .81.316.733.733 0 0 1-.031.893A8.349 8.349 0 0 1 8.344 16C3.734 16 0 12.286 0 7.71 0 4.266 2.114 1.312 5.124.06A.752.752 0 0 1 6 .278z"/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
style={{ height: `${height * 2/3}px`, width: `${width * 2/3}px` }}
|
||||
fill={fill}
|
||||
viewBox="0 0 16 16"
|
||||
>
|
||||
<path d="M8 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM8 0a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 0zm0 13a.5.5 0 0 1 .5.5v2a.5.5 0 0 1-1 0v-2A.5.5 0 0 1 8 13zm8-5a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2a.5.5 0 0 1 .5.5zM3 8a.5.5 0 0 1-.5.5h-2a.5.5 0 0 1 0-1h2A.5.5 0 0 1 3 8zm10.657-5.657a.5.5 0 0 1 0 .707l-1.414 1.415a.5.5 0 1 1-.707-.708l1.414-1.414a.5.5 0 0 1 .707 0zm-9.193 9.193a.5.5 0 0 1 0 .707L3.05 13.657a.5.5 0 0 1-.707-.707l1.414-1.414a.5.5 0 0 1 .707 0zm9.193 2.121a.5.5 0 0 1-.707 0l-1.414-1.414a.5.5 0 0 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .707zM4.464 4.465a.5.5 0 0 1-.707 0L2.343 3.05a.5.5 0 1 1 .707-.707l1.414 1.414a.5.5 0 0 1 0 .708z"/>
|
||||
</svg>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
@ -1,209 +0,0 @@
|
||||
---
|
||||
import astroLogo from '../assets/astro.svg';
|
||||
import background from '../assets/background.svg';
|
||||
---
|
||||
|
||||
<div id="container">
|
||||
<img id="background" src={background.src} alt="" fetchpriority="high" />
|
||||
<main>
|
||||
<section id="hero">
|
||||
<a href="https://astro.build"
|
||||
><img src={astroLogo.src} width="115" height="48" alt="Astro Homepage" /></a
|
||||
>
|
||||
<h1>
|
||||
To get started, open the <code><pre>src/pages</pre></code> directory in your project.
|
||||
</h1>
|
||||
<section id="links">
|
||||
<a class="button" href="https://docs.astro.build">Read our docs</a>
|
||||
<a href="https://astro.build/chat"
|
||||
>Join our Discord <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 127.14 96.36"
|
||||
><path
|
||||
fill="currentColor"
|
||||
d="M107.7 8.07A105.15 105.15 0 0 0 81.47 0a72.06 72.06 0 0 0-3.36 6.83 97.68 97.68 0 0 0-29.11 0A72.37 72.37 0 0 0 45.64 0a105.89 105.89 0 0 0-26.25 8.09C2.79 32.65-1.71 56.6.54 80.21a105.73 105.73 0 0 0 32.17 16.15 77.7 77.7 0 0 0 6.89-11.11 68.42 68.42 0 0 1-10.85-5.18c.91-.66 1.8-1.34 2.66-2a75.57 75.57 0 0 0 64.32 0c.87.71 1.76 1.39 2.66 2a68.68 68.68 0 0 1-10.87 5.19 77 77 0 0 0 6.89 11.1 105.25 105.25 0 0 0 32.19-16.14c2.64-27.38-4.51-51.11-18.9-72.15ZM42.45 65.69C36.18 65.69 31 60 31 53s5-12.74 11.43-12.74S54 46 53.89 53s-5.05 12.69-11.44 12.69Zm42.24 0C78.41 65.69 73.25 60 73.25 53s5-12.74 11.44-12.74S96.23 46 96.12 53s-5.04 12.69-11.43 12.69Z"
|
||||
></path></svg
|
||||
>
|
||||
</a>
|
||||
</section>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<a href="https://astro.build/blog/astro-5/" id="news" class="box">
|
||||
<svg width="32" height="32" fill="none" xmlns="http://www.w3.org/2000/svg"
|
||||
><path
|
||||
d="M24.667 12c1.333 1.414 2 3.192 2 5.334 0 4.62-4.934 5.7-7.334 12C18.444 28.567 18 27.456 18 26c0-4.642 6.667-7.053 6.667-14Zm-5.334-5.333c1.6 1.65 2.4 3.43 2.4 5.333 0 6.602-8.06 7.59-6.4 17.334C13.111 27.787 12 25.564 12 22.666c0-4.434 7.333-8 7.333-16Zm-6-5.333C15.111 3.555 16 5.556 16 7.333c0 8.333-11.333 10.962-5.333 22-3.488-.774-6-4-6-8 0-8.667 8.666-10 8.666-20Z"
|
||||
fill="#111827"></path></svg
|
||||
>
|
||||
<h2>What's New in Astro 5.0?</h2>
|
||||
<p>
|
||||
From content layers to server islands, click to learn more about the new features and
|
||||
improvements in Astro 5.0
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
#background {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
z-index: -1;
|
||||
filter: blur(100px);
|
||||
}
|
||||
|
||||
#container {
|
||||
font-family: Inter, Roboto, 'Helvetica Neue', 'Arial Nova', 'Nimbus Sans', Arial, sans-serif;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
main {
|
||||
height: 100%;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
#hero {
|
||||
display: flex;
|
||||
align-items: start;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
margin-top: 0.25em;
|
||||
}
|
||||
|
||||
#links {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
#links a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 10px 12px;
|
||||
color: #111827;
|
||||
text-decoration: none;
|
||||
transition: color 0.2s;
|
||||
}
|
||||
|
||||
#links a:hover {
|
||||
color: rgb(78, 80, 86);
|
||||
}
|
||||
|
||||
#links a svg {
|
||||
height: 1em;
|
||||
margin-left: 8px;
|
||||
}
|
||||
|
||||
#links a.button {
|
||||
color: white;
|
||||
background: linear-gradient(83.21deg, #3245ff 0%, #bc52ee 100%);
|
||||
box-shadow:
|
||||
inset 0 0 0 1px rgba(255, 255, 255, 0.12),
|
||||
inset 0 -2px 0 rgba(0, 0, 0, 0.24);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
#links a.button:hover {
|
||||
color: rgb(230, 230, 230);
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas,
|
||||
'DejaVu Sans Mono', monospace;
|
||||
font-weight: normal;
|
||||
background: linear-gradient(14deg, #d83333 0%, #f041ff 100%);
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
h2 {
|
||||
margin: 0 0 1em;
|
||||
font-weight: normal;
|
||||
color: #111827;
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
p {
|
||||
color: #4b5563;
|
||||
font-size: 16px;
|
||||
line-height: 24px;
|
||||
letter-spacing: -0.006em;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
code {
|
||||
display: inline-block;
|
||||
background:
|
||||
linear-gradient(66.77deg, #f3cddd 0%, #f5cee7 100%) padding-box,
|
||||
linear-gradient(155deg, #d83333 0%, #f041ff 18%, #f5cee7 45%) border-box;
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.box {
|
||||
padding: 16px;
|
||||
background: rgba(255, 255, 255, 1);
|
||||
border-radius: 16px;
|
||||
border: 1px solid white;
|
||||
}
|
||||
|
||||
#news {
|
||||
position: absolute;
|
||||
bottom: 16px;
|
||||
right: 16px;
|
||||
max-width: 300px;
|
||||
text-decoration: none;
|
||||
transition: background 0.2s;
|
||||
backdrop-filter: blur(50px);
|
||||
}
|
||||
|
||||
#news:hover {
|
||||
background: rgba(255, 255, 255, 0.55);
|
||||
}
|
||||
|
||||
@media screen and (max-height: 368px) {
|
||||
#news {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
#container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#hero {
|
||||
display: block;
|
||||
padding-top: 10%;
|
||||
}
|
||||
|
||||
#links {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
#links a.button {
|
||||
padding: 14px 18px;
|
||||
}
|
||||
|
||||
#news {
|
||||
right: 16px;
|
||||
left: 16px;
|
||||
bottom: 2.5rem;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
line-height: 1.5;
|
||||
}
|
||||
}
|
||||
</style>
|
58
src/components/header.astro
Normal file
58
src/components/header.astro
Normal file
@ -0,0 +1,58 @@
|
||||
---
|
||||
import { SITE_NAME, NAV_LINKS } from '@/consts.ts';
|
||||
import { ThemeToggle } from './ThemeToggle';
|
||||
|
||||
// 获取当前路径
|
||||
const currentPath = Astro.url.pathname;
|
||||
|
||||
// 移除结尾的斜杠以统一路径格式
|
||||
const normalizedPath = currentPath.endsWith('/') ? currentPath.slice(0, -1) : currentPath;
|
||||
|
||||
// 定义导航链接
|
||||
|
||||
---
|
||||
<header class="fixed w-full top-0 z-50 bg-white/80 dark:bg-dark-surface/80 backdrop-blur-md border-b border-secondary-200 dark:border-dark-border">
|
||||
<nav>
|
||||
<div class="max-w-6xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||
<div class="flex justify-between h-16">
|
||||
<!-- Logo 部分 -->
|
||||
<div class="flex items-center">
|
||||
<a href="/" class="text-lg font-semibold text-primary-900 dark:text-primary-100 hover:text-primary-600 dark:hover:text-primary-400">
|
||||
{SITE_NAME}
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<!-- 导航链接 -->
|
||||
<div class="hidden md:flex md:items-center md:space-x-8">
|
||||
{NAV_LINKS.map(link => (
|
||||
<a
|
||||
href={link.href}
|
||||
class:list={[
|
||||
'inline-flex items-center px-1 pt-1 text-sm font-medium',
|
||||
normalizedPath === (link.href === '/' ? '' : link.href)
|
||||
? 'text-primary-600 dark:text-primary-400 border-b-2 border-primary-600 dark:border-primary-400'
|
||||
: 'text-secondary-600 dark:text-secondary-400 hover:text-primary-600 dark:hover:text-primary-400 hover:border-b-2 hover:border-primary-300 dark:hover:border-primary-700'
|
||||
]}
|
||||
>
|
||||
{link.text}
|
||||
</a>
|
||||
))}
|
||||
<ThemeToggle client:load />
|
||||
</div>
|
||||
|
||||
<!-- 移动端菜单按钮 -->
|
||||
<div class="flex items-center md:hidden">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center justify-center p-2 rounded-md text-secondary-400 dark:text-secondary-500 hover:text-secondary-500 dark:hover:text-secondary-400 hover:bg-secondary-100 dark:hover:bg-dark-card focus:outline-none focus:ring-2 focus:ring-inset focus:ring-primary-500"
|
||||
>
|
||||
<span class="sr-only">打开菜单</span>
|
||||
<svg class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
36
src/consts.ts
Normal file
36
src/consts.ts
Normal file
@ -0,0 +1,36 @@
|
||||
export const SITE_NAME = "Blog Name";
|
||||
export const NAV_LINKS = [
|
||||
{ href: '/', text: '首页' },
|
||||
{ href: '/articles', text: '文章' },
|
||||
{ href: '/movies', text: '观影' },
|
||||
{ href: '/books', text: '读书' },
|
||||
{ href: '/about', text: '关于' },
|
||||
{ href: '/projects', text: '项目' }
|
||||
];
|
||||
|
||||
export const VISITED_PLACES = [ '黑龙江', '吉林', '辽宁', '北京', '天津', '广东', '西藏', '河北', '山东', '湖南','重庆','四川' ];
|
||||
|
||||
export const DOUBAN_ID = 'lsy22';
|
||||
|
||||
|
||||
// Git 配置 - 只包含用户需要修改的内容
|
||||
export const GIT_CONFIG = {
|
||||
// 每页显示的项目数量
|
||||
perPage: 10,
|
||||
|
||||
// 用户配置 - 用户只需修改这部分
|
||||
github: {
|
||||
username: 'lsy2246', // GitHub 用户名
|
||||
token: '' // GitHub 访问令牌(可选)
|
||||
},
|
||||
gitea: {
|
||||
url: 'https://g.lsy22.com', // Gitea 实例 URL
|
||||
username: 'lsy', // Gitea 用户名
|
||||
token: '' // Gitea 访问令牌(可选)
|
||||
},
|
||||
gitee: {
|
||||
username: 'lsy22', // Gitee 用户名
|
||||
token: '' // Gitee 访问令牌(可选)
|
||||
}
|
||||
};
|
||||
|
148
src/content.config.ts
Normal file
148
src/content.config.ts
Normal file
@ -0,0 +1,148 @@
|
||||
// 1. 从 `astro:content` 导入工具函数
|
||||
import { defineCollection, z } from 'astro:content';
|
||||
import { glob } from 'astro/loaders';
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
// 2. 定义内容结构接口
|
||||
export interface ContentStructure {
|
||||
articles: string[];
|
||||
sections: SectionStructure[];
|
||||
}
|
||||
|
||||
export interface SectionStructure {
|
||||
name: string;
|
||||
path: string;
|
||||
articles: string[];
|
||||
sections: SectionStructure[];
|
||||
}
|
||||
|
||||
// 辅助函数:获取相对于content目录的路径
|
||||
export function getRelativePath(fullPath: string, basePath = './src/content'): string {
|
||||
// 统一路径分隔符
|
||||
const normalizedPath = fullPath.replace(/\\/g, '/');
|
||||
const normalizedBasePath = basePath.replace(/\\/g, '/');
|
||||
|
||||
// 移除基础路径
|
||||
let relativePath = normalizedPath;
|
||||
|
||||
// 如果路径包含基础路径,则移除它
|
||||
if (normalizedPath.includes(normalizedBasePath)) {
|
||||
relativePath = normalizedPath.replace(normalizedBasePath, '');
|
||||
}
|
||||
|
||||
// 移除开头的斜杠
|
||||
relativePath = relativePath.startsWith('/') ? relativePath.substring(1) : relativePath;
|
||||
|
||||
// 如果路径以articles/开头,移除它(适配Astro内容集合)
|
||||
if (relativePath.startsWith('articles/')) {
|
||||
relativePath = relativePath.substring('articles/'.length);
|
||||
}
|
||||
|
||||
return relativePath;
|
||||
}
|
||||
|
||||
// 辅助函数:从文件路径中提取文件名(不带扩展名)
|
||||
export function getBasename(filePath: string): string {
|
||||
// 统一路径分隔符
|
||||
const normalizedPath = filePath.replace(/\\/g, '/');
|
||||
|
||||
// 分割路径并获取最后一部分(文件名)
|
||||
const parts = normalizedPath.split('/');
|
||||
const fileName = parts[parts.length - 1];
|
||||
|
||||
// 移除扩展名
|
||||
const basename = fileName.replace(/\.(md|mdx)$/, '');
|
||||
|
||||
return basename;
|
||||
}
|
||||
|
||||
// 辅助函数:从文件路径中提取目录路径
|
||||
export function getDirPath(filePath: string, basePath = './src/content'): string {
|
||||
const basename = getBasename(filePath);
|
||||
const relativePath = getRelativePath(filePath, basePath);
|
||||
|
||||
// 移除文件名部分,获取目录路径
|
||||
const dirPath = relativePath.replace(`${basename}.md`, '').replace(/\/$/, '');
|
||||
|
||||
return dirPath;
|
||||
}
|
||||
|
||||
// 3. 定义目录结构处理函数
|
||||
function getContentStructure(contentDir = './src/content', basePath = './src/content'): ContentStructure {
|
||||
// 检查目录是否存在
|
||||
if (!fs.existsSync(contentDir)) {
|
||||
return { articles: [], sections: [] };
|
||||
}
|
||||
// 获取目录下的所有文件和文件夹
|
||||
const items = fs.readdirSync(contentDir, { withFileTypes: true });
|
||||
|
||||
// 分离文章和目录
|
||||
const articles = items
|
||||
.filter(item => item.isFile() && item.name.endsWith('.md'))
|
||||
.map(item => {
|
||||
// 生成相对于content目录的路径,用于在页面中查找文章
|
||||
const fullPath = path.join(contentDir, item.name);
|
||||
// 将路径转换为相对于content目录的格式
|
||||
return fullPath.replace(/\\/g, '/');
|
||||
});
|
||||
|
||||
// 获取子目录(作为章节)
|
||||
const sections: SectionStructure[] = items
|
||||
.filter(item => item.isDirectory())
|
||||
.map(item => {
|
||||
const sectionPath = path.join(contentDir, item.name);
|
||||
// 递归获取子目录的结构
|
||||
const sectionContent: ContentStructure = getContentStructure(sectionPath, basePath);
|
||||
|
||||
// 确保路径格式正确
|
||||
const normalizedPath = sectionPath.replace(/\\/g, '/');
|
||||
|
||||
return {
|
||||
name: item.name,
|
||||
path: normalizedPath,
|
||||
articles: sectionContent.articles,
|
||||
sections: sectionContent.sections
|
||||
};
|
||||
});
|
||||
|
||||
return { articles, sections };
|
||||
}
|
||||
|
||||
// 4. 定义你的集合
|
||||
const articles = defineCollection({
|
||||
// 使用glob加载器从content目录加载所有markdown文件
|
||||
loader: glob({ pattern: "**/*.md", base: "./src/content" }),
|
||||
schema: z.object({
|
||||
title: z.string(),
|
||||
date: z.date(),
|
||||
tags: z.array(z.string()).optional(),
|
||||
summary: z.string().optional(),
|
||||
image: z.string().optional(),
|
||||
author: z.string().optional(),
|
||||
draft: z.boolean().optional().default(false),
|
||||
// 添加section字段,用于标识文章所属的目录
|
||||
section: z.string().optional(),
|
||||
// 添加weight字段,用于排序
|
||||
weight: z.number().optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// 5. 定义目录集合
|
||||
const sections = defineCollection({
|
||||
type: 'data',
|
||||
schema: z.object({
|
||||
name: z.string(),
|
||||
title: z.string().optional(),
|
||||
description: z.string().optional(),
|
||||
weight: z.number().optional(),
|
||||
articles: z.array(z.string()).optional(),
|
||||
subsections: z.array(z.string()).optional(),
|
||||
}),
|
||||
});
|
||||
|
||||
// 6. 导出一个 `collections` 对象来注册你的集合
|
||||
export const collections = { articles, sections };
|
||||
|
||||
// 7. 导出内容结构,可以在构建时使用
|
||||
export const contentStructure = getContentStructure();
|
19
src/content/a/a.md
Normal file
19
src/content/a/a.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "测试文章"
|
||||
date: 2023-03-03
|
||||
tags: ["测试"]
|
||||
category: "测试分类"
|
||||
summary: "这是一篇测试文章,用于测试目录结构"
|
||||
---
|
||||
|
||||
# 测试文章
|
||||
|
||||
这是一篇测试文章,用于测试目录结构功能。
|
||||
|
||||
## 二级标题
|
||||
|
||||
这是二级标题下的内容。
|
||||
|
||||
### 三级标题
|
||||
|
||||
这是三级标题下的内容。
|
335
src/content/a/d/d.md
Normal file
335
src/content/a/d/d.md
Normal file
@ -0,0 +1,335 @@
|
||||
---
|
||||
title: "多级目录测试文章"
|
||||
date: 2023-03-03
|
||||
tags: ["测试", "多级目录"]
|
||||
category: "测试分类"
|
||||
summary: "这是一篇用于测试多级目录功能的文章"
|
||||
---
|
||||
## 1. 基础语法
|
||||
|
||||
### 1.1 粗体文本
|
||||
|
||||
```markdown
|
||||
**这是粗体文本**
|
||||
```
|
||||
|
||||
**这是粗体文本**
|
||||
|
||||
### 1.2 斜体文本
|
||||
|
||||
```markdown
|
||||
*这是斜体文本*
|
||||
```
|
||||
|
||||
*这是斜体文本*
|
||||
|
||||
### 1.3 粗斜体文本
|
||||
|
||||
```markdown
|
||||
***这是粗斜体文本***
|
||||
```
|
||||
|
||||
***这是粗斜体文本***
|
||||
|
||||
### 1.4 删除线文本
|
||||
|
||||
```markdown
|
||||
~~这是删除线文本~~
|
||||
```
|
||||
|
||||
~~这是删除线文本~~
|
||||
|
||||
### 1.5 无序列表
|
||||
|
||||
```markdown
|
||||
- 第一项
|
||||
- 子项 1
|
||||
- 子项 2
|
||||
- 第二项
|
||||
- 第三项
|
||||
```
|
||||
|
||||
- 第一项
|
||||
- 子项 1
|
||||
- 子项 2
|
||||
- 第二项
|
||||
- 第三项
|
||||
|
||||
### 1.6 有序列表
|
||||
|
||||
```markdown
|
||||
1. 第一步
|
||||
1. 子步骤 1
|
||||
2. 子步骤 2
|
||||
2. 第二步
|
||||
3. 第三步
|
||||
```
|
||||
|
||||
1. 第一步
|
||||
1. 子步骤 1
|
||||
2. 子步骤 2
|
||||
2. 第二步
|
||||
3. 第三步
|
||||
|
||||
### 1.7 任务列表
|
||||
|
||||
```markdown
|
||||
- [x] 已完成任务
|
||||
- [ ] 未完成任务
|
||||
- [x] 又一个已完成任务
|
||||
```
|
||||
|
||||
- [x] 已完成任务
|
||||
- [ ] 未完成任务
|
||||
- [x] 又一个已完成任务
|
||||
|
||||
### 1.8 行内代码
|
||||
|
||||
```markdown
|
||||
这是一段包含`const greeting = "Hello World";`的行内代码
|
||||
```
|
||||
|
||||
这是一段包含`const greeting = "Hello World";`的行内代码
|
||||
|
||||
### 1.9 代码块
|
||||
|
||||
````markdown
|
||||
```typescript
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
function greet(user: User): string {
|
||||
return `Hello, \${user.name}!`;
|
||||
}
|
||||
```
|
||||
````
|
||||
|
||||
```typescript
|
||||
interface User {
|
||||
id: number;
|
||||
name: string;
|
||||
email: string;
|
||||
}
|
||||
|
||||
function greet(user: User): string {
|
||||
return `Hello, \${user.name}!`;
|
||||
}
|
||||
```
|
||||
|
||||
### 1.10 表格
|
||||
|
||||
```markdown
|
||||
| 功能 | 基础版 | 高级版 |
|
||||
|:-----|:------:|-------:|
|
||||
| 文本编辑 | ✓ | ✓ |
|
||||
| 实时预览 | ✗ | ✓ |
|
||||
| 导出格式 | 2种 | 5种 |
|
||||
```
|
||||
|
||||
| 功能 | 基础版 | 高级版 |
|
||||
|:-----|:------:|-------:|
|
||||
| 文本编辑 | ✓ | ✓ |
|
||||
| 实时预览 | ✗ | ✓ |
|
||||
| 导出格式 | 2种 | 5种 |
|
||||
|
||||
### 1.11 引用
|
||||
|
||||
```markdown
|
||||
> 📌 **最佳实践**
|
||||
>
|
||||
> 好的文章需要有清晰的结构和流畅的表达。
|
||||
```
|
||||
|
||||
> 📌 **最佳实践**
|
||||
>
|
||||
> 好的文章需要有清晰的结构和流畅的表达。
|
||||
|
||||
### 1.12 脚注
|
||||
|
||||
```markdown
|
||||
这里有一个脚注[^1]。
|
||||
|
||||
[^1]: 这是脚注的内容。
|
||||
```
|
||||
|
||||
这里有一个脚注[^1]。
|
||||
|
||||
[^1]: 这是脚注的内容。
|
||||
|
||||
### 1.13 表情符号
|
||||
|
||||
```markdown
|
||||
:smile: :heart: :star: :rocket:
|
||||
```
|
||||
|
||||
:smile: :heart: :star: :rocket:
|
||||
|
||||
### 1.14 可折叠内容
|
||||
|
||||
```markdown
|
||||
<details>
|
||||
<summary >
|
||||
🎯 如何选择合适的写作工具?
|
||||
</summary>
|
||||
|
||||
选择写作工具时需要考虑以下几点:
|
||||
|
||||
1. **跨平台支持** - 确保在不同设备上都能访问
|
||||
2. **实时预览** - Markdown 实时渲染很重要
|
||||
3. **版本控制** - 最好能支持文章的版本管理
|
||||
4. **导出功能** - 支持导出为多种格式
|
||||
</details>
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>
|
||||
🎯 如何选择合适的写作工具?
|
||||
</summary>
|
||||
|
||||
选择写作工具时需要考虑以下几点:
|
||||
|
||||
1. **跨平台支持** - 确保在不同设备上都能访问
|
||||
2. **实时预览** - Markdown 实时渲染很重要
|
||||
3. **版本控制** - 最好能支持文章的版本管理
|
||||
4. **导出功能** - 支持导出为多种格式
|
||||
</details>
|
||||
|
||||
### 1.15 引用式
|
||||
|
||||
```markdown
|
||||
> 📌 **最佳实践**
|
||||
>
|
||||
> 好的文章需要有清晰的结构和流畅的表达。以下是一些建议:
|
||||
>
|
||||
> 1. 开门见山,直入主题
|
||||
> 2. 层次分明,逻辑清晰
|
||||
> 3. 语言简洁,表达准确
|
||||
>
|
||||
> *— 写作指南*
|
||||
```
|
||||
|
||||
> 📌 **最佳实践**
|
||||
>
|
||||
> 好的文章需要有清晰的结构和流畅的表达。以下是一些建议:
|
||||
>
|
||||
> 1. 开门见山,直入主题
|
||||
> 2. 层次分明,逻辑清晰
|
||||
> 3. 语言简洁,表达准确
|
||||
>
|
||||
> *— 写作指南*
|
||||
|
||||
|
||||
## 2. HTML排版
|
||||
|
||||
### 2.1 图文混排布局
|
||||
|
||||
```markdown
|
||||
<div class="flex items-center gap-6 my-8">
|
||||
<img src="https://images.unsplash.com/photo-1516116216624-53e697fedbea?w=400&h=400"
|
||||
alt="写作工具"
|
||||
class="w-1/3 rounded-lg shadow-lg" />
|
||||
<div class="flex-1">
|
||||
<h4 class="text-xl font-bold mb-2">高效写作工具</h4>
|
||||
<p>使用合适的写作工具可以极大提升写作效率。推荐使用支持即时预览的编辑器,这样可以实时查看排版效果。</p>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
<div class="flex items-center gap-6 my-8">
|
||||
<img src="https://images.unsplash.com/photo-1516116216624-53e697fedbea?w=400&h=400"
|
||||
alt="写作工具"
|
||||
class="w-1/3 rounded-lg shadow-lg" />
|
||||
<div class="flex-1">
|
||||
<h4 class="text-xl font-bold mb-2">高效写作工具</h4>
|
||||
<p>使用合适的写作工具可以极大提升写作效率。推荐使用支持即时预览的编辑器,这样可以实时查看排版效果。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
### 2.2 并排卡片
|
||||
|
||||
```markdown
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-8">
|
||||
<div class="p-6 bg-gray-100 rounded-lg">
|
||||
<h4 class="text-lg font-bold mb-2">🚀 快速上手</h4>
|
||||
<p>通过简单的标记语法,快速创建格式化的文档,无需复杂的排版工具。</p>
|
||||
</div>
|
||||
<div class="p-6 bg-gray-100 rounded-lg">
|
||||
<h4 class="text-lg font-bold mb-2">⚡ 高效输出</h4>
|
||||
<p>专注于内容创作,让工具自动处理排版,提高写作效率。</p>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
<div class="grid grid-cols-1 md:grid-cols-2 gap-6 my-8">
|
||||
<div class="p-6 bg-gray-100 rounded-lg">
|
||||
<h4 class="text-lg font-bold mb-2">🚀 快速上手</h4>
|
||||
<p>通过简单的标记语法,快速创建格式化的文档,无需复杂的排版工具。</p>
|
||||
</div>
|
||||
<div class="p-6 bg-gray-100 rounded-lg">
|
||||
<h4 class="text-lg font-bold mb-2">⚡ 高效输出</h4>
|
||||
<p>专注于内容创作,让工具自动处理排版,提高写作效率。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
### 2.4 高亮提示框
|
||||
|
||||
```markdown
|
||||
<div class="p-6 bg-blue-50 border-l-4 border-blue-500 rounded-lg my-8">
|
||||
<h4 class="text-lg font-bold text-blue-700 mb-2">💡 小贴士</h4>
|
||||
<p class="text-blue-600">在写作时,可以先列出文章大纲,再逐步充实内容。这可以保证文章结构清晰,内容完整。</p>
|
||||
</div>
|
||||
```
|
||||
|
||||
<div class="p-6 bg-blue-50 border-l-4 border-blue-500 rounded-lg my-8">
|
||||
<h4 class="text-lg font-bold text-blue-700 mb-2">小贴士</h4>
|
||||
<p class="text-blue-600">在写作时,可以先列出文章大纲,再逐步充实内容。这样可以保证文章结构清晰,内容完整。</p>
|
||||
</div>
|
||||
|
||||
### 2.5 时间线
|
||||
|
||||
```markdown
|
||||
<div class="relative pl-8 my-8 border-l-2 border-gray-200">
|
||||
<div class="mb-8 relative">
|
||||
<div class="absolute -left-10 w-4 h-4 bg-blue-500 rounded-full"></div>
|
||||
<div class="font-bold mb-2">1. 确定主题</div>
|
||||
<p>根据目标受众和写作目的,确定文章主题。</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-8 relative">
|
||||
<div class="absolute -left-10 w-4 h-4 bg-blue-500 rounded-full"></div>
|
||||
<div class="font-bold mb-2">2. 收集资料</div>
|
||||
<p>广泛搜集相关资料,为写作做充实准备。</p>
|
||||
</div>
|
||||
</div>
|
||||
```
|
||||
|
||||
<div class="relative pl-8 my-8 border-l-2 border-gray-200">
|
||||
<div class="mb-8 relative">
|
||||
<div class="absolute -left-10 w-4 h-4 bg-blue-500 rounded-full"></div>
|
||||
<div class="font-bold mb-2">1. 确定主题</div>
|
||||
<p>根据目标受众和写作目的,确定文章主题。</p>
|
||||
</div>
|
||||
|
||||
<div class="mb-8 relative">
|
||||
<div class="absolute -left-10 w-4 h-4 bg-blue-500 rounded-full"></div>
|
||||
<div class="font-bold mb-2">2. 收集资料</div>
|
||||
<p>广泛搜集相关资料,为写作做充实准备。</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
## 3. 总结
|
||||
|
||||
本文展示了 Markdown 从基础到高级的各种用法:
|
||||
|
||||
1. 基础语法:文本格式化、列表、代码、表格等
|
||||
2. 高级排版:图文混排、叠面板、卡片布局等
|
||||
3. 特殊语法:数学公式、脚注、表情符号等
|
||||
|
||||
> 💡 **提示**:部分高级排版功能可能需要特定的 Markdown 编辑器或渲染支持,请确认是否支持这些功能。
|
108
src/content/astro-introduction.md
Normal file
108
src/content/astro-introduction.md
Normal file
@ -0,0 +1,108 @@
|
||||
---
|
||||
title: Astro 框架介绍
|
||||
date: 2023-07-20
|
||||
tags: [Astro, 前端, Web开发]
|
||||
category: 技术
|
||||
summary: Astro 是一个现代的静态站点生成器,专注于内容驱动的网站,本文将介绍其基本特性和使用方法。
|
||||
---
|
||||
|
||||
# Astro 框架介绍
|
||||
|
||||
[Astro](https://astro.build/) 是一个现代的静态站点生成器,专注于内容驱动的网站。它允许开发者使用他们喜欢的 UI 组件框架(如 React、Vue、Svelte 等),同时生成快速、优化的静态 HTML。
|
||||
|
||||
## Astro 的主要特点
|
||||
|
||||
### 1. 零 JavaScript 默认
|
||||
|
||||
Astro 默认不会向客户端发送任何 JavaScript。这意味着您的网站将以闪电般的速度加载,因为浏览器不需要下载、解析和执行 JavaScript 代码。
|
||||
|
||||
### 2. 组件岛屿架构
|
||||
|
||||
Astro 引入了"组件岛屿"的概念,允许您在需要交互性的地方选择性地使用 JavaScript。这种方法确保了最佳的性能,同时仍然提供了丰富的用户体验。
|
||||
|
||||
```astro
|
||||
---
|
||||
import ReactCounter from '../components/ReactCounter.jsx';
|
||||
import VueCounter from '../components/VueCounter.vue';
|
||||
import SvelteCounter from '../components/SvelteCounter.svelte';
|
||||
---
|
||||
|
||||
<!-- 这些组件将在客户端激活(水合) -->
|
||||
<ReactCounter client:load />
|
||||
<VueCounter client:visible />
|
||||
<SvelteCounter client:idle />
|
||||
```
|
||||
|
||||
### 3. 多框架支持
|
||||
|
||||
Astro 允许您在同一个项目中使用多种 UI 框架,如 React、Vue、Svelte、Solid 等。这意味着您可以使用最适合特定任务的工具,而不必被单一框架所限制。
|
||||
|
||||
### 4. 内置优化
|
||||
|
||||
Astro 自动优化您的网站,包括:
|
||||
|
||||
- 代码分割
|
||||
- CSS 优化
|
||||
- 图像优化
|
||||
- 预渲染
|
||||
- 延迟加载
|
||||
|
||||
## 基本使用
|
||||
|
||||
### 安装
|
||||
|
||||
使用以下命令创建一个新的 Astro 项目:
|
||||
|
||||
```bash
|
||||
# 使用 npm
|
||||
npm create astro@latest
|
||||
|
||||
# 使用 yarn
|
||||
yarn create astro
|
||||
|
||||
# 使用 pnpm
|
||||
pnpm create astro@latest
|
||||
```
|
||||
|
||||
### 项目结构
|
||||
|
||||
一个基本的 Astro 项目结构如下:
|
||||
|
||||
```
|
||||
/
|
||||
├── public/
|
||||
│ └── favicon.svg
|
||||
├── src/
|
||||
│ ├── components/
|
||||
│ │ └── Card.astro
|
||||
│ ├── layouts/
|
||||
│ │ └── Layout.astro
|
||||
│ └── pages/
|
||||
│ └── index.astro
|
||||
└── package.json
|
||||
```
|
||||
|
||||
### 创建页面
|
||||
|
||||
在 Astro 中,`src/pages/` 目录中的每个 `.astro` 文件都会生成一个对应的 HTML 页面:
|
||||
|
||||
```astro
|
||||
---
|
||||
// src/pages/index.astro
|
||||
---
|
||||
|
||||
<html>
|
||||
<head>
|
||||
<title>我的 Astro 网站</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>欢迎来到我的网站!</h1>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## 结语
|
||||
|
||||
Astro 是一个强大而灵活的框架,特别适合内容驱动的网站,如博客、文档站点、营销网站等。它的零 JavaScript 默认策略和组件岛屿架构使其成为构建高性能网站的绝佳选择。
|
||||
|
||||
如果您正在寻找一个能够提供出色开发体验和最终用户体验的框架,Astro 绝对值得一试!
|
19
src/content/h/a.md
Normal file
19
src/content/h/a.md
Normal file
@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "测试文章"
|
||||
date: 2023-03-03
|
||||
tags: ["测试"]
|
||||
category: "测试分类"
|
||||
summary: "这是一篇测试文章,用于测试目录结构"
|
||||
---
|
||||
|
||||
# 测试文章
|
||||
|
||||
这是一篇测试文章,用于测试目录结构功能。
|
||||
|
||||
## 二级标题
|
||||
|
||||
这是二级标题下的内容。
|
||||
|
||||
### 三级标题
|
||||
|
||||
这是三级标题下的内容。
|
79
src/content/hello-world.md
Normal file
79
src/content/hello-world.md
Normal file
@ -0,0 +1,79 @@
|
||||
---
|
||||
title: Hello World
|
||||
date: 2023-06-15
|
||||
tags: [示例, Markdown, 入门]
|
||||
category: 教程
|
||||
summary: 这是一篇示例文章,展示了 Markdown 的基本语法和使用方法。
|
||||
---
|
||||
|
||||
# Hello World
|
||||
|
||||
这是一篇示例文章,用于展示 Markdown 的基本语法和使用方法。
|
||||
|
||||
## Markdown 简介
|
||||
|
||||
Markdown 是一种轻量级标记语言,创建于 2004 年,其设计目标是易读易写,成为一种适用于网络的书写语言。Markdown 的语法简洁明了,易于掌握,目前被广泛用于撰写博客、文档、笔记等。
|
||||
|
||||
## 基本语法
|
||||
|
||||
### 标题
|
||||
|
||||
使用 `#` 号可以表示不同级别的标题,例如:
|
||||
|
||||
```markdown
|
||||
# 一级标题
|
||||
## 二级标题
|
||||
### 三级标题
|
||||
```
|
||||
|
||||
### 强调
|
||||
|
||||
使用星号或下划线可以强调文本:
|
||||
|
||||
*斜体* 或 _斜体_
|
||||
**粗体** 或 __粗体__
|
||||
***粗斜体*** 或 ___粗斜体___
|
||||
|
||||
### 列表
|
||||
|
||||
无序列表使用星号、加号或减号作为列表标记:
|
||||
|
||||
* 项目一
|
||||
* 项目二
|
||||
* 项目三
|
||||
|
||||
有序列表使用数字加点:
|
||||
|
||||
1. 第一项
|
||||
2. 第二项
|
||||
3. 第三项
|
||||
|
||||
### 链接
|
||||
|
||||
[链接文本](https://www.example.com)
|
||||
|
||||
### 图片
|
||||
|
||||

|
||||
|
||||
### 引用
|
||||
|
||||
> 这是一段引用文本。
|
||||
>
|
||||
> 引用可以有多个段落。
|
||||
|
||||
### 代码
|
||||
|
||||
行内代码使用反引号:`console.log('Hello World')`
|
||||
|
||||
代码块使用三个反引号:
|
||||
|
||||
```javascript
|
||||
function sayHello() {
|
||||
console.log('Hello World');
|
||||
}
|
||||
```
|
||||
|
||||
## 结语
|
||||
|
||||
Markdown 的语法非常简单,但功能强大,希望这篇文章能帮助您快速入门 Markdown。更多高级用法,请参考 [Markdown 官方文档](https://daringfireball.net/projects/markdown/)。
|
@ -1,22 +0,0 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<meta name="generator" content={Astro.generator} />
|
||||
<title>Astro Basics</title>
|
||||
</head>
|
||||
<body>
|
||||
<slot />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
<style>
|
||||
html,
|
||||
body {
|
||||
margin: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
155
src/pages/api/articles.ts
Normal file
155
src/pages/api/articles.ts
Normal file
@ -0,0 +1,155 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { getCollection } from 'astro:content';
|
||||
import { contentStructure } from '../../content.config';
|
||||
import type { SectionStructure } from '../../content.config';
|
||||
|
||||
export const GET: APIRoute = async ({ request }) => {
|
||||
// 获取查询参数
|
||||
const url = new URL(request.url);
|
||||
const page = parseInt(url.searchParams.get('page') || '1');
|
||||
const limit = parseInt(url.searchParams.get('limit') || '10');
|
||||
const tag = url.searchParams.get('tag') || '';
|
||||
const path = url.searchParams.get('path') || '';
|
||||
|
||||
// 获取所有文章
|
||||
const articles = await getCollection('articles');
|
||||
|
||||
// 根据条件过滤文章
|
||||
let filteredArticles = articles;
|
||||
|
||||
// 如果有标签过滤
|
||||
if (tag) {
|
||||
filteredArticles = filteredArticles.filter(article =>
|
||||
article.data.tags && article.data.tags.includes(tag)
|
||||
);
|
||||
}
|
||||
|
||||
// 如果有路径过滤,需要从contentStructure中查找对应目录下的文章
|
||||
if (path) {
|
||||
// 解析路径
|
||||
const pathSegments = path.split('/').filter(segment => segment.trim() !== '');
|
||||
|
||||
// 递归查找目录
|
||||
const findArticlesInPath = (sections: SectionStructure[], currentPath = ''): string[] => {
|
||||
for (const section of sections) {
|
||||
const sectionPath = currentPath ? `${currentPath}/${section.name}` : section.name;
|
||||
|
||||
// 如果找到匹配的目录
|
||||
if (sectionPath === path) {
|
||||
return section.articles;
|
||||
}
|
||||
|
||||
// 递归查找子目录
|
||||
const articlesInSubsection = findArticlesInPath(section.sections, sectionPath);
|
||||
if (articlesInSubsection.length > 0) {
|
||||
return articlesInSubsection;
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
};
|
||||
|
||||
// 获取目录下的文章路径
|
||||
const articlePaths = findArticlesInPath(contentStructure.sections);
|
||||
|
||||
// 根据路径过滤文章
|
||||
if (articlePaths.length > 0) {
|
||||
filteredArticles = filteredArticles.filter(article => {
|
||||
// 检查文章ID是否在目录的文章列表中
|
||||
return articlePaths.some(articlePath => {
|
||||
const articleId = article.id;
|
||||
const pathParts = articlePath.split('/');
|
||||
const fileName = pathParts[pathParts.length - 1];
|
||||
|
||||
// 尝试多种匹配方式
|
||||
return (
|
||||
articlePath.includes(articleId) ||
|
||||
articleId.includes(fileName) ||
|
||||
fileName.includes(articleId)
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 按日期排序(最新的在前面)
|
||||
const sortedArticles = filteredArticles.sort(
|
||||
(a, b) => b.data.date.getTime() - a.data.date.getTime()
|
||||
);
|
||||
|
||||
// 计算分页
|
||||
const startIndex = (page - 1) * limit;
|
||||
const endIndex = startIndex + limit;
|
||||
const paginatedArticles = sortedArticles.slice(startIndex, endIndex);
|
||||
|
||||
// 格式化文章数据,只返回需要的字段
|
||||
const formattedArticles = paginatedArticles.map(article => {
|
||||
// 查找文章所属的目录
|
||||
let section = '';
|
||||
|
||||
// 递归查找文章所属的目录
|
||||
const findSection = (sections: SectionStructure[], articleId: string, parentPath = ''): string | null => {
|
||||
for (const sec of sections) {
|
||||
const sectionPath = parentPath ? `${parentPath}/${sec.name}` : sec.name;
|
||||
|
||||
// 检查文章是否在当前目录中
|
||||
for (const artPath of sec.articles) {
|
||||
const pathParts = artPath.split('/');
|
||||
const fileName = pathParts[pathParts.length - 1];
|
||||
|
||||
// 尝试多种匹配方式
|
||||
if (
|
||||
artPath.includes(articleId) ||
|
||||
articleId.includes(fileName) ||
|
||||
fileName.includes(articleId)
|
||||
) {
|
||||
return sectionPath;
|
||||
}
|
||||
}
|
||||
|
||||
// 递归检查子目录
|
||||
const foundInSubsection = findSection(sec.sections, articleId, sectionPath);
|
||||
if (foundInSubsection) {
|
||||
return foundInSubsection;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
section = findSection(contentStructure.sections, article.id) || '';
|
||||
|
||||
return {
|
||||
id: article.id,
|
||||
title: article.data.title,
|
||||
date: article.data.date.toISOString(),
|
||||
summary: article.data.summary || '',
|
||||
tags: article.data.tags || [],
|
||||
section: section
|
||||
};
|
||||
});
|
||||
|
||||
// 构建分页信息
|
||||
const pagination = {
|
||||
total: sortedArticles.length,
|
||||
current: page,
|
||||
limit: limit,
|
||||
hasNext: endIndex < sortedArticles.length,
|
||||
hasPrev: page > 1,
|
||||
totalPages: Math.ceil(sortedArticles.length / limit)
|
||||
};
|
||||
|
||||
// 返回JSON响应
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
articles: formattedArticles,
|
||||
pagination: pagination
|
||||
}),
|
||||
{
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
124
src/pages/api/douban.ts
Normal file
124
src/pages/api/douban.ts
Normal file
@ -0,0 +1,124 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { load } from 'cheerio';
|
||||
import { DOUBAN_ID } from '@/consts';
|
||||
|
||||
// 添加服务器渲染标记
|
||||
export const prerender = false;
|
||||
|
||||
export const GET: APIRoute = async ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
const type = url.searchParams.get('type') || 'movie';
|
||||
const start = parseInt(url.searchParams.get('start') || '0');
|
||||
|
||||
try {
|
||||
let doubanUrl = '';
|
||||
if (type === 'book') {
|
||||
doubanUrl = `https://book.douban.com/people/${DOUBAN_ID}/collect?start=${start}&sort=time&rating=all&filter=all&mode=grid`;
|
||||
} else {
|
||||
doubanUrl = `https://movie.douban.com/people/${DOUBAN_ID}/collect?start=${start}&sort=time&rating=all&filter=all&mode=grid`;
|
||||
}
|
||||
|
||||
const response = await fetch(doubanUrl, {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
|
||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
|
||||
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
|
||||
'Referer': 'https://movie.douban.com/'
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
return new Response(JSON.stringify({ error: '获取豆瓣数据失败' }), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const html = await response.text();
|
||||
const $ = load(html);
|
||||
|
||||
// 添加类型定义
|
||||
interface DoubanItem {
|
||||
imageUrl: string;
|
||||
title: string;
|
||||
subtitle: string;
|
||||
link: string;
|
||||
intro: string;
|
||||
rating: number;
|
||||
date: string;
|
||||
}
|
||||
|
||||
const items: DoubanItem[] = [];
|
||||
$('.item.comment-item').each((_, element) => {
|
||||
const $element = $(element);
|
||||
|
||||
const imageUrl = $element.find('.pic img').attr('src') || '';
|
||||
const title = $element.find('.title a em').text().trim();
|
||||
const subtitle = $element.find('.title a').text().replace(title, '').trim();
|
||||
const link = $element.find('.title a').attr('href') || '';
|
||||
const intro = $element.find('.intro').text().trim();
|
||||
|
||||
// 获取评分,从rating1-t到rating5-t
|
||||
let rating = 0;
|
||||
for (let i = 1; i <= 5; i++) {
|
||||
if ($element.find(`.rating${i}-t`).length > 0) {
|
||||
rating = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const date = $element.find('.date').text().trim();
|
||||
|
||||
items.push({
|
||||
imageUrl,
|
||||
title,
|
||||
subtitle,
|
||||
link,
|
||||
intro,
|
||||
rating,
|
||||
date
|
||||
});
|
||||
});
|
||||
|
||||
// 改进分页信息获取逻辑
|
||||
let currentPage = 1;
|
||||
let totalPages = 1;
|
||||
|
||||
// 尝试从当前页码元素获取信息
|
||||
if ($('.paginator .thispage').length > 0) {
|
||||
currentPage = parseInt($('.paginator .thispage').text() || '1');
|
||||
// 豆瓣可能不直接提供总页数,需要计算
|
||||
const paginatorLinks = $('.paginator a');
|
||||
let maxPage = currentPage;
|
||||
paginatorLinks.each((_, el) => {
|
||||
const pageNum = parseInt($(el).text());
|
||||
if (!isNaN(pageNum) && pageNum > maxPage) {
|
||||
maxPage = pageNum;
|
||||
}
|
||||
});
|
||||
totalPages = maxPage;
|
||||
}
|
||||
|
||||
const pagination = {
|
||||
current: currentPage,
|
||||
total: totalPages,
|
||||
hasNext: $('.paginator .next a').length > 0,
|
||||
hasPrev: $('.paginator .prev a').length > 0
|
||||
};
|
||||
|
||||
return new Response(JSON.stringify({ items, pagination }), {
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
return new Response(JSON.stringify({ error: '获取豆瓣数据失败' }), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
349
src/pages/api/git-projects.ts
Normal file
349
src/pages/api/git-projects.ts
Normal file
@ -0,0 +1,349 @@
|
||||
import type { APIRoute } from 'astro';
|
||||
import { Octokit } from 'octokit';
|
||||
import fetch from 'node-fetch';
|
||||
import { GIT_CONFIG } from '@/consts';
|
||||
import { GitPlatform, GIT_PLATFORM_CONFIG } from '@/components/GitProjectCollection';
|
||||
|
||||
interface GitProject {
|
||||
name: string;
|
||||
description: string;
|
||||
url: string;
|
||||
stars: number;
|
||||
forks: number;
|
||||
language: string;
|
||||
updatedAt: string;
|
||||
owner: string;
|
||||
avatarUrl: string;
|
||||
platform: GitPlatform;
|
||||
}
|
||||
|
||||
interface Pagination {
|
||||
current: number;
|
||||
total: number;
|
||||
hasNext: boolean;
|
||||
hasPrev: boolean;
|
||||
}
|
||||
|
||||
export const GET: APIRoute = async ({ request }) => {
|
||||
const url = new URL(request.url);
|
||||
const platformParam = url.searchParams.get('platform') || 'github';
|
||||
const platform = platformParam as GitPlatform;
|
||||
const page = parseInt(url.searchParams.get('page') || '1');
|
||||
const username = url.searchParams.get('username') || '';
|
||||
const organization = url.searchParams.get('organization') || '';
|
||||
|
||||
try {
|
||||
let projects: GitProject[] = [];
|
||||
let pagination: Pagination = { current: page, total: 1, hasNext: false, hasPrev: page > 1 };
|
||||
|
||||
if (platform === GitPlatform.GITHUB) {
|
||||
const result = await fetchGithubProjects(username, organization, page);
|
||||
projects = result.projects;
|
||||
pagination = result.pagination;
|
||||
} else if (platform === GitPlatform.GITEA) {
|
||||
const result = await fetchGiteaProjects(username, organization, page);
|
||||
projects = result.projects;
|
||||
pagination = result.pagination;
|
||||
} else if (platform === GitPlatform.GITEE) {
|
||||
try {
|
||||
const result = await fetchGiteeProjects(username, organization, page);
|
||||
projects = result.projects;
|
||||
pagination = result.pagination;
|
||||
} catch (giteeError) {
|
||||
// 返回空数据而不是抛出错误
|
||||
}
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({ projects, pagination }), {
|
||||
status: 200,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
let errorMessage = '获取数据失败';
|
||||
if (error instanceof Error) {
|
||||
errorMessage = error.message;
|
||||
}
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
error: errorMessage,
|
||||
platform
|
||||
}), {
|
||||
status: 500,
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
async function fetchGithubProjects(username: string, organization: string, page: number) {
|
||||
// 添加重试逻辑
|
||||
const maxRetries = 3;
|
||||
let retryCount = 0;
|
||||
|
||||
while (retryCount < maxRetries) {
|
||||
try {
|
||||
const octokit = new Octokit({
|
||||
auth: GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITHUB].token || process.env.GITHUB_TOKEN,
|
||||
request: {
|
||||
timeout: 10000 // 增加超时时间到10秒
|
||||
}
|
||||
});
|
||||
|
||||
const perPage = GIT_CONFIG.perPage;
|
||||
let repos;
|
||||
|
||||
if (organization) {
|
||||
const { data } = await octokit.request('GET /orgs/{org}/repos', {
|
||||
org: organization,
|
||||
per_page: perPage,
|
||||
page: page,
|
||||
sort: 'updated',
|
||||
direction: 'desc'
|
||||
});
|
||||
repos = data;
|
||||
} else if (username) {
|
||||
const { data } = await octokit.request('GET /users/{username}/repos', {
|
||||
username: username,
|
||||
per_page: perPage,
|
||||
page: page,
|
||||
sort: 'updated',
|
||||
direction: 'desc'
|
||||
});
|
||||
repos = data;
|
||||
} else {
|
||||
// 如果没有指定用户或组织,使用默认用户名
|
||||
const defaultUsername = GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITHUB].username;
|
||||
const { data } = await octokit.request('GET /users/{username}/repos', {
|
||||
username: defaultUsername,
|
||||
per_page: perPage,
|
||||
page: page,
|
||||
sort: 'updated',
|
||||
direction: 'desc'
|
||||
});
|
||||
repos = data;
|
||||
}
|
||||
|
||||
// 替换获取分页信息的代码
|
||||
let hasNext = false;
|
||||
let hasPrev = page > 1;
|
||||
let totalPages = 1;
|
||||
|
||||
// 使用响应头中的 Link 信息
|
||||
if (repos.length === perPage) {
|
||||
hasNext = true;
|
||||
totalPages = page + 1;
|
||||
}
|
||||
|
||||
// 或者使用 GitHub API 的 repository_count 估算
|
||||
if (repos.length > 0 && repos[0].owner) {
|
||||
// 简单估算:如果有结果且等于每页数量,则可能有下一页
|
||||
hasNext = repos.length === perPage;
|
||||
totalPages = hasNext ? page + 1 : page;
|
||||
}
|
||||
|
||||
const projects = repos.map((repo: any) => ({
|
||||
name: repo.name,
|
||||
description: repo.description,
|
||||
url: repo.html_url,
|
||||
stars: repo.stargazers_count,
|
||||
forks: repo.forks_count,
|
||||
language: repo.language,
|
||||
updatedAt: repo.updated_at,
|
||||
owner: repo.owner.login,
|
||||
avatarUrl: repo.owner.avatar_url,
|
||||
platform: GitPlatform.GITHUB
|
||||
}));
|
||||
|
||||
return {
|
||||
projects,
|
||||
pagination: {
|
||||
current: page,
|
||||
total: totalPages,
|
||||
hasNext,
|
||||
hasPrev
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
retryCount++;
|
||||
|
||||
if (retryCount >= maxRetries) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
// 等待一段时间后重试
|
||||
await new Promise(resolve => setTimeout(resolve, 2000 * retryCount));
|
||||
}
|
||||
}
|
||||
|
||||
// 添加默认返回值,防止 undefined
|
||||
return {
|
||||
projects: [],
|
||||
pagination: {
|
||||
current: page,
|
||||
total: 1,
|
||||
hasNext: false,
|
||||
hasPrev: page > 1
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
async function fetchGiteaProjects(username: string, organization: string, page: number) {
|
||||
try {
|
||||
// 使用consts中的配置
|
||||
const perPage = GIT_CONFIG.perPage;
|
||||
const platformConfig = GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITEA];
|
||||
|
||||
if (!platformConfig) {
|
||||
throw new Error('Gitea 平台配置不存在');
|
||||
}
|
||||
|
||||
const giteaUrl = platformConfig.url;
|
||||
|
||||
if (!giteaUrl) {
|
||||
throw new Error('Gitea URL 不存在');
|
||||
}
|
||||
|
||||
let apiUrl;
|
||||
if (organization) {
|
||||
apiUrl = `${giteaUrl}/api/v1/orgs/${organization}/repos?page=${page}&per_page=${perPage}`;
|
||||
} else if (username) {
|
||||
apiUrl = `${giteaUrl}/api/v1/users/${username}/repos?page=${page}&per_page=${perPage}`;
|
||||
} else {
|
||||
const defaultUsername = GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITEA].username;
|
||||
apiUrl = `${giteaUrl}/api/v1/users/${defaultUsername}/repos?page=${page}&per_page=${perPage}`;
|
||||
}
|
||||
|
||||
const response = await fetch(apiUrl, {
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
...(GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITEA].token ?
|
||||
{ 'Authorization': `token ${GIT_PLATFORM_CONFIG.platforms[GitPlatform.GITEA].token}` } :
|
||||
{})
|
||||
}
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Gitea API 请求失败: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as any;
|
||||
|
||||
// Gitea API 返回的是数组
|
||||
const repos = Array.isArray(data) ? data : [];
|
||||
|
||||
// 获取分页信息
|
||||
const totalCount = parseInt(response.headers.get('X-Total-Count') || '0');
|
||||
const totalPages = Math.ceil(totalCount / perPage) || 1;
|
||||
|
||||
const projects = repos.map((repo: any) => ({
|
||||
name: repo.name,
|
||||
description: repo.description || '',
|
||||
url: repo.html_url || `${giteaUrl}/${repo.full_name || `${repo.owner.username || repo.owner.login}/${repo.name}`}`,
|
||||
stars: repo.stars_count || repo.stargazers_count || 0,
|
||||
forks: repo.forks_count || 0,
|
||||
language: repo.language || '',
|
||||
updatedAt: repo.updated_at,
|
||||
owner: repo.owner.username || repo.owner.login,
|
||||
avatarUrl: repo.owner.avatar_url,
|
||||
platform: GitPlatform.GITEA
|
||||
}));
|
||||
|
||||
return {
|
||||
projects,
|
||||
pagination: {
|
||||
current: page,
|
||||
total: totalPages,
|
||||
hasNext: page < totalPages,
|
||||
hasPrev: page > 1
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
// 返回空数据而不是抛出错误
|
||||
return {
|
||||
projects: [],
|
||||
pagination: {
|
||||
current: page,
|
||||
total: 1,
|
||||
hasNext: false,
|
||||
hasPrev: page > 1
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchGiteeProjects(username: string, organization: string, page: number) {
|
||||
try {
|
||||
// 使用consts中的配置
|
||||
const perPage = GIT_CONFIG.perPage;
|
||||
|
||||
// 确定用户名
|
||||
const giteeUsername = username || GIT_CONFIG.gitee.username;
|
||||
|
||||
if (!giteeUsername) {
|
||||
throw new Error('Gitee 用户名未配置');
|
||||
}
|
||||
|
||||
// 构建API URL
|
||||
let apiUrl;
|
||||
if (organization) {
|
||||
apiUrl = `https://gitee.com/api/v5/orgs/${organization}/repos?page=${page}&per_page=${perPage}&sort=updated&direction=desc`;
|
||||
} else {
|
||||
apiUrl = `https://gitee.com/api/v5/users/${giteeUsername}/repos?page=${page}&per_page=${perPage}&sort=updated&direction=desc`;
|
||||
}
|
||||
|
||||
// 添加访问令牌(如果有)
|
||||
if (GIT_CONFIG.gitee.token) {
|
||||
apiUrl += `&access_token=${GIT_CONFIG.gitee.token}`;
|
||||
}
|
||||
|
||||
const response = await fetch(apiUrl);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Gitee API 请求失败: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json() as any[];
|
||||
|
||||
// 转换数据格式
|
||||
const projects: GitProject[] = data.map(repo => ({
|
||||
name: repo.name || '',
|
||||
description: repo.description || '',
|
||||
url: repo.html_url || '',
|
||||
stars: repo.stargazers_count || 0,
|
||||
forks: repo.forks_count || 0,
|
||||
language: repo.language || '',
|
||||
updatedAt: repo.updated_at || '',
|
||||
owner: repo.owner?.login || '',
|
||||
avatarUrl: repo.owner?.avatar_url || '',
|
||||
platform: GitPlatform.GITEE
|
||||
}));
|
||||
|
||||
// 获取分页信息
|
||||
const totalCount = parseInt(response.headers.get('total_count') || '0');
|
||||
const totalPages = Math.ceil(totalCount / perPage) || 1;
|
||||
|
||||
return {
|
||||
projects,
|
||||
pagination: {
|
||||
current: page,
|
||||
total: totalPages,
|
||||
hasNext: page < totalPages,
|
||||
hasPrev: page > 1
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
// 返回空结果
|
||||
return {
|
||||
projects: [],
|
||||
pagination: {
|
||||
current: page,
|
||||
total: 1,
|
||||
hasNext: false,
|
||||
hasPrev: page > 1
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
322
src/pages/articles/[...id].astro
Normal file
322
src/pages/articles/[...id].astro
Normal file
@ -0,0 +1,322 @@
|
||||
---
|
||||
import { getCollection, render } from 'astro:content';
|
||||
import { contentStructure, getRelativePath, getBasename, getDirPath } from '../../content.config';
|
||||
import type { SectionStructure } from '../../content.config';
|
||||
import Layout from '../../components/Layout.astro';
|
||||
import Breadcrumb from '../../components/Breadcrumb.astro';
|
||||
|
||||
// 添加这一行,告诉Astro预渲染这个页面
|
||||
export const prerender = true;
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const articles = await getCollection('articles');
|
||||
|
||||
// 为每篇文章添加section信息
|
||||
const articlesWithSections = articles.map(article => {
|
||||
// 查找文章所属的目录
|
||||
let section = '';
|
||||
const findSection = (sections: SectionStructure[], articleId: string, parentPath = ''): string | null => {
|
||||
for (const sec of sections) {
|
||||
const sectionPath = parentPath ? `${parentPath}/${sec.name}` : sec.name;
|
||||
|
||||
// 检查文章是否在当前目录中
|
||||
for (const artPath of sec.articles) {
|
||||
const artId = getRelativePath(artPath);
|
||||
const basename = getBasename(artPath);
|
||||
const dirPath = getDirPath(artPath);
|
||||
|
||||
// 尝试多种可能的ID格式
|
||||
const possibleIds = [
|
||||
artId, // 完整相对路径
|
||||
`${sectionPath}/${basename}`, // 目录路径/文件名
|
||||
basename, // 仅文件名
|
||||
dirPath ? `${dirPath}/${basename}` : basename, // 目录路径/文件名
|
||||
`articles/${artId}`, // 添加集合名称前缀
|
||||
`articles/${sectionPath}/${basename}` // 添加集合名称前缀和目录路径
|
||||
];
|
||||
|
||||
// 精确匹配
|
||||
if (possibleIds.includes(articleId)) {
|
||||
return sectionPath;
|
||||
}
|
||||
|
||||
// 检查文章ID是否以某个可能的ID结尾
|
||||
for (const possibleId of possibleIds) {
|
||||
if (articleId.endsWith(possibleId)) {
|
||||
return sectionPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 递归检查子目录
|
||||
const foundInSubsection = findSection(sec.sections, articleId, sectionPath);
|
||||
if (foundInSubsection) {
|
||||
return foundInSubsection;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
section = findSection(contentStructure.sections, article.id) || '';
|
||||
|
||||
return {
|
||||
...article,
|
||||
section
|
||||
};
|
||||
});
|
||||
|
||||
return articlesWithSections.map(article => {
|
||||
return {
|
||||
params: { id: article.id },
|
||||
props: { article, section: article.section }
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
// 获取文章内容
|
||||
const { article, section } = Astro.props;
|
||||
|
||||
// 渲染文章内容
|
||||
const { Content } = await render(article);
|
||||
|
||||
// 获取面包屑导航
|
||||
const breadcrumbs = section ? section.split('/') : [];
|
||||
|
||||
// 获取相关文章
|
||||
const allArticles = await getCollection('articles');
|
||||
const relatedArticles = allArticles
|
||||
.filter(a => a.id !== article.id && (
|
||||
(a.data.tags && article.data.tags && a.data.tags.some(tag => article.data.tags?.includes(tag)))
|
||||
))
|
||||
.sort((a, b) => b.data.date.getTime() - a.data.date.getTime())
|
||||
.slice(0, 3);
|
||||
---
|
||||
|
||||
<Layout>
|
||||
<div class="bg-gradient-to-b from-primary-50 dark:from-dark-surface to-white dark:to-dark-bg min-h-screen">
|
||||
<div class="max-w-4xl mx-auto px-4 py-8">
|
||||
<!-- 阅读进度条 -->
|
||||
<div class="fixed top-0 left-0 w-full h-1 bg-transparent z-50" id="progress-container">
|
||||
<div class="h-full w-0 bg-primary-500 transition-width duration-100" id="progress-bar"></div>
|
||||
</div>
|
||||
|
||||
<!-- 文章头部 -->
|
||||
<header class="mb-8">
|
||||
<!-- 导航区域 -->
|
||||
<div class="bg-white dark:bg-dark-card rounded-xl p-4 mb-6">
|
||||
<div class="flex items-center justify-between">
|
||||
<Breadcrumb
|
||||
pageType="article"
|
||||
pathSegments={breadcrumbs}
|
||||
articleTitle={article.data.title}
|
||||
/>
|
||||
|
||||
{/* 返回按钮 */}
|
||||
<a href="/articles" class="text-secondary-500 dark:text-secondary-400 hover:text-primary-600 dark:hover:text-primary-400 transition-colors flex items-center text-sm">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
|
||||
</svg>
|
||||
返回文章列表
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h1 class="text-3xl font-bold mb-4 text-gray-900 dark:text-gray-100">{article.data.title}</h1>
|
||||
|
||||
<div class="flex flex-wrap items-center gap-4 text-sm text-secondary-600 dark:text-secondary-400 mb-4">
|
||||
<time datetime={article.data.date.toISOString()} class="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z" />
|
||||
</svg>
|
||||
{article.data.date.toLocaleDateString('zh-CN')}
|
||||
</time>
|
||||
|
||||
{/* 显示文章所在目录 */}
|
||||
{section && (
|
||||
<span class="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
|
||||
</svg>
|
||||
<a href={`/articles?path=${encodeURIComponent(section)}`} class="hover:text-indigo-600 transition-colors">
|
||||
{section}
|
||||
</a>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{article.data.tags && article.data.tags.length > 0 && (
|
||||
<div class="flex flex-wrap gap-2 mb-6">
|
||||
{article.data.tags.map(tag => (
|
||||
<a href={`/articles?tag=${tag}`} class="text-xs bg-primary-50 dark:bg-primary-900/30 text-primary-600 dark:text-primary-400 py-1 px-2 rounded hover:bg-primary-100 dark:hover:bg-primary-800/30 transition-colors">
|
||||
#{tag}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{article.data.summary && (
|
||||
<div class="bg-primary-50 dark:bg-primary-900/30 p-4 rounded-lg mb-6 text-secondary-700 dark:text-secondary-300 italic">
|
||||
{article.data.summary}
|
||||
</div>
|
||||
)}
|
||||
</header>
|
||||
|
||||
<!-- 文章内容 -->
|
||||
<article class="prose prose-lg dark:prose-invert prose-primary prose-table:rounded-lg prose-thead:bg-secondary-50 dark:prose-thead:bg-dark-card prose-ul:list-disc prose-ol:list-decimal prose-li:my-1 max-w-none mb-12 bg-white dark:bg-dark-card p-8 rounded-xl">
|
||||
<Content />
|
||||
</article>
|
||||
|
||||
<!-- 相关文章 -->
|
||||
{relatedArticles.length > 0 && (
|
||||
<div class="mt-12 pt-8 border-t border-secondary-200 dark:border-dark-border">
|
||||
<h2 class="text-2xl font-bold mb-6 text-primary-900 dark:text-primary-100">相关文章</h2>
|
||||
<div class="grid grid-cols-1 md:grid-cols-3 gap-6">
|
||||
{relatedArticles.map(relatedArticle => (
|
||||
<a href={`/articles/${relatedArticle.id}`} class="block p-4 border border-primary-100 dark:border-dark-border rounded-lg bg-white dark:bg-dark-card hover:shadow-md transition-shadow">
|
||||
<h3 class="font-bold text-lg mb-2 line-clamp-2 text-gray-800 dark:text-gray-200 hover:text-primary-700 dark:hover:text-primary-400">{relatedArticle.data.title}</h3>
|
||||
<p class="text-sm text-secondary-600 dark:text-secondary-400 mb-2">{relatedArticle.data.date.toLocaleDateString('zh-CN')}</p>
|
||||
{relatedArticle.data.summary && (
|
||||
<p class="text-sm text-secondary-700 dark:text-secondary-300 line-clamp-3">{relatedArticle.data.summary}</p>
|
||||
)}
|
||||
</a>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<!-- 返回顶部按钮 -->
|
||||
<button id="back-to-top" class="fixed bottom-8 right-8 w-12 h-12 rounded-full bg-primary-500 dark:bg-primary-600 text-white shadow-md flex items-center justify-center opacity-0 invisible translate-y-5 transition-all duration-300 hover:bg-primary-600 dark:hover:bg-primary-700">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 10l7-7m0 0l7 7m-7-7v18" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Layout>
|
||||
|
||||
<script>
|
||||
// 阅读进度条
|
||||
const progressBar = document.getElementById('progress-bar');
|
||||
const backToTopButton = document.getElementById('back-to-top');
|
||||
|
||||
function updateReadingProgress() {
|
||||
const scrollTop = window.scrollY || document.documentElement.scrollTop;
|
||||
const scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
|
||||
const progress = (scrollTop / scrollHeight) * 100;
|
||||
|
||||
if (progressBar) {
|
||||
progressBar.style.width = `${progress}%`;
|
||||
}
|
||||
|
||||
// 显示/隐藏返回顶部按钮
|
||||
if (backToTopButton) {
|
||||
if (scrollTop > 300) {
|
||||
backToTopButton.classList.add('opacity-100', 'visible', 'translate-y-0');
|
||||
backToTopButton.classList.remove('opacity-0', 'invisible', 'translate-y-5');
|
||||
} else {
|
||||
backToTopButton.classList.add('opacity-0', 'invisible', 'translate-y-5');
|
||||
backToTopButton.classList.remove('opacity-100', 'visible', 'translate-y-0');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 返回顶部功能
|
||||
if (backToTopButton) {
|
||||
backToTopButton.addEventListener('click', () => {
|
||||
window.scrollTo({
|
||||
top: 0,
|
||||
behavior: 'smooth'
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 监听滚动事件
|
||||
window.addEventListener('scroll', updateReadingProgress);
|
||||
|
||||
// 初始化
|
||||
updateReadingProgress();
|
||||
|
||||
// 代码块增强功能
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
// 处理所有代码块
|
||||
const codeBlocks = document.querySelectorAll('pre');
|
||||
|
||||
codeBlocks.forEach(pre => {
|
||||
// 获取代码语言
|
||||
const code = pre.querySelector('code');
|
||||
if (!code) return;
|
||||
|
||||
// 从类名中提取语言
|
||||
const className = code.className;
|
||||
const languageMatch = className.match(/language-(\w+)/);
|
||||
const language = languageMatch ? languageMatch[1] : 'text';
|
||||
|
||||
// 创建顶部栏
|
||||
const header = document.createElement('div');
|
||||
header.className = 'code-header flex justify-between items-center text-xs px-4 py-2 bg-secondary-800 dark:bg-dark-card text-secondary-300 dark:text-secondary-400 rounded-t-lg';
|
||||
|
||||
// 创建语言标签
|
||||
const languageLabel = document.createElement('span');
|
||||
languageLabel.className = 'code-language font-mono';
|
||||
languageLabel.textContent = language;
|
||||
|
||||
// 创建复制按钮
|
||||
const copyButton = document.createElement('button');
|
||||
copyButton.className = 'code-copy-button flex items-center gap-1 hover:text-white dark:hover:text-primary-400 transition-colors';
|
||||
|
||||
// 创建SVG图标和文本
|
||||
const copyIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4"><rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path></svg>`;
|
||||
const successIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4"><path d="M20 6L9 17l-5-5"></path></svg>`;
|
||||
const errorIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="w-4 h-4"><circle cx="12" cy="12" r="10"></circle><line x1="15" y1="9" x2="9" y2="15"></line><line x1="9" y1="9" x2="15" y2="15"></line></svg>`;
|
||||
|
||||
copyButton.innerHTML = `${copyIcon}<span>复制</span>`;
|
||||
copyButton.setAttribute('aria-label', '复制代码');
|
||||
copyButton.setAttribute('title', '复制代码到剪贴板');
|
||||
|
||||
// 添加复制功能
|
||||
copyButton.addEventListener('click', (e) => {
|
||||
e.stopPropagation();
|
||||
|
||||
// 获取代码文本
|
||||
const codeText = code.textContent || '';
|
||||
|
||||
// 复制到剪贴板
|
||||
navigator.clipboard.writeText(codeText)
|
||||
.then(() => {
|
||||
// 复制成功,更改按钮文本
|
||||
copyButton.innerHTML = `${successIcon}<span>已复制</span>`;
|
||||
copyButton.classList.add('text-green-400');
|
||||
|
||||
// 2秒后恢复按钮文本
|
||||
setTimeout(() => {
|
||||
copyButton.innerHTML = `${copyIcon}<span>复制</span>`;
|
||||
copyButton.classList.remove('text-green-400');
|
||||
}, 2000);
|
||||
})
|
||||
.catch(() => {
|
||||
// 复制失败,更改按钮文本
|
||||
copyButton.innerHTML = `${errorIcon}<span>失败</span>`;
|
||||
copyButton.classList.add('text-red-400');
|
||||
|
||||
// 2秒后恢复按钮文本
|
||||
setTimeout(() => {
|
||||
copyButton.innerHTML = `${copyIcon}<span>复制</span>`;
|
||||
copyButton.classList.remove('text-red-400');
|
||||
}, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
// 将语言标签和复制按钮添加到顶部栏
|
||||
header.appendChild(languageLabel);
|
||||
header.appendChild(copyButton);
|
||||
|
||||
// 将顶部栏插入到代码块的最前面
|
||||
pre.insertBefore(header, pre.firstChild);
|
||||
|
||||
// 调整代码块样式
|
||||
pre.classList.add('rounded-b-lg', 'mt-0');
|
||||
pre.style.marginTop = '0';
|
||||
});
|
||||
});
|
||||
</script>
|
388
src/pages/articles/index.astro
Normal file
388
src/pages/articles/index.astro
Normal file
@ -0,0 +1,388 @@
|
||||
---
|
||||
import { getCollection } from 'astro:content';
|
||||
import type { CollectionEntry } from 'astro:content';
|
||||
import { contentStructure, getRelativePath, getBasename, getDirPath } from '../../content.config';
|
||||
import Layout from '@/components/Layout.astro';
|
||||
import Breadcrumb from '@/components/Breadcrumb.astro';
|
||||
import ArticleTimeline from '@/components/ArticleTimeline.astro';
|
||||
|
||||
// 预渲染页面,但允许客户端导航
|
||||
export const prerender = false;
|
||||
|
||||
// 获取所有文章,并按日期排序
|
||||
const articles: CollectionEntry<'articles'>[] = await getCollection('articles');
|
||||
const sortedArticles = articles.sort(
|
||||
(a, b) => b.data.date.getTime() - a.data.date.getTime()
|
||||
);
|
||||
|
||||
// 获取所有标签
|
||||
const allTags = articles.flatMap(article => article.data.tags || []);
|
||||
const tags = [...new Set(allTags)].sort();
|
||||
|
||||
// 获取内容结构
|
||||
const { sections } = contentStructure;
|
||||
|
||||
// 获取当前路径参数
|
||||
const path = Astro.url.searchParams.get('path') || '';
|
||||
const pathSegments = path ? decodeURIComponent(path).split('/') : [];
|
||||
|
||||
// 获取标签参数
|
||||
const tagFilter = Astro.url.searchParams.get('tag') || '';
|
||||
|
||||
// 获取视图模式参数
|
||||
const viewMode = Astro.url.searchParams.get('view') || 'grid';
|
||||
|
||||
// 根据路径获取当前目录
|
||||
function getCurrentSection(pathSegments: string[]) {
|
||||
// 过滤掉空字符串
|
||||
const filteredSegments = pathSegments.filter(segment => segment.trim() !== '');
|
||||
|
||||
if (filteredSegments.length === 0) {
|
||||
return { sections, articles: contentStructure.articles, currentPath: '' };
|
||||
}
|
||||
|
||||
let currentSections = sections;
|
||||
let currentPath = '';
|
||||
let currentArticles: string[] = [];
|
||||
|
||||
// 遍历路径段,逐级查找
|
||||
for (let i = 0; i < filteredSegments.length; i++) {
|
||||
const segment = filteredSegments[i];
|
||||
|
||||
// 查找当前段对应的目录
|
||||
const foundSection = currentSections.find(s => s.name === segment);
|
||||
|
||||
if (!foundSection) {
|
||||
return { sections: [], articles: [], currentPath: '' };
|
||||
}
|
||||
|
||||
// 更新当前路径
|
||||
currentPath = currentPath ? `${currentPath}/${segment}` : segment;
|
||||
|
||||
// 如果是最后一个段,返回该目录的内容
|
||||
if (i === filteredSegments.length - 1) {
|
||||
return {
|
||||
sections: foundSection.sections,
|
||||
articles: foundSection.articles,
|
||||
currentPath
|
||||
};
|
||||
}
|
||||
|
||||
// 否则继续向下查找
|
||||
currentSections = foundSection.sections;
|
||||
}
|
||||
|
||||
// 默认返回空
|
||||
return { sections: [], articles: [], currentPath: '' };
|
||||
}
|
||||
|
||||
// 获取当前目录内容
|
||||
const { sections: currentSections, articles: currentArticles, currentPath } = getCurrentSection(pathSegments);
|
||||
|
||||
// 如果有标签过滤,则过滤文章
|
||||
let filteredArticles = sortedArticles;
|
||||
let pageTitle = currentPath ? currentPath : '文章列表';
|
||||
|
||||
if (tagFilter) {
|
||||
filteredArticles = sortedArticles.filter(article =>
|
||||
article.data.tags && article.data.tags.includes(tagFilter)
|
||||
);
|
||||
pageTitle = `标签: ${tagFilter}`;
|
||||
}
|
||||
|
||||
// 获取面包屑导航
|
||||
interface Breadcrumb {
|
||||
name: string;
|
||||
path: string;
|
||||
}
|
||||
|
||||
|
||||
---
|
||||
|
||||
<Layout>
|
||||
<div class="bg-gradient-to-b from-primary-50 to-white dark:from-gray-900 dark:to-gray-800 min-h-screen">
|
||||
<main class={`mx-auto px-4 py-6 ${viewMode === 'grid' ? 'max-w-6xl' : 'max-w-4xl'}`}>
|
||||
<!-- 导航栏 -->
|
||||
<div class="bg-white dark:bg-gray-800 rounded-xl mb-4">
|
||||
<div class="px-4 py-3">
|
||||
<div class="flex items-center justify-between !h-10">
|
||||
<Breadcrumb
|
||||
pageType="articles"
|
||||
pathSegments={pathSegments}
|
||||
tagFilter={tagFilter}
|
||||
/>
|
||||
|
||||
<!-- 视图切换按钮 -->
|
||||
<div class="flex items-center gap-px">
|
||||
<a href={`/articles?${new URLSearchParams({...Object.fromEntries(Astro.url.searchParams), view: 'grid'}).toString()}`}
|
||||
class={`px-3 py-1.5 transition-colors flex items-center gap-1 ${
|
||||
viewMode === 'grid'
|
||||
? 'text-primary-600'
|
||||
: 'text-gray-400 hover:text-gray-500'
|
||||
}`}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2V6zM14 6a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2V6zM4 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2H6a2 2 0 01-2-2v-2zM14 16a2 2 0 012-2h2a2 2 0 012 2v2a2 2 0 01-2 2h-2a2 2 0 01-2-2v-2z" />
|
||||
</svg>
|
||||
</a>
|
||||
<a href={`/articles?${new URLSearchParams({...Object.fromEntries(Astro.url.searchParams), view: 'timeline'}).toString()}`}
|
||||
class={`px-3 py-1.5 transition-colors flex items-center gap-1 ${
|
||||
viewMode === 'timeline'
|
||||
? 'text-primary-600'
|
||||
: 'text-gray-400 hover:text-gray-500'
|
||||
}`}>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
|
||||
</svg>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{viewMode === 'grid' ? (
|
||||
<>
|
||||
<!-- 内容卡片网格 -->
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6 mb-12">
|
||||
{/* 上一级目录卡片 - 仅在浏览目录时显示 */}
|
||||
{!tagFilter && pathSegments.length > 0 && (
|
||||
<a href={`/articles${pathSegments.length > 1 ? `?path=${encodeURIComponent(pathSegments.slice(0, -1).join('/'))}` : ''}`}
|
||||
class="group flex flex-col h-full p-4 border border-primary-100 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-800 hover:shadow-xl transition-all duration-300 hover:border-primary-300 dark:hover:border-primary-600">
|
||||
<div class="flex items-center">
|
||||
<div class="w-10 h-10 flex items-center justify-center rounded-lg bg-primary-100 text-primary-600 group-hover:bg-primary-200 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 17l-5-5m0 0l5-5m-5 5h12" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<div class="font-bold text-base text-gray-800 dark:text-gray-100 group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors">返回上级目录</div>
|
||||
<div class="text-xs text-gray-500">返回上一级</div>
|
||||
</div>
|
||||
<div class="text-primary-500 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
)}
|
||||
|
||||
{/* 目录卡片 - 仅在浏览目录时显示 */}
|
||||
{!tagFilter && currentSections.map(section => {
|
||||
// 确保目录链接正确生成
|
||||
const dirLink = currentPath ? `${currentPath}/${section.name}` : section.name;
|
||||
|
||||
return (
|
||||
<a href={`/articles?path=${encodeURIComponent(dirLink)}`}
|
||||
class="group flex flex-col h-full p-4 border border-primary-100 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-800 hover:shadow-xl transition-all duration-300 hover:border-primary-300 dark:hover:border-primary-600">
|
||||
<div class="flex items-center">
|
||||
<div class="w-10 h-10 flex items-center justify-center rounded-lg bg-primary-100 text-primary-600 group-hover:bg-primary-200 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 19a2 2 0 01-2-2V7a2 2 0 012-2h4l2 2h4a2 2 0 012 2v1M5 19h14a2 2 0 002-2v-5a2 2 0 00-2-2H9a2 2 0 00-2 2v5a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<div class="font-bold text-base text-gray-800 dark:text-gray-100 group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors line-clamp-1">{section.name}</div>
|
||||
<div class="text-xs text-gray-500 flex items-center mt-1">
|
||||
{section.sections.length > 0 && (
|
||||
<span class="flex items-center mr-3">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
|
||||
</svg>
|
||||
{section.sections.length} 个子目录
|
||||
</span>
|
||||
)}
|
||||
{section.articles.length > 0 && (
|
||||
<span class="flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-3 w-3 mr-1" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z" />
|
||||
</svg>
|
||||
{section.articles.length} 篇文章
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-primary-500 opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path fill-rule="evenodd" d="M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z" clip-rule="evenodd" />
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
|
||||
{/* 文章卡片 - 根据是否有标签过滤显示不同内容 */}
|
||||
{tagFilter ? (
|
||||
// 显示标签过滤后的文章
|
||||
filteredArticles.map(article => (
|
||||
<a href={`/articles/${article.id}`}
|
||||
class="group flex flex-col h-full p-4 border border-primary-100 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-800 hover:shadow-xl transition-all duration-300 hover:border-primary-300 dark:hover:border-primary-600">
|
||||
<div class="flex items-start">
|
||||
<div class="w-10 h-10 flex-shrink-0 flex items-center justify-center rounded-lg bg-primary-100 text-primary-600 group-hover:bg-primary-200 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<h3 class="font-bold text-base text-gray-800 dark:text-gray-100 group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors line-clamp-2">{article.data.title}</h3>
|
||||
{article.data.summary && (
|
||||
<p class="text-xs text-gray-600 mt-1 line-clamp-2">{article.data.summary}</p>
|
||||
)}
|
||||
<div class="text-xs text-gray-500 mt-2 flex items-center justify-between">
|
||||
<time datetime={article.data.date.toISOString()}>
|
||||
{article.data.date.toLocaleDateString('zh-CN', {year: 'numeric', month: 'long', day: 'numeric'})}
|
||||
</time>
|
||||
<span class="text-primary-600 font-medium">阅读全文</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
))
|
||||
) : (
|
||||
// 显示当前目录的文章
|
||||
currentArticles.map(articlePath => {
|
||||
// 获取文章ID
|
||||
const articleId = getRelativePath(articlePath);
|
||||
|
||||
// 尝试不同的方式匹配文章
|
||||
const article = articles.find(a => {
|
||||
// 1. 直接匹配完整路径
|
||||
if (a.id === articleId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. 匹配文件名(不含路径和扩展名)
|
||||
const baseName = getBasename(articleId);
|
||||
if (a.id === baseName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. 尝试匹配相对路径的一部分
|
||||
const articleParts = articleId.split('/');
|
||||
const fileName = articleParts[articleParts.length - 1];
|
||||
if (a.id.endsWith(fileName)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4. 移除.md扩展名后匹配
|
||||
const idWithoutExt = articleId.replace(/\.md$/, '');
|
||||
if (a.id === idWithoutExt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 5. 处理多级目录结构
|
||||
// 如果文章ID包含目录路径,尝试匹配最后的文件名部分
|
||||
const articlePathParts = articlePath.split('/');
|
||||
const articleFileName = articlePathParts[articlePathParts.length - 1];
|
||||
const articleIdParts = a.id.split('/');
|
||||
const articleIdFileName = articleIdParts[articleIdParts.length - 1];
|
||||
|
||||
if (articleFileName === articleIdFileName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 6. 移除扩展名后比较文件名
|
||||
const fileNameWithoutExt = articleFileName.replace(/\.md$/, '');
|
||||
if (articleIdFileName === fileNameWithoutExt) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
if (!article) {
|
||||
return (
|
||||
<div class="flex flex-col h-full p-4 border border-red-200 rounded-xl bg-red-50">
|
||||
<div class="flex items-start">
|
||||
<div class="w-10 h-10 flex-shrink-0 flex items-center justify-center rounded-lg bg-red-100 text-red-600">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<h3 class="font-bold text-base text-red-800">文章不存在</h3>
|
||||
<p class="text-xs text-red-600 mt-1">ID: {articleId}</p>
|
||||
<div class="text-xs text-red-500 mt-2 line-clamp-1">
|
||||
可用文章: {articles.map(a => a.id).join(', ')}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<a href={`/articles/${article.id}`}
|
||||
class="group flex flex-col h-full p-4 border border-primary-100 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-800 hover:shadow-xl transition-all duration-300 hover:border-primary-300 dark:hover:border-primary-600">
|
||||
<div class="flex items-start">
|
||||
<div class="w-10 h-10 flex-shrink-0 flex items-center justify-center rounded-lg bg-primary-100 text-primary-600 group-hover:bg-primary-200 transition-colors">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 20H5a2 2 0 01-2-2V6a2 2 0 012-2h10a2 2 0 012 2v1m2 13a2 2 0 01-2-2V7m2 13a2 2 0 002-2V9a2 2 0 00-2-2h-2m-4-3H9M7 16h6M7 8h6v4H7V8z" />
|
||||
</svg>
|
||||
</div>
|
||||
<div class="ml-3 flex-1">
|
||||
<h3 class="font-bold text-base text-gray-800 dark:text-gray-100 group-hover:text-primary-700 dark:group-hover:text-primary-300 transition-colors line-clamp-2">{article.data.title}</h3>
|
||||
{article.data.summary && (
|
||||
<p class="text-xs text-gray-600 mt-1 line-clamp-2">{article.data.summary}</p>
|
||||
)}
|
||||
<div class="text-xs text-gray-500 mt-2 flex items-center justify-between">
|
||||
<time datetime={article.data.date.toISOString()}>
|
||||
{article.data.date.toLocaleDateString('zh-CN', {year: 'numeric', month: 'long', day: 'numeric'})}
|
||||
</time>
|
||||
<span class="text-primary-600 font-medium">阅读全文</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* 空内容提示 */}
|
||||
{((tagFilter && filteredArticles.length === 0) || (!tagFilter && currentSections.length === 0 && currentArticles.length === 0)) && (
|
||||
<div class="text-center py-16 bg-white rounded-xl shadow-sm mb-12">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-16 w-16 mx-auto text-primary-200 mb-4" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20 13V6a2 2 0 00-2-2H6a2 2 0 00-2 2v7m16 0v5a2 2 0 01-2 2H6a2 2 0 01-2-2v-5m16 0h-2.586a1 1 0 00-.707.293l-2.414 2.414a1 1 0 01-.707.293h-3.172a1 1 0 01-.707-.293l-2.414-2.414A1 1 0 006.586 13H4" />
|
||||
</svg>
|
||||
<h3 class="text-2xl font-bold text-gray-700 mb-2">
|
||||
{tagFilter ? `没有找到标签为 "${tagFilter}" 的文章` : '此目录为空'}
|
||||
</h3>
|
||||
<p class="text-gray-500 max-w-md mx-auto">
|
||||
{tagFilter ? '请尝试其他标签或返回文章列表' : '此目录下暂无内容,请浏览其他目录或返回上一级'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<!-- 标签过滤器 -->
|
||||
<div class="bg-white dark:bg-gray-800 p-8 rounded-xl shadow-sm">
|
||||
<h2 class="text-2xl font-bold mb-6 text-primary-900 dark:text-primary-100 flex items-center">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
||||
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M7 7h.01M7 3h5c.512 0 1.024.195 1.414.586l7 7a2 2 0 010 2.828l-7 7a2 2 0 01-2.828 0l-7-7A1.994 1.994 0 013 12V7a4 4 0 014-4z" />
|
||||
</svg>
|
||||
文章标签
|
||||
</h2>
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
{tags.map(tag => {
|
||||
const isActive = tag === tagFilter;
|
||||
return (
|
||||
<a href={`/articles?tag=${tag}`}
|
||||
class={`py-2 px-4 rounded-full text-sm font-medium transition-all duration-200 ${
|
||||
isActive
|
||||
? 'bg-primary-600 text-white dark:bg-primary-500 dark:text-gray-900 hover:bg-primary-700 dark:hover:bg-primary-400'
|
||||
: 'bg-primary-50 dark:bg-gray-700 text-primary-700 dark:text-primary-200 hover:bg-primary-100 dark:hover:bg-gray-600'
|
||||
}`}>
|
||||
{tag}
|
||||
</a>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<ArticleTimeline title="" itemsPerPage={10} />
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
</Layout>
|
9
src/pages/books.astro
Normal file
9
src/pages/books.astro
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
import Layout from '@/components/Layout.astro';
|
||||
import MediaGrid from '@/components/MediaGrid.astro';
|
||||
import { SITE_NAME } from '@/consts';
|
||||
---
|
||||
|
||||
<Layout title={`图书 - ${SITE_NAME}`}>
|
||||
<MediaGrid type="book" title="我读过的书" />
|
||||
</Layout>
|
@ -1,11 +1,10 @@
|
||||
---
|
||||
import Welcome from '../components/Welcome.astro';
|
||||
import Layout from '../layouts/Layout.astro';
|
||||
|
||||
// Welcome to Astro! Wondering what to do next? Check out the Astro documentation at https://docs.astro.build
|
||||
// Don't want to use any of this? Delete everything in this file, the `assets`, `components`, and `layouts` directories, and start fresh.
|
||||
import Layout from '@/components/Layout.astro';
|
||||
import { ThemeToggle } from '@/components/ThemeToggle';
|
||||
---
|
||||
|
||||
<Layout>
|
||||
<Welcome />
|
||||
|
||||
|
||||
|
||||
</Layout>
|
||||
|
9
src/pages/movies.astro
Normal file
9
src/pages/movies.astro
Normal file
@ -0,0 +1,9 @@
|
||||
---
|
||||
import Layout from '@/components/Layout.astro';
|
||||
import MediaGrid from '@/components/MediaGrid.astro';
|
||||
import { SITE_NAME } from '@/consts.ts';
|
||||
---
|
||||
|
||||
<Layout title={`电影 - ${SITE_NAME}`}>
|
||||
<MediaGrid type="movie" title="我看过的电影" />
|
||||
</Layout>
|
0
src/pages/projects.astro
Normal file
0
src/pages/projects.astro
Normal file
172
src/styles/code-blocks.css
Normal file
172
src/styles/code-blocks.css
Normal file
@ -0,0 +1,172 @@
|
||||
/* 代码块容器样式 */
|
||||
.prose pre {
|
||||
position: relative;
|
||||
margin: 1.5em 0;
|
||||
padding: 0;
|
||||
border-radius: 0.5rem;
|
||||
/* 调整背景色和边框 */
|
||||
background-color: #282c34 !important;
|
||||
border: 1px solid #374151;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.prose pre:hover {
|
||||
/* 移除之前的transform和shadow */
|
||||
}
|
||||
|
||||
/* 代码块顶部栏 - 调整颜色使其更突出 */
|
||||
.code-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
/* 修改背景色为更深的颜色 */
|
||||
background-color: #21252b;
|
||||
padding: 0.5rem 1rem;
|
||||
/* 调整边框颜色 */
|
||||
border-bottom: 1px solid #374151;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
/* 语言标签 */
|
||||
.code-language {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
/* 调整颜色使其更明显 */
|
||||
color: #d1d5db;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
}
|
||||
|
||||
/* 复制按钮 - 增强视觉效果 */
|
||||
.code-copy-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 6px;
|
||||
padding: 0.35rem 0.75rem;
|
||||
font-size: 0.75rem;
|
||||
/* 调整按钮颜色 */
|
||||
color: #d1d5db;
|
||||
background-color: #2c313a;
|
||||
border: 1px solid #4b5563;
|
||||
border-radius: 0.25rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
}
|
||||
|
||||
.code-copy-button svg {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
stroke: currentColor;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.code-copy-button span {
|
||||
font-size: 0.75rem;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.code-copy-button:hover {
|
||||
background-color: #374151;
|
||||
color: #f3f4f6;
|
||||
border-color: #6b7280;
|
||||
}
|
||||
|
||||
.code-copy-button:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
/* 代码内容区域 */
|
||||
.prose pre code {
|
||||
display: block;
|
||||
padding: 1.5em 1.25em;
|
||||
overflow-x: auto;
|
||||
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
font-size: 0.9em;
|
||||
line-height: 1.6;
|
||||
tab-size: 2;
|
||||
/* 调整文字颜色 */
|
||||
color: #abb2bf !important;
|
||||
}
|
||||
|
||||
/* 自定义滚动条 */
|
||||
.prose pre code::-webkit-scrollbar {
|
||||
height: 8px;
|
||||
background-color: #282c34;
|
||||
}
|
||||
|
||||
.prose pre code::-webkit-scrollbar-thumb {
|
||||
background-color: #4b5363;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.prose pre code::-webkit-scrollbar-thumb:hover {
|
||||
background-color: #5a6377;
|
||||
}
|
||||
|
||||
.prose pre code::-webkit-scrollbar-track {
|
||||
background-color: #21252b;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
/* Firefox滚动条 */
|
||||
.prose pre code {
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: #4b5363 #282c34;
|
||||
}
|
||||
|
||||
/* 代码行高亮 */
|
||||
.prose pre .highlight-line {
|
||||
background-color: rgba(171, 178, 191, 0.1);
|
||||
display: block;
|
||||
margin: 0 -1em;
|
||||
padding: 0 1em;
|
||||
}
|
||||
|
||||
/* 行号 */
|
||||
.prose pre code {
|
||||
counter-reset: line;
|
||||
}
|
||||
|
||||
.prose pre code .line {
|
||||
display: inline-block;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 内联代码样式 */
|
||||
.prose :not(pre) > code {
|
||||
background-color: rgba(171, 178, 191, 0.1);
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 0.25em;
|
||||
font-weight: 400;
|
||||
white-space: nowrap;
|
||||
border: 1px solid rgba(171, 178, 191, 0.2);
|
||||
font-family: "JetBrains Mono", Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
|
||||
font-size: 0.85em;
|
||||
color: #e06c75;
|
||||
}
|
||||
|
||||
/* 暗色模式适配 */
|
||||
[data-theme="dark"] .prose pre,
|
||||
[data-theme="dark"] .code-header {
|
||||
background-color: #282c34 !important;
|
||||
border-color: #374151;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .code-copy-button {
|
||||
background-color: #2c313a;
|
||||
border-color: #4b5563;
|
||||
color: #d1d5db;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .code-copy-button:hover {
|
||||
background-color: #374151;
|
||||
color: #f3f4f6;
|
||||
border-color: #6b7280;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose pre code {
|
||||
/* 调整暗色模式文字颜色 */
|
||||
color: #abb2bf;
|
||||
}
|
253
src/styles/content-styles.css
Normal file
253
src/styles/content-styles.css
Normal file
@ -0,0 +1,253 @@
|
||||
/* 增强表格样式 */
|
||||
.prose table {
|
||||
border-collapse: collapse;
|
||||
width: 100%;
|
||||
margin-top: 1.5em;
|
||||
margin-bottom: 1.5em;
|
||||
border-radius: 0.5rem;
|
||||
overflow: hidden;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.prose thead {
|
||||
background-color: var(--color-secondary-50);
|
||||
}
|
||||
|
||||
.prose thead th {
|
||||
padding: 0.75rem 1rem;
|
||||
font-weight: 600;
|
||||
text-align: left;
|
||||
border-bottom: 2px solid var(--color-secondary-200);
|
||||
}
|
||||
|
||||
.prose tbody tr {
|
||||
border-bottom: 1px solid var(--color-secondary-200);
|
||||
}
|
||||
|
||||
.prose tbody tr:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.prose tbody td {
|
||||
padding: 0.75rem 1rem;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.prose tbody tr:nth-child(even) {
|
||||
background-color: var(--color-secondary-50);
|
||||
}
|
||||
|
||||
/* 增强列表样式 */
|
||||
.prose ul {
|
||||
list-style-type: disc;
|
||||
margin-top: 1.25em;
|
||||
margin-bottom: 1.25em;
|
||||
padding-left: 1.625em;
|
||||
}
|
||||
|
||||
.prose ul li {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
padding-left: 0.375em;
|
||||
}
|
||||
|
||||
.prose ul li::marker {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.prose ul li ul {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
}
|
||||
|
||||
.prose ol {
|
||||
list-style-type: decimal;
|
||||
margin-top: 1.25em;
|
||||
margin-bottom: 1.25em;
|
||||
padding-left: 1.625em;
|
||||
}
|
||||
|
||||
.prose ol li {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
padding-left: 0.375em;
|
||||
}
|
||||
|
||||
.prose ol li::marker {
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
/* 增强代码块样式 */
|
||||
.prose pre {
|
||||
margin: 1.5em 0;
|
||||
padding: 1em;
|
||||
border-radius: 0.375rem;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.prose :not(pre) > code {
|
||||
background-color: rgba(0, 0, 0, 0.1);
|
||||
padding: 0.2em 0.4em;
|
||||
border-radius: 0.25em;
|
||||
font-weight: 400;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 移除 Tailwind Typography 添加的引号 */
|
||||
.prose code::before,
|
||||
.prose code::after {
|
||||
content: none !important;
|
||||
}
|
||||
|
||||
/* 表情符号样式 */
|
||||
.prose img.emoji {
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
margin: 0 0.05em 0 0.1em;
|
||||
vertical-align: -0.1em;
|
||||
display: inline-block;
|
||||
border: none;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* 标题样式 */
|
||||
.prose h1 {
|
||||
font-size: 2.25rem;
|
||||
font-weight: 700;
|
||||
margin-top: 2.5rem;
|
||||
margin-bottom: 1.5rem;
|
||||
color: var(--color-secondary-900);
|
||||
border-bottom: 1px solid var(--color-secondary-200);
|
||||
padding-bottom: 0.5rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.prose h1::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
left: 0;
|
||||
width: 100px;
|
||||
height: 3px;
|
||||
background: linear-gradient(to right, var(--color-primary-600), var(--color-primary-400));
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.prose h2 {
|
||||
font-size: 1.875rem;
|
||||
font-weight: 700;
|
||||
margin-top: 2rem;
|
||||
margin-bottom: 1.25rem;
|
||||
color: var(--color-secondary-900);
|
||||
border-bottom: 1px solid var(--color-secondary-200);
|
||||
padding-bottom: 0.25rem;
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.prose h2::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: -1px;
|
||||
left: 0;
|
||||
width: 75px;
|
||||
height: 2px;
|
||||
background: linear-gradient(to right, var(--color-primary-500), var(--color-primary-300));
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.prose h3 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1.75rem;
|
||||
margin-bottom: 1rem;
|
||||
color: var(--color-secondary-900);
|
||||
position: relative;
|
||||
padding-left: 1rem;
|
||||
}
|
||||
|
||||
.prose h3::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
left: 0;
|
||||
top: 0.25em;
|
||||
height: 1em;
|
||||
width: 4px;
|
||||
background: linear-gradient(to bottom, var(--color-primary-500), var(--color-primary-300));
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.prose h4 {
|
||||
font-size: 1.25rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1.5rem;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--color-secondary-900);
|
||||
}
|
||||
|
||||
.prose h5 {
|
||||
font-size: 1.125rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--color-secondary-900);
|
||||
}
|
||||
|
||||
.prose h6 {
|
||||
font-size: 1rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
color: var(--color-secondary-700);
|
||||
}
|
||||
|
||||
/* 标题锚点样式 */
|
||||
.prose h1 .anchor,
|
||||
.prose h2 .anchor,
|
||||
.prose h3 .anchor,
|
||||
.prose h4 .anchor,
|
||||
.prose h5 .anchor,
|
||||
.prose h6 .anchor {
|
||||
visibility: hidden;
|
||||
margin-left: 0.5rem;
|
||||
color: #a0aec0;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.prose h1:hover .anchor,
|
||||
.prose h2:hover .anchor,
|
||||
.prose h3:hover .anchor,
|
||||
.prose h4:hover .anchor,
|
||||
.prose h5:hover .anchor,
|
||||
.prose h6:hover .anchor {
|
||||
visibility: visible;
|
||||
}
|
||||
|
||||
/* 暗色模式 */
|
||||
[data-theme="dark"] .prose {
|
||||
color: var(--color-secondary-300);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose h1,
|
||||
[data-theme="dark"] .prose h2,
|
||||
[data-theme="dark"] .prose h3,
|
||||
[data-theme="dark"] .prose h4,
|
||||
[data-theme="dark"] .prose h5 {
|
||||
color: var(--color-secondary-100);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose h6 {
|
||||
color: var(--color-secondary-300);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose thead {
|
||||
background-color: var(--color-dark-card);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose tbody tr:nth-child(even) {
|
||||
background-color: var(--color-dark-card);
|
||||
}
|
||||
|
||||
[data-theme="dark"] .prose thead th,
|
||||
[data-theme="dark"] .prose tbody tr {
|
||||
border-color: var(--color-dark-border);
|
||||
}
|
36
src/styles/emoji.css
Normal file
36
src/styles/emoji.css
Normal file
@ -0,0 +1,36 @@
|
||||
/* 表情符号样式 */
|
||||
.emoji {
|
||||
height: 1em;
|
||||
width: 1em;
|
||||
margin: 0 0.05em 0 0.1em;
|
||||
vertical-align: -0.1em;
|
||||
display: inline-block !important;
|
||||
border: none !important;
|
||||
box-shadow: none !important;
|
||||
background: none !important;
|
||||
}
|
||||
|
||||
/* 确保表情符号在列表项中正确显示 */
|
||||
li .emoji {
|
||||
margin-right: 0.2em;
|
||||
}
|
||||
|
||||
/* 确保表情符号在标题中正确显示 */
|
||||
h1 .emoji,
|
||||
h2 .emoji,
|
||||
h3 .emoji,
|
||||
h4 .emoji,
|
||||
h5 .emoji,
|
||||
h6 .emoji {
|
||||
vertical-align: -0.1em;
|
||||
}
|
||||
|
||||
/* 确保表情符号在表格中正确显示 */
|
||||
td .emoji,
|
||||
th .emoji {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
[data-theme="dark"] .emoji {
|
||||
filter: brightness(0.8) contrast(1.2);
|
||||
}
|
56
src/styles/global.css
Normal file
56
src/styles/global.css
Normal file
@ -0,0 +1,56 @@
|
||||
@import "tailwindcss";
|
||||
@import "./prism.css";
|
||||
@import "./content-styles.css";
|
||||
@import "./emoji.css";
|
||||
@import "./code-blocks.css";
|
||||
|
||||
/* 定义深色模式选择器 */
|
||||
@custom-variant dark (&:where([data-theme=dark], [data-theme=dark] *));
|
||||
|
||||
@theme {
|
||||
/* 主色调 - 使用更现代的蓝紫色 */
|
||||
--color-primary-50: #f5f7ff;
|
||||
--color-primary-100: #ebf0ff;
|
||||
--color-primary-200: #d6e0ff;
|
||||
--color-primary-300: #adc2ff;
|
||||
--color-primary-400: #839dff;
|
||||
--color-primary-500: #4b6bff;
|
||||
--color-primary-600: #3451db;
|
||||
--color-primary-700: #2541b7;
|
||||
--color-primary-800: #1a3293;
|
||||
--color-primary-900: #132878;
|
||||
--color-primary-950: #0c1b5c;
|
||||
|
||||
/* 中性色调 */
|
||||
--color-gray-50: #f8fafc;
|
||||
--color-gray-100: #f1f5f9;
|
||||
--color-gray-200: #e2e8f0;
|
||||
--color-gray-300: #cbd5e1;
|
||||
--color-gray-400: #94a3b8;
|
||||
--color-gray-500: #64748b;
|
||||
--color-gray-600: #475569;
|
||||
--color-gray-700: #334155;
|
||||
--color-gray-800: #1e293b;
|
||||
--color-gray-900: #0f172a;
|
||||
--color-gray-950: #020617;
|
||||
|
||||
/* 深色模式颜色 */
|
||||
--color-dark-bg: #0f172a;
|
||||
--color-dark-surface: #1e293b;
|
||||
--color-dark-card: #334155;
|
||||
--color-dark-border: #475569;
|
||||
--color-dark-text: #e2e8f0;
|
||||
--color-dark-text-secondary: #94a3b8;
|
||||
}
|
||||
|
||||
/* 深色模式样式 */
|
||||
[data-theme='dark'] {
|
||||
--bg-primary: var(--color-dark-bg);
|
||||
--bg-secondary: var(--color-dark-surface);
|
||||
--text-primary: var(--color-dark-text);
|
||||
--text-secondary: var(--color-dark-text-secondary);
|
||||
--border-color: var(--color-dark-border);
|
||||
|
||||
background-color: var(--bg-primary);
|
||||
color: var(--text-primary);
|
||||
}
|
139
src/styles/prism.css
Normal file
139
src/styles/prism.css
Normal file
@ -0,0 +1,139 @@
|
||||
/* PrismJS 1.29.0
|
||||
https://prismjs.com/download.html#themes=prism-tomorrow&languages=markup+css+clike+javascript+bash+jsx+tsx+typescript */
|
||||
/**
|
||||
* prism.js tomorrow night eighties for JavaScript, CoffeeScript, CSS and HTML
|
||||
* Based on https://github.com/chriskempson/tomorrow-theme
|
||||
* @author Rose Pritchard
|
||||
*/
|
||||
|
||||
code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
color: #abb2bf !important;
|
||||
background: none;
|
||||
font-family: Consolas, Monaco, 'Andale Mono', 'Ubuntu Mono', monospace;
|
||||
font-size: 1em;
|
||||
text-align: left;
|
||||
white-space: pre;
|
||||
word-spacing: normal;
|
||||
word-break: normal;
|
||||
word-wrap: normal;
|
||||
line-height: 1.5;
|
||||
border: 1px solid #374151;
|
||||
|
||||
-moz-tab-size: 4;
|
||||
-o-tab-size: 4;
|
||||
tab-size: 4;
|
||||
|
||||
-webkit-hyphens: none;
|
||||
-moz-hyphens: none;
|
||||
-ms-hyphens: none;
|
||||
hyphens: none;
|
||||
}
|
||||
|
||||
/* Code blocks */
|
||||
pre[class*="language-"] {
|
||||
padding: 1em;
|
||||
margin: .5em 0;
|
||||
overflow: auto;
|
||||
border-radius: 0.5rem;
|
||||
background: #282c34 !important;
|
||||
}
|
||||
|
||||
:not(pre) > code[class*="language-"],
|
||||
pre[class*="language-"] {
|
||||
background: #282c34 !important;
|
||||
}
|
||||
|
||||
/* Inline code */
|
||||
:not(pre) > code[class*="language-"] {
|
||||
padding: .1em;
|
||||
border-radius: .3em;
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.token.comment,
|
||||
.token.block-comment,
|
||||
.token.prolog,
|
||||
.token.doctype,
|
||||
.token.cdata {
|
||||
color: #7f848e;
|
||||
}
|
||||
|
||||
.token.punctuation {
|
||||
color: #abb2bf;
|
||||
}
|
||||
|
||||
.token.tag,
|
||||
.token.attr-name,
|
||||
.token.namespace,
|
||||
.token.deleted {
|
||||
color: #e06c75;
|
||||
}
|
||||
|
||||
.token.function-name {
|
||||
color: #61afef;
|
||||
}
|
||||
|
||||
.token.boolean,
|
||||
.token.number,
|
||||
.token.function {
|
||||
color: #d19a66;
|
||||
}
|
||||
|
||||
.token.property,
|
||||
.token.class-name,
|
||||
.token.constant,
|
||||
.token.symbol {
|
||||
color: #e5c07b;
|
||||
}
|
||||
|
||||
.token.selector,
|
||||
.token.important,
|
||||
.token.atrule,
|
||||
.token.keyword,
|
||||
.token.builtin {
|
||||
color: #c678dd;
|
||||
}
|
||||
|
||||
.token.string,
|
||||
.token.char,
|
||||
.token.attr-value,
|
||||
.token.regex,
|
||||
.token.variable {
|
||||
color: #98c379;
|
||||
}
|
||||
|
||||
.token.operator,
|
||||
.token.entity,
|
||||
.token.url {
|
||||
color: #56b6c2;
|
||||
}
|
||||
|
||||
.token.important,
|
||||
.token.bold {
|
||||
font-weight: bold;
|
||||
}
|
||||
.token.italic {
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
.token.entity {
|
||||
cursor: help;
|
||||
}
|
||||
|
||||
.token.inserted {
|
||||
color: green;
|
||||
}
|
||||
|
||||
[data-theme="dark"] code[class*="language-"],
|
||||
[data-theme="dark"] pre[class*="language-"] {
|
||||
color: #abb2bf !important;
|
||||
background: #282c34 !important;
|
||||
}
|
||||
|
||||
[data-theme="dark"] :not(pre) > code[class*="language-"],
|
||||
[data-theme="dark"] pre[class*="language-"] {
|
||||
background: #282c34 !important;
|
||||
}
|
||||
|
||||
/* 添加其他token的暗色模式样式... */
|
@ -1,5 +1,22 @@
|
||||
{
|
||||
"extends": "astro/tsconfigs/strict",
|
||||
"include": [".astro/types.d.ts", "**/*"],
|
||||
"exclude": ["dist"]
|
||||
}
|
||||
"include": [
|
||||
".astro/types.d.ts",
|
||||
"src/**/*"
|
||||
],
|
||||
"exclude": [
|
||||
"dist"
|
||||
],
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
},
|
||||
"jsx": "react-jsx",
|
||||
"jsxImportSource": "react",
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user