博客搭建教程视频地址:https://www.bilibili.com/video/BV1nY6xYmEw7?buvid=YD44F3D7CA9FF4654EA985A08644F4A38FB0&from_spmid=tm.recommend.0.0&is_story_h5=false&mid=QY8SLP3aFxWc3ZZhivkAwX8FTQ%2FSZMtL1rElX6M3iMo%3D&plat_id=116&share_from=ugc&share_medium=iphone&share_plat=ios&share_session_id=977D55C6-F8AF-4D06-88FF-5BF8DBEDBED8&share_source=COPY&share_tag=s_i&spmid=united.player-video-detail.0.0×tamp=1735960479&unique_k=MFZ2A8W&up_id=258944527&vd_source=2faa5edeffeb71a8abb2307ca70fa880
1、环境准备
1 2 3 4
| nodejs-18以上,git
node -v npm -v
|
2、安装hexo客户端
1 2 3
| hexo是一个静态的博客框架,托管与gitee
npm config set registry https://registry.npmmirror.com
|
安装hexo客户端
使用hexo初始化一个文件夹,名字可以自定义,用于存放博客文章的文件夹
安装依赖包
前期准备完成,install完后会生成以下文件
1 2 3
| [root@localhost my-blog]# ls _config.fluid.yml _config.yml node_modules package-lock.json README.en.md scaffolds themes _config.landscape.yml db.json package.json public README.md source
|
3、配置文件简介
1 2 3
| _config.yaml:主文件夹,有博客名,作者等信息 source/_posts:用于存放我们文章的目录 themes:目录下存放的的博客的主题配置文件
|
4、启动hexo
1 2
| # 启动预览博客页面 hexo generate && hexo server
|
会生成个登入地址,用于在页面访问
5、创建gitee/githup仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
git init
git remote add origin git@github.com:xubaodong0511/xubaodong0511.github.io.git
git remote set-url origin git@github.com:xubaodong0511/blog.io.git
git remote -v
Host github.com Hostname ssh.github.com Port 443
git clone git@github.com:xubaodong0511/blog.io.git git push -u origin main --force
|
6、修改配置文件
1 2 3 4 5 6 7 8 9
| deploy: type: '' repository: git@github.com:xubaodong0511/xubaodong0511.github.io.git branch: main 注释:使用cursor运行hexo时会有管理员权限问题 解决:退出重新以管理员身份运行,并执行`Set-ExecutionPolicy RemoteSigned`,如果有选择输入Y
|
7、创建、及发布文章
1 2 3 4
| [root@localhost my-blog] INFO Validating config INFO Created: ~/my-blog/source/_posts/我的第一篇博客.md
|
安装hexo-git插件
1
| npm install hexo-deployer-git
|
发布文章
1 2 3
| hexo clean && hexo generate && hexo deploy 或 hexo c && hexo g && hexo d
|
8、cloudflare托管网站,域名代理
1 2 3 4 5 6 7 8 9 10
| # 点击worker和pages # 选择pages # 点击连接到git # 选择githup或gitee # 选第二个,only select repositories(选择仓库) # 授权 # 确认仓库,开始设置 # 确认分支,保存设置开始部署 # 继续处理项目 # 自定义域
|
9、设置主题
1 2 3 4 5 6 7 8 9 10 11 12
| githup上搜索hexo-theme-fluid 或直接打开以下地址 https://github.com/fluid-dev/hexo-theme-fluid?tab=readme-ov-file
方式一: # Hexo 5.0.0 版本以上,推荐通过 npm 直接安装,进入博客目录执行命令: npm install --save hexo-theme-fluid 然后在博客目录下创建 _config.fluid.yml,将主题的 _config.yml 内容复制进去。 方式二: # 修改 Hexo 博客目录中的 _config.yml: theme: fluid # 指定主题 language: zh-CN # 指定语言,会影响主题显示的语言,按需修改
|
主题配置
1 2 3 4 5 6 7 8
| hexo new page about 创建成功后,编辑博客目录下 /source/about/index.md,添加 layout 属性。 修改后的文件示例如下: --- title: about layout: about ---
|
重新启动hexo
1
| hexo clean && hexo generate && hexo deploy
|
10、设置文章的标签
1 2 3 4 5 6
| --- title: gicc升级 date: 2025-01-05 tags: [Linux运维,系统] ---
|
11、增加评论功能
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| https://github.com/apps/utterances
post: comments: enable: true type: utterances
utterances: repo: xubaodong0511/xubaodong0511.github.io issue_term: pathname label: utterances theme: github-light theme_dark: github-dark crossorigin: anonymous
|
12、重启hexo
1 2 3 4
| # 启动hexo hexo clean && hexo generate && hexo server 或 nohup hexo clean && hexo generate && hexo server &
|