个人博客搭建 通过Cloudflare安装Tunnel Cloudflare 注册 Cloudflare Tunnel 教程 Cloudflare Pages 教程 西部数码官网
安装Portainer CE 监控面板 1 2 3 4 5 6 7 8 9 10 11 12 sudo docker pull portainer/portainer-ce:latestsudo docker volume create portainer_datasudo docker run -d \ -p 8000:8000 -p 9443:9443 -p 9000:9000 \ --name portainer \ --restart=always \ -v /var/run/docker.sock:/var/run/docker.sock \ -v portainer_data:/data \ portainer/portainer-ce:latest
安装FileBrowser文件管理器 1 2 mkdir -p /opt/jetson-server/filebrowsertouch /opt/jetson-server/filebrowser/database.db
1 2 3 4 5 6 7 8 9 docker run -d \ --name filebrowser \ --restart=always \ -p 18080:80 \ -v /opt/jetson-server:/srv \ -v /opt/jetson-server/filebrowser:/config \ -e FILEBROWSER_USERNAME=white \ -e FILEBROWSER_PASSWORD=yourpassword \ filebrowser/filebrowser
安装git 9.0.2 1 2 3 4 apt install git /**/安装git git --version /**/查看git的版本
安装node.js环境 20.20.1 1 2 3 4 5 6 7 8 sudo apt install npmsudo apt install nodejsnpm -v node -v
arm 架构的apt中可能版本较旧,建议去nodejs下载地址 下载所需版本,然后手动解压安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 sudo tar -xzvf node-v20.20.1-linux-arm64.tar.gzsudo tar -xvf node-v20.20.1-linux-arm64.tar.xzsudo mv node-v20.20.1-linux-arm64 /usr/local/nodejsecho 'export NODE_HOME=/usr/local/nodejs' >> ~/.bashrcecho 'export PATH=$NODE_HOME/bin:$PATH' >> ~/.bashrcsource ~/.bashrcnpm config set registry https://registry.npmmirror.com
安装Hexo框架 1 2 npm install hexo-cli -g
初始化Hexo
1 2 3 4 5 6 sudo npm install hexo -gmkdir bloghexo init blog
让Hexo在后台运行
1 2 3 4 5 6 7 8 9 10 11 12 cat > hexo_run.js << 'EOF' //run const { exec } = require('child_process' ) exec ('hexo server' ,(error, stdout, stderr) => { if (error){ console.log('exec error: ${error}' ) return } console.log('stdout: ${stdout}' ); console.log('stderr: ${stderr}' ); }) EOF
安装butterfly主题 1 2 git clone -b dev https://github.com/jerryc127/hexo-theme-butterfly.git themes/butterfly
修改 Hexo 根目录下的 _config.yml,把主题改为 butterfly
如果你没有 pug 以及 stylus 的渲染器,请下载安装:
1 npm install hexo-renderer-pug hexo-renderer-stylus --save
在 hexo 的根目录创建一个文件 _config.butterfly.yml,并把主题目录的 _config.yml 内容复制到 _config.butterfly.yml 去。这边我建议用cp命令,直接将主题的config内容复制到hexo根目录上
以后只需要在 _config.butterfly.yml 进行配置就行。如果使用了 _config.butterfly.yml, 配置主题的 _config.yml 将不会有效果。
Hexo 会自动合并主题中的 _config.yml 和 _config.butterfly.yml 里的配置,如果存在同名配置,会使用 _config.butterfly.yml 的配置,其优先度较高。
1 cp themes/butterfly/_config.yml _config.butterfly.yml
配置博客 配置网站页面 打开hexo根目录的_config.yml
1 2 3 4 5 6 7 8 title: 一只白色 subtitle: White's Blog description: '欢迎来到我的个人博客,这里记录日常,分享技术...' keywords: author: White language: zh-CN timezone: ''
修改永久链接格式 修改hexo根目录的_config.yml
1 2 3 4 5 6 url: https://www.whitee.cn permalink: :category/:id/ permalink_defaults: pretty_urls: trailing_index: true trailing_html: true
当我们发布文章时,在文章头部信息中添加id信息
1 2 3 4 5 6 7 --- title: 测试文章 date: 2021-04-22 11:02:53 id: blog001 categories: []tags: []---
同时在_config.yml中修改category_map, 将很多category是中文的映射成英文
1 2 3 4 5 6 7 8 default_category: uncategorized category_map: Android: android SQL: sql 工具: kits 数据库: database tag_map:
目录配置 打开hexo根目录的_config.butterfly.yml
1 2 3 4 5 6 7 8 9 10 11 menu: 首页: / || fas fa-home 时光档案: /archives/ || fas fa-archive 标签: /tags/ || fas fa-tags 分类: /categories/ || fas fa-folder-open 列表||fa fa-list || hide: 音乐: /music/ || fas fa-music 照片: /picture/ || fas fa-images 电影: /movies/ || fas fa-video 友链: /link/ || fas fa-link 关于: /about/ || fas fa-heart
社交设置 打开hexo根目录的_config.butterfly.yml
1 2 3 social: fab fa-github: https://github.com/maodoo0701 || Github || "#hdhfbb" fas fa-envelope: mailto:maodoo@qq.com || Email || "#000000"
头像设置 1 2 3 4 favicon: /img/favicon.png avatar: img: /img/avatar.png effect: true
标签、分类等页面 top_img 设置 _config.butterfly.yml中的如下配置
配置
解释
index_img
主页的 top_img,也就是主页遮罩图片
default_top_img
默认的 top_img,当页面(包括文章页)的 top_img 没有配置时,会显示 default_top_img
archive_img
归档页面的 top_img
tag_img
tag 子页面的默认 top_img
tag_per_img
tag 子页面的 top_img,可配置每个 tag 的 top_img
category_img
category 子页面的默认 top_img
category_per_img
category 子页面的 top_img,可配置每个 category 的 top_img
(tags/categories/自建页面) 和 文章页 的 top_img
需到对应的 md 页面设置 front-matter 中的 top_img
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 tag_img: /img/tags.jpg tag_per_img: category_img: /img/categories.jpg category_per_img: 旅行: /img/category_trip.png 笔记: /img/category_note.png
页面顶部大图配置(Banner) _config.butterfly.yml 配置:
1 2 3 4 index_img: archive_img: tag_img: category_img:
标签 / 分类单独背景
1 2 3 4 tag_per_img: - java: /img/java.jpg - linux: /img/linux.jpg category_per_img:
tags(不是tag) 页面背景配置的方法(categories同理)
1 2 3 4 5 --- title: 标签 top_img: /img/tags.jpg ---
背景图和顶部脚步图设置 1 2 3 4 5 6 default_top_img: /img/default_top_img.png footer_img: false background:
自定义背景特效 修改_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 canvas_ribbon: enable: false size: 150 alpha: 0.6 zIndex: -1 click_to_change: false mobile: false canvas_fluttering_ribbon: enable: false mobile: false canvas_nest: enable: false color: '0,0,255' opacity: 0.7 zIndex: -1 count: 99 mobile: false
代码块格式设置 1 2 code_blocks: macStyle: true
文章封面 1 2 3 4 5 6 7 8 9 10 11 cover: index_enable: true aside_enable: true archives_enable: true default_cover: - https://maodoo.oss-cn-beijing.aliyuncs.com/20241210172528345.jpg - https://maodoo.oss-cn-beijing.aliyuncs.com/20241210172459243.png
主题目录 1 2 3 hexo new page tags hexo new page categories hexo new page link
分别找到 source/tags/index.md、source/categories/index.md 、source/link/index.md 文件并编辑
1 2 3 4 5 6 7 --- title: 标签 date: 2018-01-05 00:00:00 type: 'tags' orderby: random order: 1 ---
1 2 3 4 5 --- title: 分类 date: 2018-01-05 00:00:00 type: 'categories' ---
1 2 3 4 5 --- title: 友链 date: 2018-06-07 22:17:49 type: 'link' ---
数据来源
1 2 3 mkdir _data touch link.yml vi link.yml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 - class_name: 友情链接 class_desc: 那些人,那些事 link_list: - name: Hexo link: https://hexo.io/zh-tw/ avatar: https://d33wubrfki0l68.cloudfront.net/6657ba50e702d84afb32fe846bed54fba1a77add/827ae/logo.svg descr: 快速、简单且强大的网志框架 - class_name: 网站 class_desc: 值得推荐的网站 link_list: - name: Youtube link: https://www.youtube.com/ avatar: https://i.loli.net/2020/05/14/9ZkGg8v3azHJfM1.png descr: 视频网站 - name: Weibo link: https://www.weibo.com/ avatar: https://i.loli.net/2020/05/14/TLJBum386vcnI1P.png descr: 中国最大社交分享平台 - name: Twitter link: https://twitter.com/ avatar: https://i.loli.net/2020/05/14/5VyHPQqR6LWF39a.png descr: 社交分享平台
创建新文章 如果资源只给特定的文章使用,可以将 config.yml 文件中的 post_asset_folder 选项设为 true,然后在每一次通过命令创建新文章时自动创建一个与文章 title 同名的文件夹,然后就可以把有关的资源放在这个关联文件夹中,再通过相对路径来引用它们
创建新文章
文章中 Front-matter 参数
参数
作用
解释
title
文章标题
作为文章标题展示
date
发布时间
会展示在标题旁边,并为归档页起到排序作用
tags
标签
文章的标签
categories
分类
文章的分类
cover
封面
首页文章卡片封面
top_img
顶图
文章顶部 Banner 大图
sticky
置顶
文章置顶,sticky 数值越大越靠前,butterfly 会先按 sticky 再按 date 排序
description
摘要
首页文章摘要、SEO 描述、社交分享摘要、Butterfly 卡片摘要,不存在则会截取正文前几行
文章 Front-matter 中的description 在文章顶部的的 Front-matter 里设置 description 字段,修改(_config.butterfly.yml)中的 index_post_content 参数,可以控制首页文章摘要
1 2 3 4 5 6 7 8 9 index_post_content: method: 2 length: 500
安装搜索插件 1 npm install hexo-generator-searchdb --save
_config.yml 改成:
1 2 3 4 5 search: enable: true path: search.xml field: post format: html
enable: true 必须有
limit 可以先去掉(避免兼容问题)
_config.butterfly.yml 改成:
1 2 3 4 5 6 search: use: local_search local_search: enable: true preload: false
强制清理缓存(很多人死在这一步)
1 2 3 4 hexo clean rm -rf node_modules/.cachehexo g hexo s
图片懒加载插件 1 npm install hexo-lazyload-image --save
_config.yml 配置:
1 2 3 lazyload: enable: true loadingImg: /img/loading.gif
需要在/source/img目录下放置好loading.gif文件
字数统计插件 1 npm install hexo-wordcount --save or yarn add hexo-wordcount
修改侧边栏 _config.butterfly.yml 配置:
1 2 3 4 5 6 aside: enable: true hide: false button: true mobile: true position: left
代码块样式 _config.butterfly.yml配置:
1 2 3 4 5 6 highlight_theme: mac highlight_copy: true highlight_lang: false highlight_shrink: false highlight_height_limit: false code_word_wrap: true
副标题循环打字效果 _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 subtitle: enable: true effect: true typed_option: source: false sub: - 你在抱怨什么呢 - 为明天到来的事,说人生像是没有意义 - 没有选择会是唯一的路 - 这不是你自己的问题,人终归要好好去生活
版权样式 1 2 3 4 5 6 copy: enable: true copyright: enable: false limit_count: 50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 footer: nav: - title: 首页 link: / - title: 关于 link: /about/ owner: enable: true since: 2025 copyright: enable: true version: false custom_text:
页脚背景变透明设置
在你的博客目录里找到(如果没有就新建):
然后加上:
1 2 3 4 5 6 7 8 #footer { background : transparent !important ; box-shadow : none !important ; } #footer ::before { background : transparent !important ; }
打开 _config.butterfly.yml,找到:
如果你没有自定义 CSS 引入,可以加:
1 2 3 inject: head: - <link rel="stylesheet" href="/css/custom.css">
如果你用了背景图,是这种配置,那透明 footer 才会有“嵌入感”。否则你只会看到白底(看起来像没变化)
文章插入图片
1 {% asset_img image.jpg 这是一张图片 %}
1 <img src ="路径" alt ="替代文本,图片无法加载时显示" style ="zoom:50%;" width ="200" height ="200" title ="图片标题,鼠标悬停在图片上时显示" >
由于使用了post_asset_folder: true会给每个文章单独的资源文件夹
在hexo中,按理说应该是使用,但网页中却无法正常显示。此时应该使用这样的方式来引入图片:
1 {% asset_img image.jpg 这是一张图片 %}
插件hexo-renderer-marked 解决了这个问题。
可以只用npm install hexo-renderer-marked --save命令直接安装,之后在_config.yaml中更改配置如下:
1 2 3 4 post_asset_folder: true marked: prependRoot: true postAsset: true
之后就可以在文章中愉快的插入图片了。
推荐写:
1 2  
不要写:
1 2  
图片点击放大 在_config.butterfly.fly修改以下内容
展示动态图片
链接形式的文件可用,本地文件似乎不可用(可能我用的不对吧~)
在 Hexo 博客根目录下执行以下命令:
1 npm install hexo-live-photo --save
在 Hexo 的主配置文件 _config.yml 中添加以下选项:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 livephoto: enable: true autoplay: true hover_to_play: true click_to_play: true lazy_load: true threshold: 0.8 badge: true badge_text: 'Live' badge_position: 'bottom-left' loading_animation: true preload: 'auto' keep_observing: false hover_delay: 300 weixin_disable_autoplay: true
基本语法:
1 {% livephoto 图片路径 视频路径 %}
一行显示两张动图:
1 2 3 4 5 6 7 8 <div class ="image-grid" > <div class ="image-column" > {% livephoto 图片路径 视频路径 %} </div> <div class="image-column"> {% livephoto 图片路径 视频路径 %} </div> </div>
拓展用法:
1 {% livephoto 图片路径 视频路径 "图片描述" "可选标题" "可选宽度" "可选高度" %}
九宫格展示图片 在myblog/source/css/下的custom.css中添加如下样式
由于在版权样式 中的页脚背景变透明设置 中已经引用了custom.css,所以直接添加就行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 .image-grid { display : grid; grid-template-columns : repeat (3 , 1 fr); gap : 10px ; margin : 10px 0 ; } .image-grid img { width : 100% ; aspect-ratio : 1 / 1 ; object-fit : cover; border-radius : 12px ; display : block; transition : all 0.3s ease; } .image-grid img :hover { transform : scale (1.03 ); }
Markdown 这样写就可以
1 2 3 4 5 6 7 8 9 10 11 <div class ="image-grid" > <img src ="1.jpg" > <img src ="2.jpg" > <img src ="3.jpg" > <img src ="4.jpg" > <img src ="5.jpg" > <img src ="6.jpg" > <img src ="7.jpg" > <img src ="8.jpg" > <img src ="9.jpg" > </div >
部署到cloudflare GitHub中创建私有仓库并推送
Cloudflare中部署页面
Cloudflare中设置自定义域
新增自定义域,以下两个都需要
www.yourdomain.com
yourdomain.com
在规则中自定义重定向规则
表达式:(http.host eq "yourdomain.com")
重定向url:https://www.yourdomain.com
状态代码:301
这样当访问裸域的时候会重定向