Skip to content

Add script to generate html and pdf files from markdown. #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
html/
pdf/
pdfs/
58 changes: 58 additions & 0 deletions generate_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env bash
########################################################################################################################
# Usage: ./generate_docs.sh [token]
#
# Description: Generates minimal HTML and PDF files in an output directory using GitHubs markdown API.
# The markdown files are first converted to HTML then the HTML files are converted to PDF.
#
# Note: GitHub's API is rate limited (60 requests per hour). Using an access token from the
# following URL, this rate is increased considerably: https://github.com/settings/tokens/new?scopes=
# More info here: https://github.com/joeyespo/grip#access
########################################################################################################################

OUT_DIR_HTML=html/
OUT_DIR_PDF=pdf/

# check if grip installed
which grip > /dev/null 2> /dev/null
rc=$?
if [ ${rc} != 0 ]; then
echo "The command 'grip' is not available. Install it with pip:"
echo "sudo pip install grip"
exit 1
fi

# check if chromium installed
which chromium-browser > /dev/null 2> /dev/null
rc=$?
if [ ${rc} != 0 ]; then
echo "The command 'chromium-browser' is not available. Install it with apt:"
echo "sudo apt install chromium-browser"
exit 1
fi

# make sure output directories exists
mkdir -p ${OUT_DIR_HTML}
mkdir -p ${OUT_DIR_PDF}

# check if GitHub access token provided
if [ -n "$1" ]; then
token_argument="--pass $1"
fi

# generate html
echo -n "Generating html in ${OUT_DIR_HTML} ... "
for tut in tutorial-*; do
grip \
"${tut}/README.md" ${token_argument} --quiet --export --no-inline ${OUT_DIR_HTML}${tut}.html
done
echo "done"

# generate pdf
echo -n "Generating pdf in ${OUT_DIR_PDF} ... "
for tut in $(ls ${OUT_DIR_HTML}); do
chromium-browser --headless --disable-gpu --print-to-pdf=${OUT_DIR_PDF}${tut}.pdf "${OUT_DIR_HTML}${tut}"
done
echo "done"