2025-03-09 14:37:44 +08:00
|
|
|
|
---
|
|
|
|
|
import ArticlesPage, { getStaticPaths as getOriginalPaths } from './index.astro';
|
|
|
|
|
|
|
|
|
|
// 重新导出 getStaticPaths,处理所有路径模式
|
|
|
|
|
export async function getStaticPaths() {
|
|
|
|
|
const paths = await getOriginalPaths();
|
|
|
|
|
const allPaths = paths.map(({ props }) => {
|
|
|
|
|
const results = [];
|
|
|
|
|
|
|
|
|
|
// 1. 如果有标签,添加标签路径
|
|
|
|
|
if (props.tag) {
|
|
|
|
|
// 标签主页
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: `tag/${props.tag}` },
|
|
|
|
|
props: { ...props }
|
|
|
|
|
});
|
|
|
|
|
// 标签视图页
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: `tag/${props.tag}/grid` },
|
|
|
|
|
props: { ...props, view: 'grid' }
|
|
|
|
|
});
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: `tag/${props.tag}/timeline` },
|
|
|
|
|
props: { ...props, view: 'timeline' }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. 如果有路径,添加目录路径
|
|
|
|
|
if (props.path) {
|
|
|
|
|
// 目录主页
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: props.path },
|
|
|
|
|
props: { ...props }
|
|
|
|
|
});
|
|
|
|
|
// 目录视图页
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: `${props.path}/grid` },
|
|
|
|
|
props: { ...props, view: 'grid' }
|
|
|
|
|
});
|
|
|
|
|
results.push({
|
|
|
|
|
params: { path: `${props.path}/timeline` },
|
|
|
|
|
props: { ...props, view: 'timeline' }
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}).flat();
|
|
|
|
|
|
|
|
|
|
// 添加顶级视图路径
|
|
|
|
|
allPaths.push(
|
|
|
|
|
{
|
|
|
|
|
params: { path: 'grid' },
|
|
|
|
|
props: { path: '', tag: '', view: 'grid' }
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
params: { path: 'timeline' },
|
|
|
|
|
props: { path: '', tag: '', view: 'timeline' }
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return allPaths;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用主页面组件
|
|
|
|
|
const { props } = Astro;
|
|
|
|
|
|
|
|
|
|
// 解析路径参数
|
|
|
|
|
const pathParts = (Astro.params.path as string | undefined)?.split('/') || [];
|
2025-03-10 17:35:21 +08:00
|
|
|
|
|
|
|
|
|
// 初始化变量
|
2025-03-09 14:37:44 +08:00
|
|
|
|
let path = '';
|
|
|
|
|
let tag = '';
|
|
|
|
|
let view = 'grid';
|
|
|
|
|
|
|
|
|
|
if (pathParts[0] === 'tag' && pathParts.length >= 2) {
|
2025-03-10 17:35:21 +08:00
|
|
|
|
// 标签路径处理
|
2025-03-09 14:37:44 +08:00
|
|
|
|
tag = pathParts[1];
|
|
|
|
|
view = pathParts[2] || 'grid';
|
|
|
|
|
} else {
|
2025-03-10 17:35:21 +08:00
|
|
|
|
// 处理普通路径和视图
|
|
|
|
|
const lastPart = pathParts[pathParts.length - 1];
|
|
|
|
|
|
|
|
|
|
if (['grid', 'timeline'].includes(lastPart)) {
|
|
|
|
|
// 如果最后一部分是视图类型,则移除它并设置视图
|
|
|
|
|
view = lastPart;
|
|
|
|
|
pathParts.pop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 剩余的部分都作为路径
|
|
|
|
|
path = pathParts.join('/');
|
2025-03-09 14:37:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 合并属性
|
|
|
|
|
const mergedProps = {
|
|
|
|
|
...props,
|
|
|
|
|
path,
|
|
|
|
|
tag,
|
|
|
|
|
view
|
|
|
|
|
};
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<ArticlesPage {...mergedProps} />
|