上一个版本写错了,应该为静态构建
修复大部分文章显示找不到文章问题
This commit is contained in:
parent
d3ea05700c
commit
a474298866
@ -93,7 +93,7 @@ export function getSpecialPath(originalPath: string): string {
|
||||
// 如果文件名与目录名相同或以目录名开头,则在文件名前添加特殊前缀
|
||||
if (parts.length > 1) {
|
||||
const dirName = parts[parts.length - 2];
|
||||
if (fileName === dirName || fileName.startsWith(dirName)) {
|
||||
if (fileName.toLowerCase() === dirName.toLowerCase() || fileName.toLowerCase().startsWith(dirName.toLowerCase())) {
|
||||
// 创建一个新的路径,在文件名前添加下划线前缀
|
||||
const newFileName = fileName.startsWith('_') ? fileName : `_${fileName}`;
|
||||
const fileExt = originalPath.endsWith('.md') ? '.md' : '';
|
||||
|
@ -35,14 +35,14 @@ export async function getStaticPaths() {
|
||||
`articles/${sectionPath}/${basename}` // 添加集合名称前缀和目录路径
|
||||
];
|
||||
|
||||
// 精确匹配
|
||||
if (possibleIds.includes(articleId)) {
|
||||
// 精确匹配(不区分大小写)
|
||||
if (possibleIds.some(id => id.toLowerCase() === articleId.toLowerCase())) {
|
||||
return sectionPath;
|
||||
}
|
||||
|
||||
// 检查文章ID是否以某个可能的ID结尾
|
||||
// 检查文章ID是否以某个可能的ID结尾(不区分大小写)
|
||||
for (const possibleId of possibleIds) {
|
||||
if (articleId.endsWith(possibleId)) {
|
||||
if (articleId.toLowerCase().endsWith(possibleId.toLowerCase())) {
|
||||
return sectionPath;
|
||||
}
|
||||
}
|
||||
|
@ -349,26 +349,26 @@ function getArticleUrl(articleId: string) {
|
||||
// 尝试不同的方式匹配文章
|
||||
const article = articles.find(a => {
|
||||
// 1. 直接匹配完整路径
|
||||
if (a.id === articleId) {
|
||||
if (a.id.toLowerCase() === articleId.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 2. 匹配文件名(不含路径和扩展名)
|
||||
const baseName = getBasename(articleId);
|
||||
if (a.id === baseName) {
|
||||
if (a.id.toLowerCase() === baseName.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 3. 尝试匹配相对路径的一部分
|
||||
const articleParts = articleId.split('/');
|
||||
const fileName = articleParts[articleParts.length - 1];
|
||||
if (a.id.endsWith(fileName)) {
|
||||
if (a.id.toLowerCase().endsWith(fileName.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 4. 移除.md扩展名后匹配
|
||||
const idWithoutExt = articleId.replace(/\.md$/, '');
|
||||
if (a.id === idWithoutExt) {
|
||||
if (a.id.toLowerCase() === idWithoutExt.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -379,13 +379,13 @@ function getArticleUrl(articleId: string) {
|
||||
const articleIdParts = a.id.split('/');
|
||||
const articleIdFileName = articleIdParts[articleIdParts.length - 1];
|
||||
|
||||
if (articleFileName === articleIdFileName) {
|
||||
if (articleFileName.toLowerCase() === articleIdFileName.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 6. 移除扩展名后比较文件名
|
||||
const fileNameWithoutExt = articleFileName.replace(/\.md$/, '');
|
||||
if (articleIdFileName === fileNameWithoutExt) {
|
||||
if (articleIdFileName.toLowerCase() === fileNameWithoutExt.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -393,6 +393,39 @@ function getArticleUrl(articleId: string) {
|
||||
});
|
||||
|
||||
if (!article) {
|
||||
// 尝试直接使用 getSpecialPath 处理文章ID
|
||||
const specialId = getSpecialPath(articleId);
|
||||
const articleWithSpecialPath = articles.find(a => a.id.toLowerCase() === specialId.toLowerCase());
|
||||
|
||||
if (articleWithSpecialPath) {
|
||||
return (
|
||||
<a href={getArticleUrl(articleWithSpecialPath.id)}
|
||||
class="group flex flex-col h-full p-5 border border-gray-200 dark:border-gray-700 rounded-xl bg-white dark:bg-gray-800 hover:shadow-xl hover:-translate-y-1 transition-all duration-300 shadow-lg">
|
||||
<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">{articleWithSpecialPath.data.title}</h3>
|
||||
{articleWithSpecialPath.body && (
|
||||
<p class="text-xs text-gray-600 mt-1 line-clamp-2">
|
||||
{extractSummary(articleWithSpecialPath.body)}
|
||||
</p>
|
||||
)}
|
||||
<div class="text-xs text-gray-500 mt-2 flex items-center justify-between">
|
||||
<time datetime={articleWithSpecialPath.data.date.toISOString()}>
|
||||
{articleWithSpecialPath.data.date.toLocaleDateString('zh-CN', {year: 'numeric', month: 'long', day: 'numeric'})}
|
||||
</time>
|
||||
<span class="text-primary-600 font-medium">阅读全文</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="flex flex-col h-full p-5 border border-red-200 rounded-xl bg-red-50 shadow-lg">
|
||||
<div class="flex items-start">
|
||||
@ -405,7 +438,7 @@ function getArticleUrl(articleId: string) {
|
||||
<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>
|
||||
@ -485,7 +518,7 @@ function getArticleUrl(articleId: string) {
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<ArticleTimeline title="" itemsPerPage={10} articles={sortedArticles} />
|
||||
<ArticleTimeline title="" articles={sortedArticles} />
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user