diff --git a/src/content.config.ts b/src/content.config.ts index 2604116..6a75420 100644 --- a/src/content.config.ts +++ b/src/content.config.ts @@ -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' : ''; diff --git a/src/pages/articles/[...id].astro b/src/pages/articles/[...id].astro index d9a4022..d7818c5 100644 --- a/src/pages/articles/[...id].astro +++ b/src/pages/articles/[...id].astro @@ -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; } } diff --git a/src/pages/articles/index.astro b/src/pages/articles/index.astro index ede48bf..5aba13a 100644 --- a/src/pages/articles/index.astro +++ b/src/pages/articles/index.astro @@ -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 ( + +
+
+ + + +
+
+

{articleWithSpecialPath.data.title}

+ {articleWithSpecialPath.body && ( +

+ {extractSummary(articleWithSpecialPath.body)} +

+ )} +
+ + 阅读全文 +
+
+
+
+ ); + } + return (
@@ -405,7 +438,7 @@ function getArticleUrl(articleId: string) {

文章不存在

ID: {articleId}

- 可用文章: {articles.map(a => a.id).join(', ')} + 可能需要特殊路径处理,请检查文件名是否与目录名相同或包含目录名
@@ -485,7 +518,7 @@ function getArticleUrl(articleId: string) { ) : ( - + )}