Skip to content

Instantly share code, notes, and snippets.

@ikikko
Last active June 1, 2020 15:29
Show Gist options
  • Save ikikko/a687d6627dba553e1e9e53f35db5de05 to your computer and use it in GitHub Desktop.
Save ikikko/a687d6627dba553e1e9e53f35db5de05 to your computer and use it in GitHub Desktop.
継続的原稿デリバリー
name: Make HTML CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
container: pandoc/core
steps:
- uses: actions/checkout@v2
- name: Run shell script for making html
run: ./make.sh
- name: Upload html
uses: actions/upload-artifact@v1
with:
name: docs
path: docs
deploy:
needs: build
runs-on: ubuntu-latest
steps:
- name: Download html
uses: actions/download-artifact@v1
with:
name: docs
# e.g. https://<organization>.github.io/<repository>/<#PR num>/output.html
- name: Make sub dir for pull request
run: |
mkdir -p ${{ github.event.number }}
mv docs/* ${{ github.event.number }}
mv ${{ github.event.number }} docs
if: github.event_name == 'pull_request'
- name: Deploy html
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./docs
commit_message: ${{ github.event.head_commit.message }}
keep_files: true
#!/bin/sh
# require: pandoc
OUTPUT=docs/output.html
# ヘッダー
cat templates/template_header.html > $OUTPUT
# イントロダクション
pandoc -f markdown -t html docs/intro.md >> $OUTPUT
# 目次
echo '<ul class="table-of-contents">'
for file in docs/ch*.md; do
echo '<li>'
# + md から見出しだけを抜き出して
# + 第1レベル・第2レベルそれぞれに html タグを埋めつつ
# + 最初の第2レベルに <ul>, 最後の第2レベルに </ul> を追加
grep -h '^#' $file | \
sed -e 's|^# \(.*\)|<a href="#\1">\1</a>|' \
-e 's|^## \(.*\)|<li><a href="#\1">\1</a></li>|' \
-e '1,/li/ s|^<li>|<ul><li>|' \
-e '$ s|</li>$|</li></ul>|'
echo '</li>'
done
echo '</ul>'
# 本文
for file in docs/ch*.md; do
# エンジニアHubのスタイルに合わせて、h1/h2 を h3/h4 に変換しつつ html 化
sed 's/^#/###/' $file | pandoc -f markdown -t html >> $OUTPUT
done
# フッター
cat templates/template_footer.html >> $OUTPUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment