Linux搭建Hexo博客
2024-10-27🌱湖州: 🌦 🌡️+16°C 🌬️↓12km/h
更新源
添加源,终端输入:
sudo vim /etc/apt/sources.list
下列源选择部分添加:
官方源
deb http://http.kali.org/kali kali-rolling main non-free contrib
deb-src http://http.kali.org/kali kali-rolling main non-free contrib
中科大源
deb http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib
deb-src http://mirrors.ustc.edu.cn/kali kali-rolling main non-free contrib阿里云源
deb http://mirrors.aliyun.com/kali kali-rolling main non-free contrib
deb-src http://mirrors.aliyun.com/kali kali-rolling main non-free contrib清华大学源
deb http://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free
deb-src https://mirrors.tuna.tsinghua.edu.cn/kali kali-rolling main contrib non-free
浙大源
deb http://mirrors.zju.edu.cn/kali kali-rolling main contrib non-free
deb-src http://mirrors.zju.edu.cn/kali kali-rolling main contrib non-free
东软大学源
deb http://mirrors.neusoft.edu.cn/kali kali-rolling/main non-free contrib
deb-src http://mirrors.neusoft.edu.cn/kali kali-rolling/main non-free contrib
新加坡kali源
deb http://mirror.nus.edu.sg/kali/kali/ kali main non-free contrib
deb-src http://mirror.nus.edu.sg/kali/kali/ kali main non-free contrib
163 Kali源
deb http://mirrors.163.com/debian wheezy main non-free contrib
deb-src http://mirrors.163.com/debian wheezy main non-free contrib
apt-get update更新
下载依赖
git自带
node
1
apt install node
npm
1
apt install npm
hexo-cli
1
npm install -g hexo-cli`
新建博客目录
1 | hexo init |
下载插件
- 上传GitHub插件
npm install hexo-deployer-git
- 插入图片插件
npm install https://github.com/CodeFalling/hexo-asset-image
- 图片插件下载好后需要将根目录中的config文件的post_asset_folder改成true
注意:这些一定要安装好,不要只是配一下环境变量,从头安装保险一点
hexo主题
hexo-theme-yilia-plus
下载
cd ./themes/
git clone –depth=1 https://github.com/JoeyBling/hexo-theme-yilia-plus.git
显示文章的部分内容
显示文章的部分内容
1 | <!-- more --> |
更新
1 | cd themes/yilia-plus |
使用想要的主题需要在config文件配置theme的名称
hexo-theme-reimu
https://github.com/D-Sketon/hexo-theme-reimu?tab=readme-ov-file
hexo-theme-anzhiyu
Git 安裝
在博客根目录里安装最新版【推荐】
1 | git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu |
应用主题
修改 hexo 配置文件_config.yml,把主题改为anzhiyu
1 | theme: anzhiyu |
如果你没有 pug 以及 stylus 的渲染器,请下载安装:
npm install hexo-renderer-pug hexo-renderer-stylus --save
覆盖配置
覆盖配置可以使主题配置放置在 anzhiyu 目录之外,避免在更新主题时丢失自定义的配置。
通过 Npm 安装主题的用户可忽略,其他用户建议学习使用。
- macos/linux 在博客根目录运行
1 | cp -rf ./themes/anzhiyu/_config.yml ./_config.anzhiyu.yml |
- windows 复制
/themes/anzhiyu/_config.yml此文件到 hexo 根目录,并重命名为_config.anzhiyu.yml
以后如果修改任何主题配置,都只需修改 _config.anzhiyu.yml 的配置即可。
注意:
- 只要存在于
_config.anzhiyu.yml的配置都是高优先级,修改原_config.yml是无效的。 - 每次更新主题可能存在配置变更,请注意更新说明,可能需要手动对
_config.anzhiyu.yml同步修改。 - 想查看覆盖配置有没有生效,可以通过
hexo g --debug查看命令行输出。 - 如果想将某些配置覆盖为空,注意不要把主键删掉,不然是无法覆盖的
butterfly
官方文档
https://butterfly.js.org/posts/21cfbf15/
hexo基础操作
- 启动本地服务
1 | hexo -s |
清理缓存
1
hexo clean
生成静态文件
1
hexo g
推送到github
1
hexo d
新建文章
1
hexo n "文件名"
hexo进阶
添加分类
1 | hexo new page categories |
然后再去生成的source\categories中的index.md中添加type: categories
然后在文章的头中添加分类属性即可,只能有一个分类
改变新建文件的模板
scaffolds目录中储存的是新建文件的模板,添加categories属性,这样新建文件的时候就会有这个属性了
部署到github
- _config.yml文件配置
在文件的最后一行添加这个配置
1 | deploy: |
- 在本地生成新的sshkey文件
输入命令:cd ~/.ssh进入.ssh文件夹
输入命令:ssh-keygen -t rsa -C '注册时的邮箱地址'
- 然后到GitHub,去设置里面将生成的pub文件的内容粘贴到新建的ssh中
输入命令(git):ssh -T git@github.com 并且输入yes之后,行末尾会显示你的用户名
接着在本地绑定与Github的用户名和邮箱(git)
输入命令:git config –global user.name “注册时用户名”
输入命令:git config –global user.email “注册时邮箱”
随机图床
https://t.mwm.moe/moe/
https://t.mwm.moe/fj
http://www.98qy.com/sjbz/api.php





