md(markdown)文件发布到博客,通过发现github(github page)是不错的选择,主要是支持自定义域名及cname(不用备案,备案太麻烦了)

env

  • blogs //private repo
  • mvpbang.github.io //public repo
  • github actions
  • hugo
  • window10
  • github

1.hugo安装

#hugo + hugo_extended

二进制文件添加到PATH中

#hugo-themes

2.create github repo && add ssh-key

2.1create repo

  • blogs //private md
  • mvbbang.github.io //public github-page

2.2generate ssh-key (deploy_key)

ssh-keygen -t rsa -b 4096 -C "[email protected]" -f gh-pages -N ""

gh-pages   //私钥
gh-pages.pub   //公钥

-C 指定提交邮箱 -f 生成秘钥前缀

2.3blogs (add private key)

  • Setting -> Secrets -> Actions -> (name: ACTIONS_DEPLOY_KEY)

2.4mvpbang.github.io (add public key)

  • Setting -> Deploy keys -> (name: ACTIONS_DEPLOY_KEY)

点击Deploy keys,添加公钥,Allow write access一定要勾上,否则会无法远程提交

3.add blogs actions

3.1hugo-actions

#Actions -> New workflow -> main.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
29
30
31
32
33
34
35
36
name: GitHub Pages

on:
  push:
    branches:
      - main  # Set a branch to deploy
  pull_request:

jobs:
  deploy:
    runs-on: ubuntu-20.04
    concurrency:
      group: ${{ github.workflow }}-${{ github.ref }}
    steps:
      - uses: actions/checkout@v2
        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@v2
        with:
          hugo-version: '0.82.0'
          extended: true

      - name: Build
        run: hugo --minify

      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
          external_repository: mvpbang/mvpbang.github.io   ### 推送到公共仓库用于github-page
          publish_branch: master
          publish_dir: ./public
          cname: mvpbang.com    ### define cname

#hugo-themes

#github-pages

4.add md && push blogs

4.1create markdown

#创建md
hugo new post/test.md

#本地调试
hugo server -D

http://localhost:1313/

#push到blogs

4.2mvpbang.github.io open github-pages

#source
master ->/

#custom domain
mvpbang.com  (cname www -> mvpbang.github.io)

#域名设置dns添加cname

#testing

Github Pages访问较慢

  • 可通过自定义域名+CDN加快访问速度

add cloudflare

reference