Hexo 使用
Hexo 是一个静态博客站点生成工具,可以将 Markdown 格式的文档转换成静态页面,非常适合用来做个人技术博客。
使用
-
安装 Hexo:
mkdir MyBlog && cd MyBlog npx hexo init # 将当前目录初始化为博客站 -
创建新文章:
npx hexo new "Article Title" -
在 localhost 上预览博客:
npx hexo server -
生成静态文件:
npx hexo generate # 生成静态页面到 public 目录 -
部署到生产环境:
npx hexo deploy
部署到 GitHub
在使用 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.ymlname: Pages on: push: branches: - main # default branch jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: token: ${{ secrets.GITHUB_TOKEN }} submodules: recursive - name: Use Node.js 20 uses: actions/setup-node@v4 with: 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 文档

浙公网安备 33010602011771号