更新 create_post.sh 脚本以允许路径参数为空,修正文件名生成逻辑;修改 GitProjectCollection 组件以简化配置,确保用户名为必填项;在 WorldHeatmap 组件中添加主题变化监听,优化鼠标交互和国家选择逻辑;更新文档以包含旅行足迹功能的使用示例。
This commit is contained in:
parent
93603a7d30
commit
8d6e7a3502
@ -6,15 +6,15 @@ PROJECT_ROOT="$(cd "$(dirname "$0")" && pwd)"
|
|||||||
# 如果没有提供参数,使用交互式输入
|
# 如果没有提供参数,使用交互式输入
|
||||||
if [ "$#" -lt 2 ]; then
|
if [ "$#" -lt 2 ]; then
|
||||||
read -rp "请输入文章标题: " TITLE
|
read -rp "请输入文章标题: " TITLE
|
||||||
read -rp "请输入文章路径 (例如: web/my-post): " PATH_ARG
|
read -rp "请输入文章路径 (例如: web/my-post),也可以为空: " PATH_ARG
|
||||||
else
|
else
|
||||||
TITLE=$1
|
TITLE=$1
|
||||||
PATH_ARG=$2
|
PATH_ARG=$2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 检查输入是否为空
|
# 检查输入是否为空
|
||||||
if [ -z "$TITLE" ] || [ -z "$PATH_ARG" ]; then
|
if [ -z "$TITLE" ] ; then
|
||||||
echo "错误: 标题和路径不能为空"
|
echo "错误: 标题不能为空"
|
||||||
echo "使用方法: $0 <标题> <路径>"
|
echo "使用方法: $0 <标题> <路径>"
|
||||||
echo "示例: $0 \"我的新文章\" \"web/my-post\""
|
echo "示例: $0 \"我的新文章\" \"web/my-post\""
|
||||||
exit 1
|
exit 1
|
||||||
@ -31,7 +31,7 @@ FULL_PATH="$CONTENT_DIR/$PATH_ARG"
|
|||||||
mkdir -p "$FULL_PATH"
|
mkdir -p "$FULL_PATH"
|
||||||
|
|
||||||
# 构建最终的文件路径
|
# 构建最终的文件路径
|
||||||
FILENAME="$FULL_PATH/$(basename "$PATH_ARG").md"
|
FILENAME="$FULL_PATH/$(basename "$TITLE").md"
|
||||||
ABSOLUTE_PATH="$(cd "$(dirname "$FILENAME")" 2>/dev/null && pwd)/$(basename "$FILENAME")"
|
ABSOLUTE_PATH="$(cd "$(dirname "$FILENAME")" 2>/dev/null && pwd)/$(basename "$FILENAME")"
|
||||||
|
|
||||||
# 检查文件是否已存在
|
# 检查文件是否已存在
|
||||||
|
@ -8,18 +8,9 @@ export enum GitPlatform {
|
|||||||
GITEE = 'gitee'
|
GITEE = 'gitee'
|
||||||
}
|
}
|
||||||
|
|
||||||
// Git 配置接口
|
|
||||||
export type GitConfig = {
|
|
||||||
username: string;
|
|
||||||
token?: string;
|
|
||||||
perPage?: number;
|
|
||||||
url?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// 平台默认配置
|
// 平台默认配置
|
||||||
export const DEFAULT_GIT_CONFIG = {
|
export const DEFAULT_GIT_CONFIG = {
|
||||||
perPage: 10,
|
perPage: 10
|
||||||
giteaUrl: ''
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 内部使用的平台配置
|
// 内部使用的平台配置
|
||||||
@ -62,10 +53,12 @@ interface Pagination {
|
|||||||
|
|
||||||
interface GitProjectCollectionProps {
|
interface GitProjectCollectionProps {
|
||||||
platform: GitPlatform;
|
platform: GitPlatform;
|
||||||
username?: string;
|
username: string;
|
||||||
organization?: string;
|
organization?: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
config: GitConfig;
|
token?: string;
|
||||||
|
perPage?: number;
|
||||||
|
url?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
||||||
@ -73,7 +66,9 @@ const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
|||||||
username,
|
username,
|
||||||
organization,
|
organization,
|
||||||
title,
|
title,
|
||||||
config
|
token,
|
||||||
|
perPage = DEFAULT_GIT_CONFIG.perPage,
|
||||||
|
url
|
||||||
}) => {
|
}) => {
|
||||||
const [projects, setProjects] = useState<GitProject[]>([]);
|
const [projects, setProjects] = useState<GitProject[]>([]);
|
||||||
const [pagination, setPagination] = useState<Pagination>({ current: 1, total: 1, hasNext: false, hasPrev: false });
|
const [pagination, setPagination] = useState<Pagination>({ current: 1, total: 1, hasNext: false, hasPrev: false });
|
||||||
@ -81,8 +76,6 @@ const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
|||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const [isPageChanging, setIsPageChanging] = useState(false);
|
const [isPageChanging, setIsPageChanging] = useState(false);
|
||||||
|
|
||||||
const effectiveUsername = username || config.username;
|
|
||||||
|
|
||||||
const fetchData = async (page = 1) => {
|
const fetchData = async (page = 1) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
@ -97,10 +90,19 @@ const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
|||||||
|
|
||||||
baseUrl.searchParams.append('platform', platform);
|
baseUrl.searchParams.append('platform', platform);
|
||||||
baseUrl.searchParams.append('page', page.toString());
|
baseUrl.searchParams.append('page', page.toString());
|
||||||
|
|
||||||
|
// 构建配置对象
|
||||||
|
const config = {
|
||||||
|
username,
|
||||||
|
token,
|
||||||
|
perPage,
|
||||||
|
url
|
||||||
|
};
|
||||||
|
|
||||||
baseUrl.searchParams.append('config', JSON.stringify(config));
|
baseUrl.searchParams.append('config', JSON.stringify(config));
|
||||||
|
|
||||||
if (effectiveUsername) {
|
if (username) {
|
||||||
baseUrl.searchParams.append('username', effectiveUsername);
|
baseUrl.searchParams.append('username', username);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (organization) {
|
if (organization) {
|
||||||
@ -132,7 +134,7 @@ const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchData(1);
|
fetchData(1);
|
||||||
}, [platform, effectiveUsername, organization]);
|
}, [platform, username, organization, token, perPage, url]);
|
||||||
|
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
if (isPageChanging) return;
|
if (isPageChanging) return;
|
||||||
@ -219,7 +221,7 @@ const GitProjectCollection: React.FC<GitProjectCollectionProps> = ({
|
|||||||
<div className="git-project-collection max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
<div className="git-project-collection max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
<h2 className="text-2xl font-bold mb-6 text-primary-700">
|
<h2 className="text-2xl font-bold mb-6 text-primary-700">
|
||||||
{displayTitle}
|
{displayTitle}
|
||||||
{effectiveUsername && <span className="ml-2 text-secondary-500">(@{effectiveUsername})</span>}
|
{username && <span className="ml-2 text-secondary-500">(@{username})</span>}
|
||||||
{organization && <span className="ml-2 text-secondary-500">(组织: {organization})</span>}
|
{organization && <span className="ml-2 text-secondary-500">(组织: {organization})</span>}
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -14,6 +14,7 @@ tags: []
|
|||||||
4. **项目展示**:支持展示 GitHub、Gitea 和 Gitee 的项目
|
4. **项目展示**:支持展示 GitHub、Gitea 和 Gitee 的项目
|
||||||
5. **观影记录**:集成豆瓣观影数据
|
5. **观影记录**:集成豆瓣观影数据
|
||||||
6. **读书记录**:集成豆瓣读书数据
|
6. **读书记录**:集成豆瓣读书数据
|
||||||
|
7. **旅行足迹**:支持展示全球旅行足迹热力图
|
||||||
|
|
||||||
## 基础配置
|
## 基础配置
|
||||||
|
|
||||||
@ -42,6 +43,9 @@ export const PSB_ICP_URL = '备案链接';
|
|||||||
|
|
||||||
// 豆瓣配置
|
// 豆瓣配置
|
||||||
export const DOUBAN_ID = '你的豆瓣ID';
|
export const DOUBAN_ID = '你的豆瓣ID';
|
||||||
|
|
||||||
|
// 旅行足迹
|
||||||
|
export const VISITED_PLACES = ['中国-北京', '中国-上海', '美国-纽约'];
|
||||||
```
|
```
|
||||||
|
|
||||||
## 文章写作
|
## 文章写作
|
||||||
@ -110,23 +114,17 @@ tags: ["标签1", "标签2"]
|
|||||||
```astro
|
```astro
|
||||||
---
|
---
|
||||||
import GitProjectCollection from '@/components/GitProjectCollection';
|
import GitProjectCollection from '@/components/GitProjectCollection';
|
||||||
import { GitPlatform, type GitConfig } from '@/components/GitProjectCollection';
|
import { GitPlatform } from '@/components/GitProjectCollection';
|
||||||
|
|
||||||
// Gitea 配置示例
|
|
||||||
const giteaConfig: GitConfig = {
|
|
||||||
username: 'your-username', // 必填:用户名
|
|
||||||
token: 'your-token', // 可选:访问令牌,用于访问私有仓库
|
|
||||||
perPage: 10, // 可选:每页显示数量,默认 10
|
|
||||||
url: 'your-git-url' // Gitea 必填,GitHub/Gitee 无需填写
|
|
||||||
};
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<GitProjectCollection
|
<GitProjectCollection
|
||||||
platform={GitPlatform.GITEA} // 平台类型:GITHUB、GITEA、GITEE
|
platform={GitPlatform.GITEA} // 平台类型:GITHUB、GITEA、GITEE
|
||||||
username="your-username" // 可选:覆盖 config 中的用户名
|
username="your-username" // 必填:用户名
|
||||||
title="Git 项目" // 显示标题
|
title="Git 项目" // 可选:显示标题
|
||||||
config={giteaConfig} // 平台配置
|
url="https://your-gitea.com" // 可选:Gitea 实例 URL(Gitea 必填,GitHub/Gitee 无需填写)
|
||||||
client:load // Astro 指令:客户端加载
|
token="your-token" // 可选:访问令牌,用于访问私有仓库
|
||||||
|
perPage={10} // 可选:每页显示数量,默认 10
|
||||||
|
client:load // Astro 指令:客户端加载
|
||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -158,6 +156,53 @@ import MediaGrid from '@/components/MediaGrid.astro';
|
|||||||
/>
|
/>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## 旅行足迹
|
||||||
|
|
||||||
|
### WorldHeatmap 组件
|
||||||
|
|
||||||
|
`WorldHeatmap` 组件用于展示你去过的地方,以热力图的形式在世界地图上显示。
|
||||||
|
|
||||||
|
#### 基本用法
|
||||||
|
|
||||||
|
在 `src/consts.ts` 中配置你去过的地方:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
// 配置你去过的地方
|
||||||
|
export const VISITED_PLACES = [
|
||||||
|
// 国内地区格式:'中国-省份/城市'
|
||||||
|
'中国-黑龙江',
|
||||||
|
'中国-北京',
|
||||||
|
'中国-上海',
|
||||||
|
// 国外地区直接使用国家名
|
||||||
|
'马来西亚',
|
||||||
|
'泰国',
|
||||||
|
'美国'
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
|
然后在页面中使用:
|
||||||
|
|
||||||
|
```astro
|
||||||
|
---
|
||||||
|
import Layout from "@/components/Layout.astro";
|
||||||
|
import WorldHeatmap from '@/components/WorldHeatmap';
|
||||||
|
import { VISITED_PLACES } from '@/consts';
|
||||||
|
---
|
||||||
|
|
||||||
|
<Layout title="旅行足迹">
|
||||||
|
<section>
|
||||||
|
<h2 class="text-3xl font-semibold text-center mb-6">我的旅行足迹</h2>
|
||||||
|
<div class="mx-auto bg-white dark:bg-gray-800 rounded-xl shadow-lg p-6">
|
||||||
|
<WorldHeatmap
|
||||||
|
client:only="react"
|
||||||
|
visitedPlaces={VISITED_PLACES}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</Layout>
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## 主题切换
|
## 主题切换
|
||||||
|
|
||||||
系统支持三种主题模式:
|
系统支持三种主题模式:
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
---
|
---
|
||||||
import Layout from '@/components/Layout.astro';
|
import Layout from '@/components/Layout.astro';
|
||||||
import GitProjectCollection from '@/components/GitProjectCollection';
|
import GitProjectCollection from '@/components/GitProjectCollection';
|
||||||
import { GitPlatform, type GitConfig } from '@/components/GitProjectCollection';
|
import { GitPlatform } from '@/components/GitProjectCollection';
|
||||||
|
|
||||||
const giteaConfig: GitConfig = {
|
|
||||||
username: 'lsy',
|
|
||||||
url: 'https://g.lsy22.com',
|
|
||||||
};
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout title="项目 | echoes">
|
<Layout title="项目 | echoes">
|
||||||
@ -16,7 +11,7 @@ const giteaConfig: GitConfig = {
|
|||||||
platform={GitPlatform.GITEA}
|
platform={GitPlatform.GITEA}
|
||||||
username="lsy"
|
username="lsy"
|
||||||
title="Gitea 个人项目"
|
title="Gitea 个人项目"
|
||||||
config={giteaConfig}
|
url="https://g.lsy22.com"
|
||||||
client:load
|
client:load
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user