Added github-pages.yml and createGithubPagesFromReadme.sh

pull/98/head
Fong Yoong 4 years ago
parent 709506e2af
commit 9c7cf6da8f

@ -0,0 +1,29 @@
name: github pages
on:
push:
branches:
- master
jobs:
deploy:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- run: sudo apt install linuxbrew-wrapper
- run: brew install coreutils
#- run: cargo install mdbook
- run: make book
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 'latest'
- run: mdbook build
- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book

@ -23,6 +23,9 @@ help: ## Print help for each target
book: ## Generate an mdBook version
@./createBookFromReadme.sh
github_pages: ## Generate an mdBook version
@./createGithubPagesFromReadme.sh
snippets: clean ## Create snippets
@type md2src >/dev/null 2>&1 || (echo "Run 'cargo install md2src' first." >&2 ; exit 1)
@mkdir -p $(SNIPPETS)

@ -0,0 +1,52 @@
#!/usr/bin/env bash
# A modified version of createBookFromReadme.sh for Github Pages
# Usage: ./createGithunPagesFromReadme.sh
# -------------------- Utility Methods --------------------
# Check for binaries
function checkEnvironment(){
type gcsplit >/dev/null 2>&1 || { echo "Install 'gcsplit' first (e.g. via 'brew install coreutils')." >&2 && exit 1 ; }
}
# Cleanup the src directory before starting
function cleanupBeforeStarting(){
rm -rf ./src
mkdir src
}
# Splits the Readme.md file based on the header in markdown and creates chapters
# Note:
# Get gcsplit via homebrew on mac: brew install coreutils
function splitIntoChapters(){
gcsplit --prefix='Chapter_' --suffix-format='%d.md' --elide-empty-files README.md '/^## /' '{*}' -q
}
# Moves generated chapters into src directory
function moveChaptersToSrcDir(){
for f in Chapter_*.md; do
mv $f src/$f
done
}
# Creates the summary from the generated chapters
function createSummary(){
cd ./src
touch SUMMARY.md
echo '# Summary' > SUMMARY.md
echo "" >> SUMMARY.md
for f in $(ls -tr | grep Chapter_); do
# Get the first line of the file
local firstLine=$(sed -n '1p' $f)
local cleanTitle=$(echo $firstLine | cut -c 3-)
echo "- [$cleanTitle](./$f)" >> SUMMARY.md;
done
cd ..
}
# -------------------- Steps to generate separate Markdown chapters --------------------
checkEnvironment
cleanupBeforeStarting
splitIntoChapters
moveChaptersToSrcDir
createSummary
Loading…
Cancel
Save