Skip to content

Commit

Permalink
添加根目录 404 页面
Browse files Browse the repository at this point in the history
  • Loading branch information
qianmoQ committed Jan 1, 2025
1 parent bd53060 commit ee7b161
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions lib/directory-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,37 @@ class DirectoryProcessor {
}

createRootRedirect() {
const root404Html = `<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script>
var anchor = document.createElement("a");
anchor.href = window.location.href;
var path = anchor.pathname;
if (path.indexOf(".html") === -1) {
path = path.replace(/\/$/, "");
path = path + ".html";
}
var lang = path.split("/")[1];
var supportedLanguages = ${JSON.stringify(this.getAvailableLocales().map(l => l.key))};
if (supportedLanguages.includes(lang)) {
window.location.replace("/" + lang + "/404.html");
} else {
window.location.replace("/zh-CN/404.html");
}
</script>
</head>
<body></body>
</html>`;

const root404Path = path.join(this.config.outputPath, '404.html');
fs.writeFileSync(root404Path, root404Html);
console.log('✓ 创建根目录 404 页面:', root404Path);

const defaultLanguage = this.config.i18n?.default || 'zh-CN';

// 创建一个极简的重定向页面
Expand Down

0 comments on commit ee7b161

Please sign in to comment.