| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Usage:
|
| 4 | # build/dev-guide.sh build-dev-guide
|
| 5 | #
|
| 6 | # This will clone the oils-for-unix/oils wiki, and build all of the markdown
|
| 7 | # files using doc tools. The docs are saved to _release/VERSION/doc/wiki.
|
| 8 | #
|
| 9 | # This can be used for the dev guide which is located at
|
| 10 | # _release/VERSION/doc/wiki/Dev-Guide.html.
|
| 11 |
|
| 12 | set -e
|
| 13 |
|
| 14 | readonly HTML_BASE_DIR=_release/VERSION
|
| 15 | readonly WIKI_DIR=_tmp/wiki
|
| 16 |
|
| 17 | has-wiki() {
|
| 18 | test -d "$WIKI_DIR"
|
| 19 | }
|
| 20 |
|
| 21 | clone-wiki() {
|
| 22 | if has-wiki; then
|
| 23 | echo "Wiki already cloned to $WIKI_DIR, pulling latest"
|
| 24 |
|
| 25 | pushd "$WIKI_DIR"
|
| 26 | git pull
|
| 27 | popd
|
| 28 | return
|
| 29 | fi
|
| 30 |
|
| 31 | echo "Cloning wiki to $WIKI_DIR"
|
| 32 | mkdir -p "$WIKI_DIR"
|
| 33 | git clone https://github.com/oils-for-unix/oils.wiki.git "$WIKI_DIR"
|
| 34 | }
|
| 35 |
|
| 36 | pre-render-wikilinks() {
|
| 37 | ## GitHub wikis have a unique [[link syntax]] which references topic within
|
| 38 | ## the wiki.
|
| 39 | ##
|
| 40 | ## This function converts that syntax to the traditional
|
| 41 | ## [link syntax](./link-syntax.html) which will render correctly once fed to
|
| 42 | ## doctools.
|
| 43 | local script=$(cat <<'EOF'
|
| 44 | import sys
|
| 45 | import re
|
| 46 |
|
| 47 | def slugify(text: str) -> str:
|
| 48 | """
|
| 49 | The links are given in "human-form" but we need to turn then into links or
|
| 50 | "slugs" which correspond to the rendered file name.
|
| 51 |
|
| 52 | Note: Some titles have commas in them. These are not present in the slug.
|
| 53 | """
|
| 54 | return text.replace(" ", "-").replace(",", "")
|
| 55 |
|
| 56 | link_pattern = re.compile(r"\[\[(.*?)\]\]")
|
| 57 |
|
| 58 | def replacer(match):
|
| 59 | text = match.group(1).strip()
|
| 60 | return f"[{text}](./{slugify(text)}.html)"
|
| 61 |
|
| 62 | input_text = sys.stdin.read()
|
| 63 | output_text = link_pattern.sub(replacer, input_text)
|
| 64 | sys.stdout.write(output_text)
|
| 65 | EOF
|
| 66 | )
|
| 67 |
|
| 68 | python3 -c "$script"
|
| 69 | }
|
| 70 |
|
| 71 | build-one() {
|
| 72 | local path=$1
|
| 73 | local name=$(basename "$path")
|
| 74 | local name=${name%.md} # Remove .md extension
|
| 75 | local name=${name/,//} # Remove commas in names (breaks doctools)
|
| 76 | local title=$(echo "$name" | sed 's/ /-/g')
|
| 77 |
|
| 78 | mkdir -p "$HTML_BASE_DIR/doc/wiki/"
|
| 79 |
|
| 80 | local web_url="../../web"
|
| 81 | build/doc.sh render-only \
|
| 82 | <(pre-render-wikilinks <"$path") \
|
| 83 | "$HTML_BASE_DIR/doc/wiki/$name.html" \
|
| 84 | "$web_url/base.css $web_url/manual.css $web_url/toc.css $web_url/language.css $web_url/code.css" \
|
| 85 | "$title"
|
| 86 | }
|
| 87 |
|
| 88 | build-dev-guide() {
|
| 89 | clone-wiki
|
| 90 | find "$WIKI_DIR" -name '*.md' -print0 | xargs -I {} -0 -- $0 build-one {}
|
| 91 | }
|
| 92 |
|
| 93 | "$@"
|