准备事项
NodeJS下载安装, 配置淘宝源
1 2 3 npm config set registry https://registry.npmmirror.com npm config get registry npm config list
Git客户端下载安装
VScode下载安装
GitHub
注册账号, 新建项目需要
Cloudflare
注册一个账号, 地址: Cloudflare
域名(可选)
最好有一个自己的域名, 可以去https://www.namesilo.com注册 , top域名和xyz域名首年1.88$, 如果有油管博主的邀请码, 可以低至1$, 域名注册后托管到Cloudflare, 参考这个油管博主的域名购买和托管部分 。
GitHub配置 创建项目 项目1: Hexo-Config
项目2: Hexo-Static
配置验证 导入本地密钥
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 git config -l git config --system -l git config --global -l git config --global user.name wangshui898 git config --global user.email wangshui898@gmail.com git config --global credential.helper store 密钥生成: ssh-keygen -t rsa -C "你的邮箱" 配置密钥: - 本机: 编辑 -> C:/用户/<用户名>/.ssh/id_rsa.pub, 复制内容 - Github: 头像-> setting -> SSH and GPG Keys -> New SSH key -> 起名+粘贴内容 测试github联通性 ssh -T git@github.com
Hexo本地部署 1. Hexo仓库克隆
打开vscode, 选择克隆仓库
输入仓库地址进行克隆, 克隆时选择本地目录
创建.gitignore, 排除node+modules目录, 防止上传node_modules目录和主题目录(有的主题目录不让上传 , 导致报错)到GitHub
上面步骤可以简化, 根据自己需求来, 我是为了把Hexo的配置上传到GtiHub, 防丢失, 也可以省略(省略的话直接创建一个Heox目录, 直接用vscode打开即可)
2. Hexo本地安装
安装hexo依赖
1 2 ctrl + ~打开终端 npm install -g hexo-cli && hexo -v
初始化Hexo
1 2 3 hexo init wangshui898-config cd wangshui898-confignpm i
3. 本地启动命令 1 2 3 4 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config hexo cl && hexo s
访问地址: http://localhost:4000 (如果css样式无法加载请检查是否使用了中文路径)
Hexo远程部署 1. 部署到GitHub Pages
安装插件(需要插件hexo-deployer-git)
1 2 cd wangshui898-config npm install hexo-deployer-git --save
编辑配置(bolog-config/_config.yml)
1 2 3 4 5 1. 修改deploy字段 deploy: type: git repository: git@github.com:<用户名>/<仓库名>.git branch: main
1 2 2. 修改URL字段(后面部署到CF时候, 就改成自己的域名) url: https://<用户名>.github.io/<仓库名>
发布到GitHub
1 2 3 4 5 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config hexo cl; hexo g; hexo d
访问验证
1 https://<用户名>.github.io/<仓库名称>
如果访问404 进入项目的setting->pages->选择分支-> save保存即可
2. 部署到Cloudflare Pages
创建Pages
1 Workers 和 Pages-> 创建 -> Pages -> 连接到Git-> 连接到GitHub
GitHub仓库授权
选择存储库
选择分支, 开始部署
绑定域名
1 选择Pages-> 自定义域 -> 设置自定义域 ->输入自己域名
配置域名
激活域名
修改_config.yml配置
1 URL字段修改自定义域的域名, 重新发布, 即可生效
3. 远程发布命令 1 2 3 4 5 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config hexo cl; hexo g; hexo d
基础配置 目录结构 source目录 /source主要用来放置标签页配置文件, 每次使用hexo new page xxx命令创建新标签页, 则会在source下生成对应名称的目录, 这个目录最后可以配置在_config.xxx.yml主题配置文件中作为一级标签页或者二级标签页
_posts博文目录 _posts主要用来存放创建的博文, 博文创建命令:
scaffolds目录 /scaffolds目录下有几个模版文件,其中
post.md :新建博文模版
page.md :新建标签页模版
post.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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 --- title: {{ title }} date: {{ date }} updated: tags: categories: keywords: description: top: top_img: comments: cover: toc: toc_number: toc_style_simple: copyright: copyright_author: copyright_author_href: copyright_url: copyright_info: mathjax: katex: aplayer: highlight_shrink: aside: swiper_index: 10 top_group_index: 10 ai: background: "#fff" --- <div class="video-container"> [up主专用,视频内嵌代码贴在这 ] </div> <style> .video-container { position: relative; width: 100 %; padding-top: 56.25 %; /* 16 :9 aspect ratio (height/width = 9 /16 * 100 %) */ } .video-container iframe { position: absolute; top: 0 ; left: 0 ; width: 100 %; height: 100 %; } </style>
page.md标签页模版 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 --- title: {{ title }} date: {{ date }} type: updated: comments: description: keywords: top_img: mathjax: katex: aside: aplayer: highlight_shrink: top_single_background: ---
关于类型 新建标签页还可以配置类型, 如标签(tags),分类(categories), 归档(archives)等, 比如type配置tags, 点击后就会列出所有标签, 配置文件在source/xxx/index.md, 配置字段为type, 示例:
1 2 3 4 5 6 --- title: 标签页 date: 2024-11-27 15:26:02 type: "tags" ---
categories类型配置 1 2 3 4 5 6 --- title: 分类页 date: 2024-11-27 15:26:02 type: "categories" ---
archives类型 1 2 3 4 5 --- title: 归档页 date: 2024-11-27 15:26:02 type: "archives" ---
基础配置 网站相关设置 此配置在_config.yml, 修改如下代码
1 2 3 4 5 6 7 8 title: 我的Hexo博客 subtitle: '' description: '' keywords: author: 消磨_时间 language: zh-CN timezone: 'Asia/Shanghai'
标签页相关配置 标签页实际展示方式以及层级配置, 配置在_config.xxx.yml中, 例如:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 menu: 首页: / || fas fa-house 技术分享 || fas fa-square-share-nodes: 开源免费: /categories/开源免费/ || fas fa-comment-dollar 科学上网: /categories/科学上网/ || fas fa-plane-departure 实用工具: /categories/实用工具/ || fas fa-gear 绿色破解: /categories/绿色破解/ || fas fa-clover 运维专栏 || fas fa-toolbox: 系统: /categories/系统/ || fas fa-computer 容器: /categories/容器/ || fas fa-boxes-stacked 监控: /categories/监控/ || fas fa-heart-pulse web平台: /categories/web平台/ || fas fa-globe 高可用: /categories/高可用/ || fas fa-network-wired 大数据: /categories/大数据/ || fas fa-chart-simple 数据库: /categories/数据库/ || fas fa-database 平台管理: /categories/平台管理/ || fas fa-server DevOps: /categories/DevOps/ || fas fa-terminal 我的博客 ||fas fa-blog: 标签: /tags/ || fas fa-tags 分类: /categories/ || fas fa-folder-open 归档: /archives/ || fas fa-archive
文章置顶功能 1 2 npm install hexo-generator-topindex --save
设置置顶, 给需要置顶的文章加入top参数,如果存在多个置顶文章,top后的参数越大,越靠前。如下:
1 2 3 4 5 6 7 8 9 --- title: 这是一个需要置顶的微博 date: 2024-11-27 16:36:11 top: 1 categories: - 运维 tags: - 创建一个标签 ---
开启搜索功能 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 npm install hexo-generator-search --save search: use: local_search placeholder: local_search: enable: true preload: false top_n_per_article: 1 unescape: false CDN:
博文唯一路径 1 2 npm install hexo-abbrlink --save
修改站点配置文件_config.yml中permalink属性
1 2 3 4 permalink: post/:abbrlink.html abbrlink: alg: crc32 rep: hex
其他配置 1 2 3 4 category_ui: index tag_ui: index
主题安装 butterfly主题
安装主题
1 2 3 4 5 6 7 8 9 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly npm install hexo-renderer-pug hexo-renderer-stylus --save
拷贝配置: 复制butterfly主题的themes/butterfly/_config.yml到根目录_config.butterfly.yml, 之后就主题修改只需要修改_config.butterfly.yml就可以了
anzhiyu主题
安装主题
1 2 3 4 5 6 7 8 9 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config git clone -b main https://github.com/anzhiyu-c/hexo-theme-anzhiyu.git themes/anzhiyu npm install hexo-renderer-pug hexo-renderer-stylus --save
拷贝配置: 复制安知鱼主题的themes/anzhiyu/_config.yml到根目录_config.anzhiyu.yml, 之后就主题修改只需要修改_config.anzhiyu.yml就可以了
应用主题 编辑_config.yml, 修改主题字段
应用示例 创建标签页 创建1个一级标签页技术(technology)和4个二级标签页, 分别是容器(container), 数据库(database), 监控(monitor), 高可用(ha), 二级标签页进入后显示对应分类的文章
创建博文 1 hexo new Cloudflare R2 + WebP Cloud + PicList打造免费个人图床
创建博文后, 每个博文配置好标签和分类, 例如
1 2 3 4 5 6 7 8 9 10 11 12 --- title: Cloudflare R2 + WebP Cloud + PicList打造免费个人图床 swiper_index: 10 top_group_index: 10 background: '#fff' tags: - Cloudflare R2 - WebP Cloud - PicList - Typora categories: - 开源免费
主题配置 butterfly常用配置 配置文件为_config.butterfly.yml
主页相关 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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 menu: menu: 首页: / || fas fa-house 技术分享 || fas fa-square-share-nodes: 开源免费: /categories/开源免费/ || fas fa-comment-dollar 科学上网: /categories/科学上网/ || fas fa-plane-departure 实用工具: /categories/实用工具/ || fas fa-gear 绿色破解: /categories/绿色破解/ || fas fa-clover 运维专栏 || fas fa-toolbox: 系统: /categories/系统/ || fas fa-computer 容器: /categories/容器/ || fas fa-boxes-stacked 监控: /categories/监控/ || fas fa-heart-pulse web平台: /categories/web平台/ || fas fa-globe 高可用: /categories/高可用/ || fas fa-network-wired 大数据: /categories/大数据/ || fas fa-chart-simple 数据库: /categories/数据库/ || fas fa-database 平台管理: /categories/平台管理/ || fas fa-server DevOps: /categories/DevOps/ || fas fa-terminal 我的博客 ||fas fa-blog: 标签: /tags/ || fas fa-tags 分类: /categories/ || fas fa-folder-open 归档: /archives/ || fas fa-archive favicon: /img/favicon.ico avatar: img: /img/avatar-dog.jpg effect: false disable_top_img: false default_top_img: /img/bg_top.png aside: enable: true hide: false button: true mobile: true position: left card_author: enable: true description: button: enable: true icon: fab fa-github text: GitHub地址 link: https://github.com/wangshui898 card_announcement: enable: true content: 这是我的第一条公告 index_layout: 1 index_post_content: method: 2 length: 500 related_post: enable: true limit: 6 date_type: created search: use: local_search placeholder: local_search: enable: true preload: false top_n_per_article: 1 unescape: false CDN: category_ui: index tag_ui: index
最终展示效果
博文相关 1 2 3 4 5 6 7 8 code_blocks: theme: darker macStyle: false height_limit: false word_wrap: false
图标相关 Butterfly 支持 font-awesome v6 图标, 找到对应图标, 找到表达代号即可
图标地址: https://fontawesome.com/v6/search?o=r&m=free
分类磁贴
安装依赖
1 npm install hexo-butterfly-categories-card --save
修改配置
配置文件_config.butterfly.yml, 添加如下
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 categoryBar: enable: true # 开关 priority: 5 #过滤器优先权 enable_page: / # 应用页面 layout: # 挂载容器类型 type: id name: recent-posts index: 0 column: odd # odd:3列 | even:4列 row: 1 #显示行数,默认两行,超过行数切换为滚动显示 message: - descr: Ubuntu指南 cover: https://assets.akilar.top/image/cover1.webp - descr: 玩转Win10 cover: https://assets.akilar.top/image/cover2.webp - descr: 长篇小说连载
主题配色 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 theme_color: enable: true main: '#49B1F5' paginator: '#00c4b6' button_hover: '#FF7242' text_selection: '#00c4b6' link_color: '#99a9bf' meta_color: '#858585' hr_color: '#A4D8FA' code_foreground: '#F47466' code_background: 'rgba(27, 31, 35, .05)' toc_color: '#00c4b6' blockquote_padding_color: '#49b1f5' blockquote_background_color: '#49b1f5' scrollbar_color: '#49b1f5' meta_theme_color_light: 'ffffff' meta_theme_color_dark: '#0d0d0d'
常用命令配置
首页配置 _config.butterfly.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 menu: 首页: / || fas fa-house 技术分享 || fas fa-square-share-nodes: 开源免费: /categories/开源免费/ || fas fa-comment-dollar 科学上网: /categories/科学上网/ || fas fa-plane-departure 实用工具: /categories/实用工具/ || fas fa-gear 绿色破解: /categories/绿色破解/ || fas fa-clover 运维专栏 || fas fa-toolbox: 系统: /categories/系统/ || fas fa-computer 容器: /categories/容器/ || fas fa-boxes-stacked 监控: /categories/监控/ || fas fa-heart-pulse web平台: /categories/web平台/ || fas fa-globe 高可用: /categories/高可用/ || fas fa-network-wired 大数据: /categories/大数据/ || fas fa-chart-simple 数据库: /categories/数据库/ || fas fa-database 平台管理: /categories/平台管理/ || fas fa-server DevOps: /categories/DevOps/ || fas fa-terminal 我的博客 ||fas fa-blog: 标签: /tags/ || fas fa-tags 分类: /categories/ || fas fa-folder-open 归档: /archives/ || fas fa-archive
标签页配置 创建标签页
标签页常用配置
1 2 3 4 5 6 --- title: 标签页 date: 2024-11-27 15:26:02 type: "tags" ---
1 2 3 4 5 6 --- title: 分类页 date: 2024-11-27 15:26:02 type: "categories" ---
1 2 3 4 5 6 --- title: 归档页 date: 2024-11-27 15:26:02 type: "archives" ---
博文配置 创建博文
博文常用配置参数
1 2 3 4 5 6 7 8 9 10 11 title: Hexo + GitHub Pages + Cloudflare Pages打造免费个人博客 swiper_index: 10 top_group_index: 10 background: '#fff' tags: - Cloudflare Pages - Hexo categories: - 开源免费 abbrlink: c95773ba date: 2024-11-29 10:13:05
本地启动 1 2 3 4 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config hexo cl && hexo s
远程发布 1 2 3 4 5 pwd D:\[Hexo-Blog]\Hexo-Config\wangshui898-config hexo cl; hexo g; hexo d
备份恢复 这里主要说一下新环境下如何快速恢复Hexo的相关配置, 假设基础环境已经配置完毕
基础条件:
之前修改都已经推送到GitHub上
基础环境nodejs, git, vscode都已经装好, 并且关联到github
主题文件的自定义图片已经另有备份(我这里保存在themes\butterfly.bak, 包括背景图和头像之类的)
克隆Hexo配置 克隆基础配置文件到本地
重装依赖 ctrl + ~打开终端, 重新安装hexo-cli插件, 此步骤需要在根目录
1 2 # hexo-cli npm install -g hexo-cli && hexo -v
重装主题 此步骤需要进入到配置目录下, 重新安装主题
1 git clone -b master https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
恢复相关图片文件
安装所需依赖 此步骤需要进入到配置目录下
1 2 3 4 5 6 # 部署插件 npm install hexo-deployer-git --save # 置顶插件 npm install hexo-generator-topindex --save # 搜索插件 npm install hexo-generator-search --save
本地启动验证
发布验证