| 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 | python3 <<'EOF'
|
| 44 | import sys
|
| 45 | import re
|
| 46 |
|
| 47 | def slugify(text: str) -> str:
|
| 48 | """Convert link text to a filename slug."""
|
| 49 | return text.strip().lower().replace(" ", "-").replace(",", "")
|
| 50 |
|
| 51 | pattern = re.compile(r"\[\[(.*?)\]\]")
|
| 52 |
|
| 53 | def replacer(match):
|
| 54 | text = match.group(1).strip()
|
| 55 | slug = slugify(text)
|
| 56 | return f"[{text}](./{slug}.html)"
|
| 57 |
|
| 58 | input_text = sys.stdin.read()
|
| 59 | output_text = pattern.sub(replacer, input_text)
|
| 60 | sys.stdout.write(output_text)
|
| 61 | EOF
|
| 62 | }
|
| 63 |
|
| 64 | build-one() {
|
| 65 | local path=$1
|
| 66 | local name=$(basename "$path")
|
| 67 | local name=${name%.md} # Remove .md extension
|
| 68 | local name=${name/,//} # Remove commas in names (breaks doctools)
|
| 69 | local title=$(echo "$name" | sed 's/ /-/g')
|
| 70 | mkdir -p "$HTML_BASE_DIR/doc/wiki/"
|
| 71 | local web_url="../../web"
|
| 72 | build/doc.sh render-only <(pre-render-wikilinks <"$path") "$HTML_BASE_DIR/doc/wiki/$name.html" "$web_url/base.css $eb_url/manual.css $web_url/toc.css $web_url/language.css $web_url/code.css" "$title"
|
| 73 | }
|
| 74 |
|
| 75 | build-dev-guide() {
|
| 76 | clone-wiki
|
| 77 | # find "$WIKI_DIR" -name '*.md' -print0 | xargs "-P$(nproc)" -I {} -0 -- $0 build-one {}
|
| 78 | find "$WIKI_DIR" -name '*.md' -print0 | xargs -P1 -I {} -0 -- $0 build-one {}
|
| 79 | }
|
| 80 |
|
| 81 | "$@"
|