前言
当你的hexo站点部署到github上以后,如果访问的链接不存在的话,github是有默认的404页面的。

但是这是不能满足我们的爱美之心的,其次我想要5秒后自动跳转回我的博客首页怎么办?
处理方案
1、创建404page
在博客主目录运行起cmd窗口,使用下面命令生成404page
2、编辑404页面
然后将下面的内容复制到source/404/index.md
文件内。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| --- title: '404 - 好巧,竟然在这里遇到你!' date: 2022-01-22 20:02:00 comments: false permalink: /404.html ---
<!-- markdownlint-disable MD039 MD033 -->
对不起,您所访问的页面不存在或者已删除。
预计将在约 <span id="timeout">5</span> 秒后返回首页。
当然,你可以 **[点这里](你的首页连接)** 直接返回首页。
<script> let countTime = 5;
function count() {
document.getElementById('timeout').textContent = countTime; countTime -= 1; if(countTime === 0){ location.href = '你的首页连接'; } setTimeout(() => { count(); }, 1000); }
count(); </script>
|
3、生成站点并运行
1 2 3
| hexo clean hexo generate hexo serve
|
4、验证404页面
本地的话需要使用http://localhost:4000/404.html
进行测试,部署到github上的话可以随意修改链接验证。