1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

mkdocs-materialとGitHub PagesでMkDocsを作成する

Last updated at Posted at 2021-11-27

Install

pip install mkdocs-material

mkdocs作成

  1. MKDocsの初期化

    mkdocs new .
    
    結果
    tree
    .
    ├── docs
    │   └── index.md
    └── mkdocs.yml
    
    1 directory, 2 files
    
  2. テーマをmkdocs.ymlで指定

    mkdocs.yml
    site_name: My Docs
    theme:
      name: material
    
  3. ローカルで起動

    mkdocs serve
    

    スクリーンショット 2021-11-27 11.09.07.png

  4. ビルド

    mkdocs build
    

    site/ 以下に生成される

  5. GitHub Pagesで公開する (gh-deploy branchにPush)

    1. GitHub Pagesの設定: 以下のようにgh-pagesブランチを指定する

      スクリーンショット 2021-11-27 11.29.16.png

    2. GitHub Actions作成 (main branchにPushされたらDocsをビルドしてDeployする)

      .github/workflows/publish.yml
      name: publish
      
      on:
        push:
          branches:
            - main
      jobs:
        deploy:
          runs-on: ubuntu-latest
          steps:
            - uses: actions/checkout@v2
            - uses: actions/setup-python@v2
              with:
                python-version: 3.9
            - run: pip install mkdocs-material
            - run: mkdocs gh-deploy --force
      
    3. GitHub Actionsを含めて、RepoへPush

    4. https://nakamasato.github.io/mkdocs-material-sample/公開された! (自分の場合は、カスタムDomainを使っているので nakamasato.comとなった)

  6. テーマ変更

    色などを変更できる

    site_name: mkdocs sample
    theme:
      name: material
      palette:
        primary: cyan
    

    スクリーンショット 2021-11-27 11.46.58.png

Reference

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?