mirror of https://github.com/Dhghomon/easy_rust
Merge pull request #98 from FongYoong/master
MdBook hosted on Github Pages via Github Actionspull/99/head
commit
c31dd70ed7
@ -0,0 +1,30 @@
|
||||
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: chmod 777 -R ./
|
||||
- run: make github_pages
|
||||
|
||||
- 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
|
@ -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_ | sort -V); 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…
Reference in New Issue