Hexo博客部署记录 Hexo是一个基于Node.js的静态网站生成器,主要用于创建博客和文档网站。
一、安装环境
nodejs官网
https://nodejs.org/zh-cn
git官网
https://git-scm.com/
验证
1 2 3 node -v npm -v git --version
二、安装Hexo 1 2 3 4 5 6 7 8 9 # 1.全局安装Hexo npm install -g hexo-cli # 2.初始化一个站点 hexo init blog.example.com cd blog.example.com # 3.安装依赖 npm install
三、生成静态文件并启动本地服务器: 1 2 3 hexo clean # 清理旧文件 hexo generate # 生成静态文件,可简写 hexo g hexo server # 启动预览,默认 http://localhost:4000,,可简写 hexo s
四、写文章 Hexo 默认文章都在 source/_posts/ 下。 创建一篇文章:
1 hexo new post "Hexo博客部署记录"
五、推送到Github 新建一个仓库
1 https://github.com/username/blog.example.com.git
1 2 3 4 5 6 7 8 git config --global user.name "YourName" git config --global user.email "YourEmail@example.com" git init git add . git commit -m "first commit" git branch -M main git remote add origin https://github.com/username/my-blog.git git push -u origin main
六、更换主题 优秀的主题汇总 https://github.com/Ailln/awesome-hexo-theme
https://github.com/theme-next/hexo-theme-next
安装主题,这里需要特别主题仓库地址,新旧版本仓库地址不一样。
1 git submodule add https://github.com/next-theme/hexo-theme-next themes/next
更新主题
在hexo 的_config.yml 启用主题
在hexo 的_config.yml 更改语言
添加评论插件
1 npm install @waline/hexo-next
在_config.next.yml 最后添加评论相关的配置(这里尽可能不修改子模块)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 # Waline # For more information: https://waline.js.org, https://github.com/walinejs/waline waline: enable: true serverURL: https://waline.bravexist.cn # vercel 域名 placeholder: (发表评论) # comment box placeholder avatar: mm # Gravatar style meta: [nick, mail, link] # Custom comment header pageSize: 10 # Pagination size lang: zh-cn # Language, available values: en, zh-cn # Warning: Do not enable both `waline.visitor` and `leancloud_visitors`. visitor: true # Article reading statistic comment_count: true # If false, comment count will only be displayed in post page, not in home page requiredFields: [nick, mail] # Set required fields: [nick] | [nick, mail] libUrl: # Set custom library cdn url
七、手动bat上传github deploy.bat
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 @echo off chcp 65001 >nul setlocal enabledelayedexpansion echo 正在构建和部署Hexo博客... echo. :: 清理和生成静态文件 echo [1/4] 清理旧文件... call hexo clean echo [2/4] 生成静态文件... call hexo generate if errorlevel 1 ( echo 错误:静态文件生成失败! pause exit /b 1 ) :: 获取当前时间(格式化) for /f "tokens=1-3 delims=/- " %%a in ('echo %date%') do ( set year=%%a set month=%%b set day=%%c ) for /f "tokens=1-2 delims=: " %%a in ('echo %time:~0,5%') do ( set hour=%%a set minute=%%b ) :: 处理时间格式(去掉前导空格) set hour=!hour: =0! set minute=!minute: =0! :: Git操作 echo [3/4] 提交源码到GitHub... git add . git status --porcelain >nul 2>&1 if errorlevel 1 ( echo 没有需要提交的更改 ) else ( git commit -m "!year!-!month!-!day! !hour!:!minute! 更新博客内容" git push origin main if errorlevel 1 ( echo 错误:推送到GitHub失败! pause exit /b 1 ) echo GitHub推送成功! ) :: 部署到GitHub Pages echo [4/4] 部署到GitHub Pages... call hexo deploy if errorlevel 1 ( echo 错误:部署失败! pause exit /b 1 ) echo. echo 博客部署完成! echo 源码已推送到:GitHub仓库 echo 博客已部署到:GitHub Pages echo. pause
七、部署到Edgeone https://console.cloud.tencent.com/edgeone/pages
选择GitHub仓库,选择Hexo构建,绑定自定义域名。
八、参考文献