From 709506e2af730b8e043a9e95c7798fd221618384 Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 20:55:20 +0800 Subject: [PATCH 1/8] Updated README.md to fix mdbook issue --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8da5712..e5728ed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ -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 +28 November 2020: [Now also available in simplified Chinese](https://github.com/kumakichi/easy_rust_chs) thanks to [kumakichi](https://github.com/kumakichi)! ## Introduction From 9c7cf6da8f5d066ec744a2f9307f32ad2c23cec4 Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 21:00:39 +0800 Subject: [PATCH 2/8] Added github-pages.yml and createGithubPagesFromReadme.sh --- .github/workflows/github-pages.yml | 29 +++++++++++++++++ Makefile | 3 ++ createGithubPagesFromReadme.sh | 52 ++++++++++++++++++++++++++++++ 3 files changed, 84 insertions(+) create mode 100644 .github/workflows/github-pages.yml create mode 100644 createGithubPagesFromReadme.sh diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml new file mode 100644 index 0000000..e1076bd --- /dev/null +++ b/.github/workflows/github-pages.yml @@ -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 \ No newline at end of file diff --git a/Makefile b/Makefile index 6cbd250..daaba77 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/createGithubPagesFromReadme.sh b/createGithubPagesFromReadme.sh new file mode 100644 index 0000000..18d5177 --- /dev/null +++ b/createGithubPagesFromReadme.sh @@ -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 \ No newline at end of file From 752203e5fb71a43da7060d68d3e9d1ad9e9c7f1a Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 21:03:13 +0800 Subject: [PATCH 3/8] Updated github-pages.yml --- .github/workflows/github-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index e1076bd..13c0753 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -13,7 +13,7 @@ jobs: - run: sudo apt install linuxbrew-wrapper - run: brew install coreutils #- run: cargo install mdbook - - run: make book + - run: make github_pages - name: Setup mdBook uses: peaceiris/actions-mdbook@v1 From b3d1f71b73ae7f74fdc342980f412a3ae89539de Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 21:12:16 +0800 Subject: [PATCH 4/8] Added chmod to github-pages.yml to execute the Makefile without permission issues --- .github/workflows/github-pages.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 13c0753..3117346 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -13,6 +13,7 @@ jobs: - 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 From 8f2059ae85b0b0e879d6b4e10bb4326293c97206 Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 21:32:21 +0800 Subject: [PATCH 5/8] Fixed summary order issue --- createGithubPagesFromReadme.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/createGithubPagesFromReadme.sh b/createGithubPagesFromReadme.sh index 18d5177..87f38f1 100644 --- a/createGithubPagesFromReadme.sh +++ b/createGithubPagesFromReadme.sh @@ -35,7 +35,7 @@ function createSummary(){ touch SUMMARY.md echo '# Summary' > SUMMARY.md echo "" >> SUMMARY.md - for f in $(ls -tr | grep Chapter_); do + for f in $(ls -tr | grep Chapter | env LC_COLLATE=C sort); do # Get the first line of the file local firstLine=$(sed -n '1p' $f) local cleanTitle=$(echo $firstLine | cut -c 3-) From 330f9cbc60d1fdfaff299dcaad53d282e245d4a0 Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 21:37:23 +0800 Subject: [PATCH 6/8] Fixed summary order issue..again lol --- createGithubPagesFromReadme.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/createGithubPagesFromReadme.sh b/createGithubPagesFromReadme.sh index 87f38f1..481550d 100644 --- a/createGithubPagesFromReadme.sh +++ b/createGithubPagesFromReadme.sh @@ -35,7 +35,7 @@ function createSummary(){ touch SUMMARY.md echo '# Summary' > SUMMARY.md echo "" >> SUMMARY.md - for f in $(ls -tr | grep Chapter | env LC_COLLATE=C sort); do + 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-) From 3535e51120b670a78a5c1ee396b7efc356ab9450 Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 22:04:59 +0800 Subject: [PATCH 7/8] Added badge for Github Action --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index e5728ed..d99ed9a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ ## 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 From 0a6ecc58d05172e95e696bd708ea90f5df436d4f Mon Sep 17 00:00:00 2001 From: Fong Yoong Date: Tue, 22 Dec 2020 22:06:04 +0800 Subject: [PATCH 8/8] Added spacing for badge --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index d99ed9a..9876690 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ## 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