Hugo博客搭建
1.安装Hugo brew install hugo 新建博客管理文件夹 hugo new site blog_name --format yaml 设置博客主题 我用的是Hugo PaperMod $ git init $ git submodule add --depth=1 https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod 修改博客配置应用主题,通过修改根目录下的hugo.yml文件 baseURL: "" languageCode: zh-cn title: Howe's Blog theme: PaperMod 这样博客的初步框架就打好了,可以先本地预览一下。命令行输入以下指令之后,就可以本地预览了,打开浏览器访问//localhost:1313/ hugo server 2.配置PaperMod 主题配置可以查看github介绍,参考example设置。 3.新建文章 hugo new post/first.md 文章头需要设置为 date: '自动生成' draft: false title: 'first' Tags: ['tags','example] 4.设置GitHub Actions 通过设置github workflow,这样就可以通过自动化发布自己的博文啦!因为我的仓库和github pages仓库不是同一个,所有需要将生成出来的静态文件,push到另一仓库,我的yml配置如下,在仓库根目录下创建 .github/workflow/hugo-deploy.yml name: GitHub Pages on: push: branches: - main # Set a branch to deploy pull_request: jobs: deploy: runs-on: ubuntu-22.04 concurrency: group: ${{ github.workflow }}-${{ github.ref }} steps: - uses: actions/checkout@v4 with: submodules: true # Fetch Hugo themes (true OR recursive) fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - name: Setup Hugo uses: peaceiris/actions-hugo@v3 with: hugo-version: 'latest' # extended: true - name: Build run: hugo --minify - name: Deploy uses: peaceiris/actions-gh-pages@v3 with: PERSONAL_TOKEN: ${{ secrets.PERSONAL_TOKEN }} publish_dir: ./public EXTERNAL_REPOSITORY: your own github page repo PUBLISH_BRANCH: master commit_message: ${{ github.event.head_commit.message }} 设置完成之后,每次push就会出发github action发布博文了。 ...