Skip to content

Commit

Permalink
feat(scripts): Add script for generating mdbook src chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Mar 30, 2022
1 parent 5057463 commit 5a7f483
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ dist_vim_DATA = citation_audit.vim quotation_audit.vim
dist_data_DATA = functions.zsh

scriptsdir = $(datadir)/scripts
dist_scripts_SCRIPTS = scripts/branch2criticmark.zsh scripts/cover_title.py scripts/diff2marked.zsh scripts/extract_references.js scripts/figure_dash.pl scripts/isbn_format.py scripts/italic_reorder.pl scripts/lazy_quotes.pl scripts/link_verses.js scripts/loadchapters.zsh scripts/msword_escapes.pl scripts/normalize_references.js scripts/ordinal_spaces.pl scripts/renumber_footnotes.pl scripts/reorder_punctuation.pl scripts/series_sort.lua scripts/smart_quotes.pl scripts/split_chapters.zsh scripts/stats.zsh scripts/toc2breaks.lua scripts/unicode_symbols.pl scripts/worklog.zsh
dist_scripts_SCRIPTS = scripts/branch2criticmark.zsh scripts/cover_title.py scripts/diff2marked.zsh scripts/extract_references.js scripts/figure_dash.pl scripts/isbn_format.py scripts/italic_reorder.pl scripts/lazy_quotes.pl scripts/link_verses.js scripts/loadchapters.zsh scripts/msword_escapes.pl scripts/normalize_references.js scripts/ordinal_spaces.pl scripts/renumber_footnotes.pl scripts/reorder_punctuation.pl scripts/series_sort.lua scripts/smart_quotes.pl scripts/split_chapters.zsh scripts/split_mdbook_src.zsh scripts/stats.zsh scripts/toc2breaks.lua scripts/unicode_symbols.pl scripts/worklog.zsh

fontsdir = $(datadir)/fonts
dist_fonts_DATA = fonts/Almendra-Bold.otf fonts/Almendra-BoldItalic.otf fonts/Almendra-Italic.otf fonts/Almendra-Regular.otf fonts/AlmendraDisplay-Regular.otf fonts/AlmendraSC-Bold.otf fonts/AlmendraSC-BoldItalic.otf fonts/AlmendraSC-Italic.otf fonts/AlmendraSC-Regular.otf fonts/FeFlow2.otf fonts/NexaRustExtras-Free.otf fonts/NexaRustHandmade-Extended-Free.otf fonts/NexaRustSans-Black-Free.otf fonts/NexaRustScriptL-0-Free.otf fonts/NexaRustSlab-BlackShadow01-Free.otf fonts/Nymphette.ttf fonts/PrintersOrnamentsOne.ttf
Expand Down
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ AX_SCRIPT([reorder_punctuation.pl])
AX_SCRIPT([series_sort.lua])
AX_SCRIPT([smart_quotes.pl])
AX_SCRIPT([split_chapters.zsh])
AX_SCRIPT([split_mdbook_src.zsh])
AX_SCRIPT([stats.zsh])
AX_SCRIPT([toc2breaks.lua])
AX_SCRIPT([unicode_symbols.pl])
Expand Down
35 changes: 35 additions & 0 deletions scripts/split_mdbook_src.zsh.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!@ZSH@
set -e
set -x

src=$1
dir=$2

echo -e "# Summary\n\n"

i=0
of=00.md

function trunc() {
: > $1
}

trunc $dir/$of

@PANDOC@ $src --markdown-headings=atx --wrap=none --to=commonmark_x-smart+gfm_auto_identifiers --reference-location=section |
@PERL@ -pne 's/{osis=".*"}//g' |
while read line; do
# Check for chapter header
if [[ $line =~ "^# .*" ]]; then
[[ $line =~ ".*unnumbered.*" ]] || let i=$i+1
@PERL@ -pne 's/^# (.*) {.*#([-\w]+).*}/\2 \1/' <<< "$line" |
read slug title
test -n "$slug"
test -n "$title"
of=$(printf %02d $i)-$slug.md
trunc $dir/$of
line="# $title"
echo "[$title](./$of)"
fi
>> $dir/$of <<< $line
done

0 comments on commit 5a7f483

Please sign in to comment.