hexo使用技巧 John Doe 2025-10-23 2025-11-13 Hexo博客完整使用指南 📝 快速命令速查 常用命令组合 1 2 3 4 hexo cl ; hexo g ; hexo d hexo cl ; hexo s hexo g ; hexo s hexo s --debug
命令详解 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 hexo clean hexo cl hexo generate hexo g hexo g --watch hexo server hexo s hexo s -p 5000 hexo s --draft hexo deploy hexo d hexo d -g
📄 文章管理 创建新文章 1 2 3 4 5 6 hexo new "文章标题" hexo n "文章标题" hexo new post "文章标题" hexo new draft "草稿标题" hexo new page "关于"
文章Front Matter模板 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 --- title: 文章标题 date: 2025-11-10 14:30:00 updated: 2025-11-10 14:30:00 tags: - Hexo - 博客 - 教程categories: - 技术 - 前端keywords: Hexo, 博客搭建, 静态网站 description: 这是文章的简短描述,会显示在搜索结果中 top: false # 是否置顶 cover: /img/cover.jpg # 文章封面图 comments: true # 是否开启评论 --- 文章正文内容... <!-- more --> <!-- 首页摘要分隔符 --> 更多详细内容...
草稿管理 1 2 3 hexo new draft "草稿标题" hexo s --draft hexo publish draft "草稿标题"
🏷️ 页面管理 创建特殊页面 1 2 3 4 5 hexo new page "tags" hexo new page "categories" hexo new page "about" hexo new page "archives" hexo new page "404"
标签页配置 创建后编辑 source/tags/index.md:
1 2 3 4 5 6 7 --- title: 标签 date: 2025-11-10 type: "tags" layout: "tags" comments: false ---
分类页配置 编辑 source/categories/index.md:
1 2 3 4 5 6 7 --- title: 分类 date: 2025-11-10 type: "categories" layout: "categories" comments: false ---
🎨 主题管理 安装主题 1 2 3 4 5 6 cd your-bloggit clone https://github.com/theme-next/hexo-theme-next themes/next npm install hexo-theme-next
切换主题 编辑 _config.yml:
更新主题 1 2 3 4 5 cd themes/your-themegit pull npm update hexo-theme-next
🔧 配置优化 网站基本配置 (_config.yml) 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 title: 我的博客 subtitle: '记录技术与生活' description: '专注于前端开发和技术分享' keywords: 前端,JavaScript,Hexo author: Your Name language: zh-CN timezone: 'Asia/Shanghai' url: https://yourname.github.io root: / permalink: :year/:month/:day/:title/ permalink_defaults: pretty_urls: trailing_index: true trailing_html: true deploy: type: git repo: https://github.com/yourname/yourname.github.io.git branch: main
提升构建速度 1 2 3 4 5 6 npm install hexo-generator-search --save npm install hexo-generator-sitemap --save npm install hexo-generator-feed --save npm install hexo-renderer-pug --save npm install hexo-renderer-sass --save
🚀 部署到GitHub Pages 1. 安装部署插件 1 npm install hexo-deployer-git --save
2. 配置 _config.yml 1 2 3 4 5 deploy: type: git repo: https://github.com/username/username.github.io.git branch: main message: "Site updated: {{ now('YYYY-MM-DD HH:mm:ss') }} "
3. 部署流程 1 2 3 4 5 6 7 hexo clean hexo generate hexo deploy hexo cl && hexo g && hexo d
4. SSH密钥配置(推荐) 1 2 3 4 5 6 7 8 9 10 11 12 ssh-keygen -t rsa -C "your_email@example.com" cat ~/.ssh/id_rsa.pubdeploy: type : git repo: git@github.com:username/username.github.io.git branch: main
💡 常用工作流 日常写作流程 1 2 3 4 5 6 7 8 9 10 11 hexo new "今天学到的新知识" code source /_posts/今天学到的新知识.md hexo s hexo cl && hexo g && hexo d
主题调试流程 1 2 3 4 5 6 7 8 hexo clean hexo s --debug hexo s --debug --watch
🐛 常见问题解决 1. 部署失败 1 2 3 4 5 6 7 rm -rf node_modules package-lock.jsonnpm install git config --global user.name "Your Name" git config --global user.email "your_email@example.com"
2. 端口被占用 1 2 3 4 5 6 hexo s -p 5000 lsof -i:4000 kill -9 PID
3. 文章不显示
4. 主题样式不生效
📦 实用插件推荐 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 npm install hexo-generator-sitemap --save npm install hexo-generator-baidu-sitemap --save npm install hexo-generator-search --save npm install hexo-image-link --save npm install hexo-asset-image --save npm install hexo-prism-plugin --save npm install hexo-all-minifier --save npm install hexo-word-counter --save npm install hexo-generator-feed --save
🎯 高级技巧 1. 使用Git管理源文件 1 2 3 4 5 git checkout -b source git add . git commit -m "backup source files" git push origin source
2. 自定义域名 1 2 3 4 5 6 echo "yourdomain.com" > source /CNAME
3. 配置GitHub Actions自动部署 创建 .github/workflows/deploy.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 name: Deploy Hexo on: push: branches: [ source ] jobs: build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - name: Setup Node.js uses: actions/setup-node@v2 with: node-version: '16' - name: Install Dependencies run: npm install - name: Build run: npm run build - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./public
📚 学习资源
🔖 快速参考卡片
命令
简写
说明
hexo clean
hexo cl
清理缓存
hexo generate
hexo g
生成静态文件
hexo server
hexo s
启动本地服务
hexo deploy
hexo d
部署到远程
hexo new
hexo n
创建新文章
hexo –version
hexo -v
查看版本
hexo –help
hexo -h
查看帮助
最后更新 : 2025-11-10提示 : 遇到问题先尝试 hexo clean 清理缓存!