Hexo 使用
Hexo 是一个静态博客站点生成工具,可以将 Markdown 格式的文档转换成静态页面,非常适合用来做个人技术博客。
使用
-
安装 Hexo:
mkdir MyBlog && cd MyBlog npx hexo init # 将当前目录初始化为博客站
-
创建新文章:
hexo new "Article Title"
-
在本地服务器上预览博客:
npx hexo server
-
生成静态文件:
npx hexo generate # 生成静态页面到 public 目录
-
部署到生产环境:
npx hexo deploy
配置生产环境
在使用 deploy
命令之前,你需要先配置生产环境。
-
修改 Hexo 配置文件。
编辑
_config.yml
,将其中的 URL 改为https://USERNAME.github.io/MyBlog
。其中USERNAME
是你的 GitHub 用户名。url: https://USERNAME.github.io/MyBlog
-
创建 GitHub Actions 配置文件
mkdir .github/workflows vim .github/workflows/pages.yml
name: Pages on: push: branches: - main # default branch jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} # If your repository depends on submodule, please see: https://github.com/actions/checkout submodules: recursive - name: Use Node.js 20 uses: actions/setup-node@v4 with: # Examples: 20, 18.19, >=16.20.2, lts/Iron, lts/Hydrogen, *, latest, current, node # Ref: https://github.com/actions/setup-node#supported-version-syntax node-version: "20" - name: Cache NPM dependencies uses: actions/cache@v4 with: path: node_modules key: ${{ runner.OS }}-npm-cache restore-keys: | ${{ runner.OS }}-npm-cache - name: Install Dependencies run: npm install - name: Build run: npm run build - name: Upload Pages artifact uses: actions/upload-pages-artifact@v3 with: path: ./public deploy: needs: build permissions: pages: write id-token: write environment: name: github-pages url: ${{ steps.deployment.outputs.page_url }} runs-on: ubuntu-latest steps: - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4
将文件中的
20
改为你实际使用的 Node.js 的版本。 -
在 GitHub 上建立新仓库并命名为
MyBlog
。 -
编辑仓库配置,打开
Settings
>Pages
,并将Source
改为GitHub Actions
。 -
将本地项目上传到 GitHub。
-
打开
https://USERNAME.github.io/MyBlog
查看效果。
参考:Hexo 文档
本文作者:Undefined443
本文链接:https://www.cnblogs.com/Undefined443/p/18279131
版权声明:本作品采用署名-非商业性使用-相同方式共享 4.0 国际许可协议进行许可。
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步