Created
March 23, 2023 11:35
-
-
Save capjamesg/183f523a00bf786dcad7ab5ebd603c32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make BookParts directory | |
rm -r BookParts && rm book.pdf | |
if [ ! -d "BookParts" ]; then | |
mkdir BookParts | |
fi | |
if [ ! -d "BookParts/new" ]; then | |
mkdir BookParts/new | |
fi | |
for f in _posts/*; | |
do | |
cp $f BookParts/ | |
done | |
for f in BookParts/*; | |
do | |
file=$(basename $f) | |
front_matter=$(sed -n '/---/,/---/p' $f | wc -l) | |
# get the title from the front matter that starts with title: | |
title=$(sed -n '/title:/p' $f | sed 's/title: //') | |
# strip the quotes from the title | |
title=$(echo $title | sed 's/"//g') | |
image=$(sed -n '/image:/p' $f | sed 's/image: //') | |
image=$(echo $image | sed 's/"//g') | |
image=$(echo $image | sed 's/ *$//g') | |
alt_text=$(sed -n '/image_alt_text:/p' $f | sed 's/image_alt_text: //') | |
alt_text=$(echo $alt_text | sed 's/"//g') | |
if [ "$alt_text" != "" ]; then | |
image_alt_text=$alt_text | |
else | |
image_alt_text="[No alt text]" | |
fi | |
if [ "$image" != "" ]; then | |
if [[ $image != *.webp ]]; then | |
echo "![$image_alt_text]($image)\n" >> BookParts/new/$file | |
fi | |
fi | |
echo "# $title\n" >> BookParts/new/$file | |
tail -n +$(($front_matter+3)) BookParts/$file >> BookParts/new/$file | |
done | |
# move /Documents/Introduction.md to the top of the list | |
mv ~/Documents/Introduction.md BookParts/new/2000-introduction.md | |
pandoc -s BookParts/new/* -o book.pdf --toc --toc-depth=2 --pdf-engine=xelatex \ | |
--metadata title="James' Coffee Blog" --metadata author="James (jamesg.blog)" --metadata date="February 25th, 2023" \ | |
--metadata lang="en-US" --metadata mainfont="Times New Roman" --metadata fontsize="12pt" \ | |
--metadata geometry:margin=1in --metadata geometry:a4paper \ | |
--highlight-style pygments \ | |
--metadata link-citations=true | |
# clean up the files | |
rm BookParts/* && rm -r BookParts/new |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment