mirror of
https://github.com/Dhghomon/easy_rust
synced 2024-11-11 07:11:02 +00:00
Merge pull request #98 from FongYoong/master
MdBook hosted on Github Pages via Github Actions
This commit is contained in:
commit
c31dd70ed7
30
.github/workflows/github-pages.yml
vendored
Normal file
30
.github/workflows/github-pages.yml
vendored
Normal file
@ -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
|
3
Makefile
3
Makefile
@ -23,6 +23,9 @@ help: ## Print help for each target
|
|||||||
book: ## Generate an mdBook version
|
book: ## Generate an mdBook version
|
||||||
@./createBookFromReadme.sh
|
@./createBookFromReadme.sh
|
||||||
|
|
||||||
|
github_pages: ## Generate an mdBook version
|
||||||
|
@./createGithubPagesFromReadme.sh
|
||||||
|
|
||||||
snippets: clean ## Create snippets
|
snippets: clean ## Create snippets
|
||||||
@type md2src >/dev/null 2>&1 || (echo "Run 'cargo install md2src' first." >&2 ; exit 1)
|
@type md2src >/dev/null 2>&1 || (echo "Run 'cargo install md2src' first." >&2 ; exit 1)
|
||||||
@mkdir -p $(SNIPPETS)
|
@mkdir -p $(SNIPPETS)
|
||||||
|
@ -1,4 +1,9 @@
|
|||||||
Update 28 November 2020: [Now also available in simplified Chinese](https://github.com/kumakichi/easy_rust_chs) thanks to [kumakichi](https://github.com/kumakichi)!
|
## Update
|
||||||
|
![example workflow name](https://github.com/FongYoong/easy_rust/workflows/github%20pages/badge.svg)
|
||||||
|
|
||||||
|
22 December: mdBook can be found [here](https://fongyoong.github.io/easy_rust/).
|
||||||
|
|
||||||
|
28 November 2020: [Now also available in simplified Chinese](https://github.com/kumakichi/easy_rust_chs) thanks to [kumakichi](https://github.com/kumakichi)!
|
||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
|
52
createGithubPagesFromReadme.sh
Normal file
52
createGithubPagesFromReadme.sh
Normal file
@ -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
Block a user