Skip to content

Instantly share code, notes, and snippets.

@vitali2y
Created April 7, 2026 08:41
Show Gist options
  • Select an option

  • Save vitali2y/61461e2bcb23f1074b9a0c3c70fa2d84 to your computer and use it in GitHub Desktop.

Select an option

Save vitali2y/61461e2bcb23f1074b9a0c3c70fa2d84 to your computer and use it in GitHub Desktop.
Building local ZeroClaw wiki

Below is an example how to build local ZeroClaw wiki (as it is on ZeroClaw official wiki):

➜  git clone https://github.com/zeroclaw-labs/zeroclaw.wiki.git && cd zeroclaw.wiki
➜  zeroclaw.wiki git:(master) ✗ cd src && ln -s Home.md SUMMARY.md && cd -
➜  zeroclaw.wiki git:(master) ✗ ./transform_links.sh -d src
Transformed: src/09.1-Memory-Backends.md
Transformed: src/09.2-Hybrid-Search.md
~...~
Transformed: src/07.1-Agent-Turn-Cycle.md
Transformed: src/12.3-Testing.md
Transformed: src/05.2-Custom-Providers.md
➜  zeroclaw.wiki git:(master) ✗ cat book.toml
[preprocessor.mermaid]
command = "mdbook-mermaid"
[output.html]
additional-js = ["mermaid.min.js", "mermaid-init.js"]
➜  zeroclaw.wiki git:(master) ✗ cargo install mdbook-mermaid                                                                                                                           
~...~
➜  zeroclaw.wiki git:(master) ✗ mdbook-mermaid install
[2026-04-07T08:18:27Z INFO  mdbook_mermaid] Reading configuration file ./book.toml
[2026-04-07T08:18:27Z INFO  mdbook_mermaid] Writing additional files to project directory at .
[2026-04-07T08:18:27Z INFO  mdbook_mermaid] Files & configuration for mdbook-mermaid are installed. You can start using it in your book.
[2026-04-07T08:18:27Z INFO  mdbook_mermaid] Add a code block like:
    ```mermaid
    graph TD;
        A-->B;
        A-->C;
        B-->D;
        C-->D;
    ```
➜  zeroclaw.wiki git:(master) ✗ mdbook build    # or: mdbook serve --open
 INFO Book building has started
 INFO Running the html backend
 INFO HTML book written to `/home/vit/prjs/my_ai/zeroclaw/zeroclaw.wiki/book`
➜  zeroclaw.wiki git:(master) ✗

Now open it by cd book && open index.html in browser.

@vitali2y
Copy link
Copy Markdown
Author

vitali2y commented Apr 7, 2026

#!/usr/bin/env bash

#
# transform_links.sh
# Transforms markdown links with GitHub wiki URLs to local .md file references
#
# Usage:
#   ./transform_links.sh <file.md> [file2.md ...]   # Transform specific files
#   ./transform_links.sh -d <directory>              # Transform all .md files in a directory
#   ./transform_links.sh -i <file.md> [...]          # Edit files in-place (overwrites originals)
#
# Examples:
#   ./transform_links.sh README.md
#   ./transform_links.sh -d ./docs
#   ./transform_links.sh -i README.md CHANGELOG.md

set -euo pipefail

INPLACE=false
DIR_MODE=false
TARGET_DIR=""

usage() {
    echo "Usage:"
    echo "  $0 <file.md> [file2.md ...]   Transform specific files (output to stdout)"
    echo "  $0 -d <directory>             Transform all .md files in a directory"
    echo "  $0 -i <file.md> [...]         Edit files in-place (overwrites originals)"
    exit 1
}

# Parse flags
while getopts ":id:" opt; do
    case $opt in
        i) INPLACE=true ;;
        d) DIR_MODE=true; TARGET_DIR="$OPTARG" ;;
        *) usage ;;
    esac
done
shift $((OPTIND - 1))

# The core sed expression:
# Matches: [Any Text](https://anything/wiki/PAGE-SLUG)
# Captures: link text and the last path segment (page slug)
# Replaces: [Any Text](PAGE-SLUG.md)
SED_EXPR='s|\(\[[^]]*\]\)(https\?://[^))]*/wiki/\([^)]*\))|\1(\2.md)|g'

transform_file() {
    local file="$1"

    if [[ ! -f "$file" ]]; then
        echo "Warning: '$file' not found, skipping." >&2
        return
    fi

    if $INPLACE; then
        # BSD (macOS) and GNU sed both support -i with an empty string for in-place
        if sed --version 2>/dev/null | grep -q GNU; then
            sed -i "$SED_EXPR" "$file"
        else
            sed -i '' "$SED_EXPR" "$file"
        fi
        echo "Transformed: $file" >&2
    else
        sed "$SED_EXPR" "$file"
    fi
}

if $DIR_MODE; then
    [[ -d "$TARGET_DIR" ]] || { echo "Error: '$TARGET_DIR' is not a directory."; exit 1; }
    INPLACE=true  # Directory mode always edits in-place
    find "$TARGET_DIR" -name "*.md" | while read -r f; do
        transform_file "$f"
    done
elif [[ $# -gt 0 ]]; then
    for file in "$@"; do
        transform_file "$file"
    done
else
    usage
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment