diff --git a/.github/actions/build-site/action.yml b/.github/actions/build-site/action.yml index afd65309..fa790568 100644 --- a/.github/actions/build-site/action.yml +++ b/.github/actions/build-site/action.yml @@ -1,8 +1,7 @@ name: Build the website description: > - Builds a checkout of this repository into /public, with its topics and - commands from valkey-doc and the command metadata from valkey and the modules, checked out - next to it in the workspace. + Builds a checkout of this repository into /public, with the commands and topics of + the repos in build/doc-sources.toml, checked out next to it in the workspace. inputs: path: @@ -18,57 +17,17 @@ inputs: runs: using: composite steps: - - name: Checkout valkey + # Clones the repos in build/doc-sources.toml next to the website checkout. + - name: Checkout the doc sources if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey - path: valkey - - - name: Checkout valkey-bloom - if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey-bloom - path: valkey-bloom - - - name: Checkout valkey-doc - if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey-doc - path: valkey-doc - - - name: Checkout valkey-json - if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey-json - path: valkey-json - - - name: Checkout valkey-search - if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey-search - path: valkey-search - - - name: Checkout valkey-large-object - if: inputs.checkout-content == 'true' - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - repository: valkey-io/valkey-large-object - path: valkey-large-object + shell: bash + working-directory: ${{ inputs.path }} + run: ./build/checkout-doc-sources.sh .. - name: Init commands and topics shell: bash working-directory: ${{ inputs.path }} - run: | - ./build/init-topics.sh ../valkey-doc/topics - ./build/init-commands.sh ../valkey-doc/commands \ - ../valkey/src/commands ../valkey-bloom/src/commands \ - ../valkey-json/src/commands ../valkey-search/src/commands \ - ../valkey-large-object/src/commands + run: ./build/init-docs.sh .. - name: Build only uses: shalzz/zola-deploy-action@1be083648a1db2853ce4970e381740c0e2fd06de # v0.23.6 diff --git a/.gitignore b/.gitignore index ff9171c0..7c9e7248 100644 --- a/.gitignore +++ b/.gitignore @@ -1,12 +1,9 @@ .DS_Store public package-lock.json -build-bloom-command-json build-command-docs build-command-json -build-json-command-json -build-search-command-json -build-large-object-command-json +build-nav build-topics content/commands/* !content/commands/_index.md diff --git a/README.md b/README.md index cdc2ec3a..8bccfcd6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Valkey.io website This repo contains the source for the valkey.io website (build scripts, template, blog posts, stylesheets, etc.). -The build integrates content from [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) and the commands definitions from [`valkey-io/valkey`](https://github.com/valkey-io/valkey), [`valkey-io/valkey-bloom`](https://github.com/valkey-io/valkey-bloom), and [`valkey-io/valkey-json`](https://github.com/valkey-io/valkey-json) (see [Build Locally](#build-locally) below for more details) +The build integrates the command and topic docs from [`valkey-io/valkey`](https://github.com/valkey-io/valkey) and the module repos, with [`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) as the fallback (see [Building additional content](#building-additional-content) below). ## Contributing @@ -43,79 +43,65 @@ The script downloads the SPDX license list, so it needs network access. ## Building additional content **By default, the site will build without documentation topics or the command reference.** -The content for documentation topics is stored within the `valkey-io/valkey-doc` repo. -The content for the command reference page is in the `valkey-io/valkey` repo. +The command and topic pages live next to the code: valkey's in [`valkey-io/valkey`](https://github.com/valkey-io/valkey), each module's in its own repo. +[`valkey-io/valkey-doc`](https://github.com/valkey-io/valkey-doc) is the fallback: it holds the pages that haven't moved yet and the pages that live there, such as the Valkey Bundle page, and `modules.json`. The clients and integrations pages (`/clients/`, `/integrations/`) are built from `_data/libraries/` in this repo, so they need no other repo. -If you want to build the site with this content, you'll need to have a local copy of `valkey-io/valkey-doc` and `valkey-io/valkey` _outside_ of this repo. -Then follow the instructions to [build the documentation topics](#building-the-documentation-topics) and/or [build the command reference](#building-the-command-reference). -The instructions show how to use scripts that create symbolic links to the `valkey-io/valkey-doc` and `valkey-io/valkey` repos as well as create a series of empty stub files that tell Zola to create pages. +To build the site with the docs, check out the repos listed in `build/doc-sources.toml` next to this repo, then gather their docs (the scripts need Python 3.11 or later to read the TOML file): -### Building the documentation topics - -Documentation 'topics' (i.e. `/topics/keyspace/`, `/topics/encryption/`, `/topics/transactions/`) source content from `valkey-io/valkey-doc`. - -```mermaid -flowchart TD - A[Webpage: /topics/keyspace/ ] - A --> B[Template: valkey-io/valkey-website] - B --> H[Repo: valkey-io/valkey-doc ] --> I[File: /topics/keyspace.md ] --> Y[Topic content] +```shell +# Clones the repos that aren't there yet (shallow, so it's quick). +./build/checkout-doc-sources.sh .. +# Run again when you add or remove a command or topic, or change a command's group or container. +./build/init-docs.sh .. ``` -Let's say that this repo and your local copy of `valkey-io/valkey-doc` reside in the same directory. -First, stop the `zola serve` process if you're running it. -From the root directory of this repo run: +Then restart `zola serve`. +`init-docs.sh` links the docs into `build-*` directories and writes a stub file in `content/commands/` or `content/topics/` for each page; all of them are ignored by git. +Edit the pages in their own repos; every page links to its source with "Update this Page on GitHub!". +The script uses [jq](https://jqlang.org/), if installed, to store each command's group and container for the documentation menu; without it the site still builds, but more slowly. -```shell -# You should only need to run this once or when you add a new topic. -./build/init-topics.sh ../valkey-doc/topics -``` +### Where the docs come from -Then, restart Zola. -Point your browser at `http://127.0.0.1:1111/topics/` and you should see the fully populated list of topics. -All files created in this process are ignored by git. -Commit your changes to your local copy of `valkey-io/valkey-doc`. +Each repo in `build/doc-sources.toml` can provide: -### Building the command reference +| File | Page | +|---|---| +| `docs/commands/.md` | `/commands//`, with the metadata from `src/commands/.json` | +| `docs/topics/.md`, and images next to it | `/topics//` | +| `docs/nav.yml` | Its entries in the documentation menu | +| `docs/groups.json` (core repo only) | The command groups | -The command reference (i.e. `/commands/set/`, `/commands/get/`, `/commands/lolwut/`) sources information from `valkey-io/valkey`, `valkey-io/valkey-bloom`, and `valkey-io/valkey-doc`. -`valkey-io/valkey`, `valkey-io/valkey-bloom`, `valkey-io/valkey-json`, `valkey-io/valkey-search` and `valkey-io/valkey-large-object` provides the command metadata (items like computational complexity, version history, arguments, etc) -whilst `valkey-io/valkey-doc` provides the command description and the command reply. +`src/commands/.json` is the command's metadata (arguments, complexity, history); it gets a page only if some repo has `docs/commands/.md`. +The fallback repo (valkey-doc) has the same files without the `docs/` prefix, its menu files in `nav.yml` and `modules-nav/.yml`. +A code repo's file wins over the fallback's copy with the same name. +If two code repos provide the same command, topic, image or command JSON, `init-docs.sh` lists both paths and fails, so a URL can't silently change source. +The menu merges the core repo's `nav.yml` with the other repos' menu files, in the order of `build/doc-sources.toml`, then the fallback's menu files that no repo is named after. -```mermaid -flowchart TD - A[Webpage: valkey.io/commands/set] - A --> B[Template: valkey-io/valkey-website] - B --> F[Repo: valkey-io/valkey ] --> G[File: /src/commands/set.json ] --> X[Command Metadata] - B --> H[Repo: valkey-io/valkey-doc ] --> I[File: /commands/set.md ] --> Y[Command Description] - H --> J[Files: /resp2_replies.json,
/resp3_replies.json] --> Z[Command Reply] -``` +`/topics/modules-api-ref/` is generated from valkey's `src/module.c` with `utils/generate-module-api-doc.rb`, which needs Ruby 2.3 or later and valkey's release tags (`checkout-doc-sources.sh` fetches them). +Without Ruby, the fallback's copy is used if it has one. -Let's say that this repo and your local copy of `valkey-io/valkey-doc`, `valkey-io/valkey-bloom`, `valkey-io/valkey-json`, `valkey-io/valkey-search`, -`valkey-io/valkey-large-object` and `valkey-io/valkey` reside in the same directories. +### Adding a repo -First, stop the `zola serve` process if you're running it. -From the root directory of this repo run: +Add a `[[source]]` table to `build/doc-sources.toml`; nothing else in this repo needs to change. -```shell -# You should only need to run this once or when you add a new command, -# or when a command's group or container changes. -./build/init-commands.sh ../valkey-doc/commands ../valkey/src/commands \ - ../valkey-bloom/src/commands ../valkey-json/src/commands ../valkey-search/src/commands \ - ../valkey-large-object/src/commands +```toml +[[source]] +name = "valkey-bloom" +repository = "valkey-io/valkey-bloom" +branch = "unstable" +path = "valkey-bloom" +role = "module" ``` -The script uses [jq](https://jqlang.org/), if installed, to store each command's group and container for the documentation menu. -Without jq, the site still builds correctly, but more slowly. - -Then, restart Zola. -Point your browser at `http://127.0.0.1:1111/commands/` and you should see the fully populated list of topics. -All files created in this process are ignored by git. -Commit your changes to your local copy of `valkey-io/valkey-doc` for description changes and `valkey-io/valkey` for command JSON changes (if you have any). +- `name`: the repo's name in the menu data and the stub comments, and the name of its fallback menu file (`modules-nav/.yml`). +- `repository` and `branch`: what CI checks out, and where "Update this Page on GitHub!" points. To build against a fork's branch, change these two. +- `path`: the checkout directory, relative to the directory that holds this repo. +- `role`: `core` (valkey: the core menu and `groups.json`), `fallback` (valkey-doc), or `module` (its menu entries get a "module" label). ### Checking links -Pull requests and deploys check the built site for links to missing pages or `#anchors`, and for valkey-doc links that weren't converted to site URLs. +Pull requests and deploys check the built site for links to missing pages or `#anchors`, and for doc links that weren't converted to site URLs. To run the checks locally (needs [lychee](https://lychee.cli.rs/) and jq), set up the topics and commands as above, then: ```shell diff --git a/build/checkout-doc-sources.sh b/build/checkout-doc-sources.sh new file mode 100755 index 00000000..9a3d25db --- /dev/null +++ b/build/checkout-doc-sources.sh @@ -0,0 +1,23 @@ +#!/bin/bash +# See README for usage. +# Clones every repo in build/doc-sources.toml into the directory given as the +# first argument (default: the parent directory of this repo). Repos that are +# already there are left alone. +set -e + +registry=$(python3 "$(dirname "$0")/doc-sources.py") +cd "${1:-$(dirname "$0")/../..}" + +while IFS=$'\t' read -r name repository branch path role; do + if [ -e "$path" ]; then + echo "$name: $path exists, skipped" + continue + fi + git clone --quiet --depth 1 --branch "$branch" "https://github.com/$repository.git" "$path" + # The core repo's release tags fill in "Available since" in the + # generated module API reference. Each tag needs only its own commit. + if [ "$role" = core ]; then + git -C "$path" fetch --quiet --depth 1 origin '+refs/tags/*:refs/tags/*' + fi + echo "$name: cloned $repository $branch into $path" +done <<< "$registry" diff --git a/build/doc-sources.py b/build/doc-sources.py new file mode 100755 index 00000000..abb0d651 --- /dev/null +++ b/build/doc-sources.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 +# Checks build/doc-sources.toml (or the file given as the first argument) and +# prints one tab-separated line per source, in file order: +# name repository branch path role +# Used by build/checkout-doc-sources.sh and build/init-docs.sh. +import sys + +if sys.version_info < (3, 11): + sys.exit("build/doc-sources.py needs Python 3.11 or later (for tomllib), found %d.%d" + % sys.version_info[:2]) + +import os +import tomllib + +KEYS = ["name", "repository", "branch", "path", "role"] +ROLES = ["core", "module", "fallback"] + +path = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(os.path.abspath(__file__)), "doc-sources.toml") + + +def fail(message): + sys.exit("%s: %s" % (path, message)) + + +try: + with open(path, "rb") as f: + sources = tomllib.load(f).get("source", []) +except (OSError, tomllib.TOMLDecodeError) as e: + fail(e) + +if not isinstance(sources, list) or not all(isinstance(s, dict) for s in sources): + fail("'source' must be an array of tables ([[source]])") + +for n, source in enumerate(sources, 1): + for key in KEYS: + value = source.get(key) + if not isinstance(value, str) or not value or any(c in value for c in "\t\n"): + fail("source %d (%s) needs '%s', a non-empty string on one line" + % (n, source.get("name", "no name"), key)) + if source["role"] not in ROLES: + fail("source %d (%s) has role '%s', must be one of %s" + % (n, source["name"], source["role"], ", ".join(ROLES))) + +for role in ["core", "fallback"]: + found = [s["name"] for s in sources if s["role"] == role] + if len(found) != 1: + fail("needs exactly one source with role '%s', found %d%s" + % (role, len(found), " (%s)" % ", ".join(found) if found else "")) + +for source in sources: + print("\t".join(source[key] for key in KEYS)) diff --git a/build/doc-sources.toml b/build/doc-sources.toml new file mode 100644 index 00000000..6178bf4a --- /dev/null +++ b/build/doc-sources.toml @@ -0,0 +1,84 @@ +# The repos the documentation comes from. See "Building additional content" +# in README.md. +# +# One [[source]] table per repo. Their order is the menu merge order: the +# other repos' menu files are merged into the core menu in this order. +# +# name The repo's name in the menu data and the stub comments, and the +# name of its fallback menu file (modules-nav/.yml in the +# fallback repo). +# repository The GitHub repo (owner/name) that build/checkout-doc-sources.sh +# clones, and where "Update this Page on GitHub!" points. +# branch The branch to clone and link to. To build against a fork's +# branch, change repository and branch. +# path The checkout directory, relative to the directory that holds +# this repo. +# role One of: +# core valkey: the core menu (docs/nav.yml), groups.json and +# the generated module API reference. Exactly one. +# module A module: its menu entries get a "module" label. +# fallback valkey-doc: pages, menus and data files that haven't +# moved to a code repo yet, and pages that live there, +# such as the Valkey Bundle page. Its menu files that +# no source is named after are merged last. Exactly one. +# +# To add a module, add a [[source]] table with role = "module" where its menu +# entries should go, for example: +# +# [[source]] +# name = "valkey-example" +# repository = "valkey-io/valkey-example" +# branch = "main" +# path = "valkey-example" +# role = "module" +# +# build/doc-sources.py checks this file and prints it for the shell scripts. + +[[source]] +name = "valkey" +repository = "valkey-io/valkey" +branch = "unstable" +path = "valkey" +role = "core" + +[[source]] +name = "valkey-bloom" +repository = "valkey-io/valkey-bloom" +branch = "unstable" +path = "valkey-bloom" +role = "module" + +[[source]] +name = "valkey-json" +repository = "valkey-io/valkey-json" +branch = "unstable" +path = "valkey-json" +role = "module" + +[[source]] +name = "valkey-search" +repository = "valkey-io/valkey-search" +branch = "main" +path = "valkey-search" +role = "module" + +[[source]] +name = "valkey-ldap" +repository = "valkey-io/valkey-ldap" +branch = "main" +path = "valkey-ldap" +role = "module" + +[[source]] +name = "valkey-large-object" +repository = "valkey-io/valkey-large-object" +branch = "main" +path = "valkey-large-object" +role = "module" + +[[source]] +name = "valkey-doc" +repository = "valkey-io/valkey-doc" +branch = "main" +path = "valkey-doc" +role = "fallback" diff --git a/build/init-commands.sh b/build/init-commands.sh deleted file mode 100755 index f973c766..00000000 --- a/build/init-commands.sh +++ /dev/null @@ -1,139 +0,0 @@ -#!/bin/bash -# See README for usage -# This file will create stub files for all the commands and create the correct symbolic links for the JSON files - -# first check to make sure there are arguments -if [ -z "$1" ]; then - echo "You must supply a path to the command docs as the first argument" - exit 1 -fi - -if [ -z "$2" ]; then - echo "You must supply a path to the command json as the second argument" - exit 1 -fi - -# check for validity of these arguments as paths -if [ ! -d "$1" ]; then - echo "The command doc directory must exist and be a valid path" - exit 1 -fi - -if [ ! -d "$2" ]; then - echo "The command JSON directory must exist and be a valid path" - exit 1 -fi - -if [ ! -d "$3" ]; then - echo "The bloom module command JSON directory must exist and be a valid path" - exit 1 -fi - -if [ ! -d "$4" ]; then - echo "The JSON module command JSON directory must exist and be a valid path" - exit 1 -fi - -if [ ! -d "$5" ]; then - echo "The Search module command JSON directory must exist and be a valid path" - exit 1 -fi - -if [ ! -d "$6" ]; then - echo "The Large Object module command JSON directory must exist and be a valid path" - exit 1 -fi - -# Uppercase aliases (/commands/GET/) collide with the lowercase pages -# (/commands/get/) on case-insensitive filesystems (macOS default). Since -# Zola 0.23, `zola build` may then write the alias redirect over the real -# page, so skip the aliases there. Override with VALKEY_COMMAND_ALIASES=1 -# (always generate) or VALKEY_COMMAND_ALIASES=0 (never generate). -if [ -n "$VALKEY_COMMAND_ALIASES" ]; then - with_aliases=$VALKEY_COMMAND_ALIASES -else - probe=$(mktemp ./.case-probe-XXXXXX) - if [ -e "$(tr '[:lower:]' '[:upper:]' <<< "$probe")" ]; then - with_aliases=0 - echo "Case-insensitive filesystem detected: skipping uppercase command aliases." - else - with_aliases=1 - fi - rm -f "$probe" -fi - -ln -sfn $1 ./build-command-docs -ln -sfn $2 ./build-command-json -ln -sfn $3 ./build-bloom-command-json -ln -sfn $4 ./build-json-command-json -ln -sfn $5 ./build-search-command-json -ln -sfn $6 ./build-large-object-command-json - -# The documentation menu needs each command's full name, container and group. -# They're written to the stub files below (using jq), so that the templates -# don't have to load every command's JSON file on every page. Without jq, the -# templates read the JSON files instead, which makes the build slower. -if command -v jq >/dev/null; then - have_jq=1 -else - have_jq=0 - echo "jq not found: the site will build correctly, but more slowly." -fi - -for fname in $(find $1 -maxdepth 1 -iname "*.md") -do - base=${fname##*/} - command=${base%.*} - command_upper=$(awk '{ print toupper($0) }' <<< $command) - if [[ "$command" != "index" ]]; then - json_file="" - if [ -f "$2/$command.json" ]; then - metadata_path="/commands/$command.json in the 'valkey' repo" - json_file="$2/$command.json" - elif [ -f "$3/$command.json" ]; then - metadata_path="/commands/$command.json in the 'valkey-bloom' repo" - json_file="$3/$command.json" - elif [ -f "$4/$command.json" ]; then - metadata_path="/commands/$command.json in the 'valkey-json' repo" - json_file="$4/$command.json" - elif [ -f "$5/$command.json" ]; then - metadata_path="/commands/$command.json in the 'valkey-search' repo" - json_file="$5/$command.json" - elif [ -f "$6/$command.json" ]; then - metadata_path="/commands/$command.json in the 'valkey-large-object' repo" - json_file="$6/$command.json" - fi - # TOML lines with the command's name, container and group, for the menu. - menu_data="" - if [ "$have_jq" = 1 ] && [ -n "$json_file" ]; then - menu_fields=$(jq -r 'to_entries[0] - | ((.value.container // "") | ascii_upcase) as $c - | "command_name = \((($c + " " + .key) | ltrimstr(" ") | ascii_upcase) | @json)", - "command_container = \($c | @json)", - "command_group = \((.value.group // "") | @json)"' "$json_file") - menu_data=$(printf '[extra]\n%s' "$menu_fields") - fi - if [ "$with_aliases" = 1 ]; then - aliases_line="aliases = [\"/commands/$command_upper/\"]" - else - aliases_line="# Uppercase alias skipped, see build/init-commands.sh" - fi - cat << EOF > "./content/commands/$command.md" -+++ -# This is a generated stub file. -# To edit the command description see /commands/$command.md in the 'valkey-doc' repo -# The command metadata is generated from $metadata_path -$aliases_line -$menu_data -+++ -EOF -fi -done - -echo "Command stub files created." - -for datafile in groups.json resp2_replies.json resp3_replies.json modules.json; do - ln -sf "../${1}/../${datafile}" "./_data/${datafile}" - - echo "Created link to ${datafile}" -done diff --git a/build/init-docs.sh b/build/init-docs.sh new file mode 100755 index 00000000..325f02e0 --- /dev/null +++ b/build/init-docs.sh @@ -0,0 +1,299 @@ +#!/bin/bash +# See README for usage. +# Gathers the command and topic docs from the repos listed in +# build/doc-sources.toml, checked out under the directory given as the first +# argument (default: the parent directory of this repo), and creates the stub +# files that tell Zola to build a page for each command and topic. + +cd "$(dirname "$0")/.." || exit 1 + +sources_arg=${1:-..} +if [ ! -d "$sources_arg" ]; then + echo "The sources directory '$sources_arg' must exist and be a valid path" + exit 1 +fi +sources=$(cd "$sources_arg" && pwd -P) +# Links are relative when the argument is, so that they also work where the +# workspace is mounted elsewhere (zola-deploy-action runs in a container). All +# links are one directory deep. +case "$sources_arg" in + /*) link_prefix=${sources_arg%/} ;; + *) link_prefix=../${sources_arg%/} ;; +esac + +# ln -s for a file under $sources, from a link one directory deep. +link_source() { # + ln -s "$link_prefix/${1#"$sources"/}" "$2" +} + +# check for old style /docs/topics +if [ -e "content/docs/topics" ]; then + echo "Documentation topic files have moved. Delete content/docs/topics before proceeding." + exit 1 +fi + +# The registry: one line per repo, in menu order. doc-sources.py checks that +# there is exactly one core and one fallback repo. Arrays rather than an +# associative array, for the bash 3.2 that ships with macOS. +registry=$(python3 build/doc-sources.py) || exit 1 +names=(); repositories=(); branches=(); paths=() +core=""; fallback="" +while IFS=$'\t' read -r name repository branch path role; do + i=${#names[@]} + names[i]=$name; repositories[i]=$repository; branches[i]=$branch; paths[i]=$path + case "$role" in + core) core=$i ;; + fallback) fallback=$i ;; + esac + if [ ! -d "$sources/$path" ]; then + echo "$name must be checked out at $sources/$path (see build/checkout-doc-sources.sh)" + exit 1 + fi +done <<< "$registry" + +duplicates=0 + +# claim +# Links the file into the build directory, unless a repo processed earlier +# already provides that name: the fallback repo then loses silently, any other +# repo is a duplicate. Sets `claimed` for the caller. +claim() { + local target="$1/${2##*/}" + claimed=0 + if [ -e "$target" ] || [ -L "$target" ]; then + if [ "$3" != "$fallback" ]; then + local first + first=$(readlink "$target") && first=${first#"$link_prefix"/} || first=$target + echo "Duplicate: ${2##*/} is provided by both $first and ${2#"$sources"/}" + duplicates=1 + fi + return + fi + link_source "$2" "$target" + claimed=1 +} + +# Front matter lines that record where a page's source is, for the edit link. +source_extra() { + printf '[extra]\nsource_repository = "%s"\nsource_branch = "%s"\nsource_path = "%s"\n' \ + "${repositories[$1]}" "${branches[$1]}" "$2" +} + +# Code repos first, then the fallback. +order=() +for i in "${!names[@]}"; do [ "$i" = "$fallback" ] || order+=("$i"); done +order+=("$fallback") + +docs_dir() { # + if [ "$1" = "$fallback" ]; then echo "$2"; else echo "docs/$2"; fi +} + +### Topics + +rm -rf build-topics +mkdir build-topics + +write_topic_stub() { # + local stub="./content/topics/$1.md" + if [ -f "./build/custom-frontmatter/topics/$1.toml" ]; then + { + echo "+++" + cat "./build/custom-frontmatter/topics/$1.toml" + source_extra "$2" "$3" + echo "+++" + } > "$stub" + else + cat << EOF > "$stub" ++++ +# This is a generated stub file. +# To edit the content see $3 in the '${names[$2]}' repo +aliases = ["/docs/topics/$1/"] +$(source_extra "$2" "$3") ++++ +EOF + fi +} + +topic_from() { # + local base=${1##*/} + claim build-topics "$1" "$2" + if [ "$claimed" = 1 ] && [ "${base%.md}" != "$base" ] && [ "$base" != "index.md" ]; then + write_topic_stub "${base%.md}" "$2" "$3" + fi +} + +# The module API reference is generated from the core repo's src/module.c. +# It needs Ruby >= 2.3, and the core repo's git tags for "Available since". +generate_api_ref() { + local valkey="$sources/${paths[$core]}" + if ! [ -f "$valkey/utils/generate-module-api-doc.rb" ]; then + echo "Warning: $valkey/utils/generate-module-api-doc.rb not found: modules-api-ref.md is not generated, the fallback repo's copy is used if it has one." + return 1 + fi + if ! ruby -e 'exit(Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3"))' 2>/dev/null; then + echo "Warning: Ruby >= 2.3 not found: modules-api-ref.md is not generated, the fallback repo's copy is used if it has one." + return 1 + fi + if ! (cd "$valkey" && ruby utils/generate-module-api-doc.rb) > build-topics/modules-api-ref.md; then + echo "Warning: utils/generate-module-api-doc.rb failed: the fallback repo's modules-api-ref.md is used if it has one." + rm -f build-topics/modules-api-ref.md + return 1 + fi + echo "Generated modules-api-ref.md from ${names[$core]} src/module.c." +} + +for i in "${order[@]}"; do + if [ "$i" = "$fallback" ] && [ ! -e build-topics/modules-api-ref.md ] && generate_api_ref; then + write_topic_stub modules-api-ref "$core" src/module.c + fi + dir=$(docs_dir "$i" topics) + for fname in "$sources/${paths[$i]}/$dir"/*; do + [ -f "$fname" ] && topic_from "$fname" "$i" "$dir/${fname##*/}" + done +done + +echo "Topic stub files created at content/topics." + +for fname in build-topics/*; do + case "$(tr '[:upper:]' '[:lower:]' <<< "$fname")" in + *.png|*.jpg|*.jpeg|*.gif) cp "$fname" ./content/topics/ ;; + esac +done +echo "Copied images to topics directory." + +### Commands + +# Uppercase aliases (/commands/GET/) collide with the lowercase pages +# (/commands/get/) on case-insensitive filesystems (macOS default). Since +# Zola 0.23, `zola build` may then write the alias redirect over the real +# page, so skip the aliases there. Override with VALKEY_COMMAND_ALIASES=1 +# (always generate) or VALKEY_COMMAND_ALIASES=0 (never generate). +if [ -n "$VALKEY_COMMAND_ALIASES" ]; then + with_aliases=$VALKEY_COMMAND_ALIASES +else + probe=$(mktemp ./.case-probe-XXXXXX) + if [ -e "$(tr '[:lower:]' '[:upper:]' <<< "$probe")" ]; then + with_aliases=0 + echo "Case-insensitive filesystem detected: skipping uppercase command aliases." + else + with_aliases=1 + fi + rm -f "$probe" +fi + +# The command metadata (src/commands/*.json) of every repo but the fallback. +rm -rf build-command-json +mkdir build-command-json +for i in "${order[@]}"; do + [ "$i" = "$fallback" ] && continue + for fname in "$sources/${paths[$i]}/src/commands"/*.json; do + [ -f "$fname" ] && claim build-command-json "$fname" "$i" + done +done + +# The documentation menu needs each command's full name, container and group. +# They're written to the stub files below (using jq), so that the templates +# don't have to load every command's JSON file on every page. Without jq, the +# templates read the JSON files instead, which makes the build slower. +if command -v jq >/dev/null; then + have_jq=1 +else + have_jq=0 + echo "jq not found: the site will build correctly, but more slowly." +fi + +write_command_stub() { # + local command=$1 command_upper metadata_path="" json_file="" menu_fields="" j + command_upper=$(awk '{ print toupper($0) }' <<< "$command") + for j in "${order[@]}"; do + if [ "$j" != "$fallback" ] && [ -f "$sources/${paths[$j]}/src/commands/$command.json" ]; then + metadata_path="src/commands/$command.json in the '${names[$j]}' repo" + json_file="build-command-json/$command.json" + break + fi + done + # TOML lines with the command's name, container and group, for the menu. + if [ "$have_jq" = 1 ] && [ -n "$json_file" ]; then + menu_fields=$(jq -r 'to_entries[0] + | ((.value.container // "") | ascii_upcase) as $c + | "command_name = \((($c + " " + .key) | ltrimstr(" ") | ascii_upcase) | @json)", + "command_container = \($c | @json)", + "command_group = \((.value.group // "") | @json)"' "$json_file") + fi + if [ "$with_aliases" = 1 ]; then + aliases_line="aliases = [\"/commands/$command_upper/\"]" + else + aliases_line="# Uppercase alias skipped, see build/init-docs.sh" + fi + cat << EOF > "./content/commands/$command.md" ++++ +# This is a generated stub file. +# To edit the command description see $3 in the '${names[$2]}' repo +# The command metadata is generated from $metadata_path +$aliases_line +$(source_extra "$2" "$3") +$menu_fields ++++ +EOF +} + +rm -rf build-command-docs +mkdir build-command-docs +for i in "${order[@]}"; do + dir=$(docs_dir "$i" commands) + for fname in "$sources/${paths[$i]}/$dir"/*.md; do + [ -f "$fname" ] || continue + claim build-command-docs "$fname" "$i" + base=${fname##*/} + if [ "$claimed" = 1 ] && [ "$base" != "index.md" ]; then + write_command_stub "${base%.md}" "$i" "$dir/$base" + fi + done +done + +echo "Command stub files created." + +if [ "$duplicates" = 1 ]; then + echo "Each command and topic must come from one repo. Remove the duplicates above." + exit 1 +fi + +### Menu and data files + +# link : links to the first candidate that exists. +link_first() { + local link=$1 f + shift + rm -f "$link" + for f in "$@"; do + if [ -f "$f" ]; then + link_source "$f" "$link" + echo "Linked $link to ${f#"$sources"/}" + return + fi + done +} + +fallback_dir="$sources/${paths[$fallback]}" +core_dir="$sources/${paths[$core]}" + +rm -rf build-nav +mkdir build-nav +link_first build-nav/nav.yml "$core_dir/docs/nav.yml" "$fallback_dir/nav.yml" +for i in "${!names[@]}"; do + if [ "$i" != "$core" ] && [ "$i" != "$fallback" ]; then + link_first "build-nav/${names[$i]}.yml" "$sources/${paths[$i]}/docs/nav.yml" "$fallback_dir/modules-nav/${names[$i]}.yml" + fi +done +# The fallback's own menu: its menu files that no source is named after. +rm -f "build-nav/${names[$fallback]}.yml" +for f in "$fallback_dir"/modules-nav/*.yml; do + [ -f "$f" ] && [ ! -e "build-nav/$(basename "$f")" ] || continue + { cat "$f"; echo; } >> "build-nav/${names[$fallback]}.yml" + echo "Added ${f#"$sources"/} to build-nav/${names[$fallback]}.yml" +done + +link_first _data/groups.json "$core_dir/docs/groups.json" "$fallback_dir/groups.json" +for datafile in modules.json resp2_replies.json resp3_replies.json; do + link_first "_data/$datafile" "$fallback_dir/$datafile" +done diff --git a/build/init-topics.sh b/build/init-topics.sh deleted file mode 100755 index 2d1133b8..00000000 --- a/build/init-topics.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -# See README for usage -# This file will create stub files for all the topics. - -# first check to make sure there are arguments -if [ -z "$1" ]; then - echo "You must supply a path to the topics as the first argument" - exit 1 -fi - -# check for validity of the argument as a path -if [ ! -d "$1" ]; then - echo "The topics directory must exist and be a valid path" - exit 1 -fi - -# check for old style /docs/topics -if [ -e "content/docs/topics" ]; then - echo "Documentation topic files have moved. Delete content/docs/topics before proceeding." - exit 1 -fi - -# Create symlink to topics, except if it already exists and points to the same directory. -if [ ! -L build-topics ] || [ "$(readlink build-topics)" != "$1" ]; then - ln -sfn "$1" ./build-topics -fi - -for fname in $(find $1 -maxdepth 1 -iname "*.md") -do - base=${fname##*/} - topic=${base%.*} - - if [[ "$topic" != "index" ]]; then - if [ -f "./build/custom-frontmatter/topics/$topic.toml" ]; then - echo "+++" >> "./content/topics/$topic.md" - cat "./build/custom-frontmatter/topics/$topic.toml" >> "./content/topics/$topic.md" - echo "+++" >> "./content/topics/$topic.md" - else - cat << EOF > "./content/topics/$topic.md" -+++ -# This is a generated stub file. -# To edit the content see /topic/$topic.md in the 'valkey-doc' repo -aliases = ["/docs/topics/$topic/"] -+++ -EOF -fi -fi -done - -echo "Topic stub files created at content/topics." - -for fname in $(find $1 -maxdepth 1 -iname "*.png" -o -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.gif") -do - base=${fname##*/} - cp ${fname} ./content/topics/${base} -done -echo "Copied images to topics directory." - diff --git a/config.toml b/config.toml index 98da73ff..3cbe7208 100644 --- a/config.toml +++ b/config.toml @@ -28,19 +28,17 @@ theme = "github-dark-default" [extra] command_description_path = "../build-command-docs/" command_json_path = "../build-command-json/" -command_bloom_json_path = "../build-bloom-command-json/" -command_json_json_path = "../build-json-command-json/" -command_search_json_path = "../build-search-command-json/" -command_large_object_json_path = "../build-large-object-command-json/" doc_topic_path = "../build-topics/" -# Documentation menu. The core menu is nav.yml in the valkey docs, next to -# the topics directory. Other sources, such as modules, can provide a menu -# file that is merged into it, in the order listed here. Without nav.yml, the -# menu only has the command reference. -nav_path = "../build-topics/../nav.yml" -nav_sources_path = "../build-topics/../modules-nav/" -nav_sources = ["valkey-bloom", "valkey-json", "valkey-search", "valkey-ldap", "valkey-bundle", "valkey-large-object"] +# The repos the docs come from (see README). +doc_sources_path = "../build/doc-sources.toml" + +# Documentation menu, gathered by build/init-docs.sh. The core menu is the +# core repo's nav.yml. The other repos can provide a menu file that is merged +# into it, in the order of doc_sources_path. Without nav.yml, the menu only +# has the command reference. +nav_path = "../build-nav/nav.yml" +nav_sources_path = "../build-nav/" # Topics with known problems, shown with a "This page is under review" note. review_list = [ @@ -65,12 +63,3 @@ in = "client-development" title = "Valkey Admin" url = "https://valkey-admin.valkey.io/" in = "getting-started" - -# Labels shown next to menu entries from other sources, by source name. Only -# modules get one; valkey-bundle isn't a module. -[extra.nav_badges] -"valkey-bloom" = "module" -"valkey-json" = "module" -"valkey-search" = "module" -"valkey-ldap" = "module" -"valkey-large-object" = "module" diff --git a/content/community/_index.md b/content/community/_index.md index 107f465e..db76f2b1 100644 --- a/content/community/_index.md +++ b/content/community/_index.md @@ -38,8 +38,8 @@ cards = [ { url = "https://github.com/valkey-io/valkey/issues/new?assignees=&labels=&projects=&template=bug_report.md&title=%5BBUG%5D", text = "Report a Bug" }, { url = "https://github.com/valkey-io/valkey/blob/unstable/SECURITY.md", text = "Security Policy" } ] }, - { icon = "icon-book.svg", title = "Contribute to Documentation", description = "Help make Valkey easier to learn and use. Documentation content, tutorials, and topic guides live in the valkey-doc repository and welcome pull requests.", links = [ - { url = "https://github.com/valkey-io/valkey-doc", text = "valkey-doc Repository" } + { icon = "icon-book.svg", title = "Contribute to Documentation", description = "Help make Valkey easier to learn and use. Command pages and topic guides live next to the code, in valkey and in each module's repository, and welcome pull requests. Every page links to its source.", links = [ + { url = "https://github.com/valkey-io/valkey/tree/unstable/docs", text = "Valkey Documentation Source" } ] }, { icon = "icon-bulb.svg", title = "Feature Requests", description = "We value your ideas! If you have a suggestion for a new feature, submit a feature request on GitHub and help shape the roadmap.", links = [ { url = "https://github.com/valkey-io/valkey/issues/new?assignees=&labels=&projects=&template=feature_request.md&title=%5BNEW%5D", text = "Submit a Feature Request" } diff --git a/templates/command-page.html b/templates/command-page.html index 8b1ca83a..1366f81d 100644 --- a/templates/command-page.html +++ b/templates/command-page.html @@ -6,11 +6,7 @@ {% set command_description = load_data(path=config.extra.command_description_path ~ page.slug ~ ".md", required= false) %} {% set command_sources = [ - load_data(path= config.extra.command_json_path ~ page.slug ~ ".json", required= false), - load_data(path= config.extra.command_bloom_json_path ~ page.slug ~ ".json", required= false), - load_data(path= config.extra.command_json_json_path ~ page.slug ~ ".json", required= false), - load_data(path= config.extra.command_search_json_path ~ page.slug ~ ".json", required= false), - load_data(path= config.extra.command_large_object_json_path ~ page.slug ~ ".json", required= false) + load_data(path= config.extra.command_json_path ~ page.slug ~ ".json", required= false) ] %} {% set command_data = [s for s in command_sources if s] | first %} @@ -165,7 +161,7 @@

{{ command_title }} {% if deprecated %} {{ de {% if command_description %} -{%- set command_description_with_fixed_links %}{{< fix_links_command content={command_description} />}}{% endset -%} +{%- set command_description_with_fixed_links %}{{< fix_links_command content={command_description} repo_url={"https://github.com/" ~ page.extra.source_repository ~ "/blob/" ~ page.extra.source_branch ~ "/"} />}}{% endset -%} {%- set command_description_html %}{{ command_description_with_fixed_links | markdown | safe }}{% endset -%} {{< heading_links content={command_description_html} />}} @@ -226,10 +222,10 @@

RESP3 Reply

{% endif %} -{# Every command page, module commands included, is built from a description in valkey-doc (see build/init-commands.sh). #} +{# The stub's front matter says where the description comes from (see build/init-docs.sh). #} {% endblock main_content %} diff --git a/templates/commands.html b/templates/commands.html index 884fc391..6e5bb897 100644 --- a/templates/commands.html +++ b/templates/commands.html @@ -38,11 +38,7 @@

We couldn't find any results matching your search

{% for page in section.pages %} {% for json_path in [ - config.extra.command_json_path ~ page.slug ~ ".json", - config.extra.command_bloom_json_path ~ page.slug ~ ".json", - config.extra.command_json_json_path ~ page.slug ~ ".json", - config.extra.command_search_json_path ~ page.slug ~ ".json", - config.extra.command_large_object_json_path ~ page.slug ~ ".json" + config.extra.command_json_path ~ page.slug ~ ".json" ] %} {% set command_data = load_data(path= json_path, required= false) %} {% if command_data %} diff --git a/templates/docs-page.html b/templates/docs-page.html index 8cb1cc83..a58707e3 100644 --- a/templates/docs-page.html +++ b/templates/docs-page.html @@ -58,12 +58,12 @@

{{ frontmatter_title }}

In the future it may change substantially or be removed entirely.


{% endif %} -{%- set content_with_fixed_links %}{{< fix_links_docs content={page_contents} />}}{% endset -%} +{%- set content_with_fixed_links %}{{< fix_links_docs content={page_contents} repo_url={"https://github.com/" ~ page.extra.source_repository ~ "/blob/" ~ page.extra.source_branch ~ "/"} />}}{% endset -%} {%- set content_html %}{{ content_with_fixed_links | markdown | safe }}{% endset -%} {{< heading_links content={content_html} />}} {{< nav_pager nav={nav_data} slug={page.slug} extra={config.extra} />}} {% endblock main_content %} diff --git a/templates/macros/command.html b/templates/macros/command.html index 86947090..8d408a22 100644 --- a/templates/macros/command.html +++ b/templates/macros/command.html @@ -44,10 +44,12 @@ {%- endfor -%} {% endcomponent arguments_parse %} -{% component fix_links_command(content) %} +{# repo_url: links from docs/commands/ or docs/topics/ to elsewhere in the + page's repo (../../COMPATIBILITY.md) go to that file on GitHub. #} +{% component fix_links_command(content, repo_url="") %}{% if repo_url %}{% set content = content | regex_replace(pattern="\\]\\(\\.\\./\\.\\./(?P[^)]*)\\)", rep="](" ~ repo_url ~ "$path)") %}{% endif %} {{ content - | regex_replace(pattern="\\]\\(\\.\\./topics/(?P.*?).md#(?P.*?)\\)", rep="](/topics/$fname#$hash)") - | regex_replace(pattern="\\]\\(\\.\\./topics/(?P.*?).md\\)", rep="](/topics/$fname)") + | regex_replace(pattern="\\]\\(\\.\\./topics/(?P[^)]*?).md#(?P.*?)\\)", rep="](/topics/$fname#$hash)") + | regex_replace(pattern="\\]\\(\\.\\./topics/(?P[^)]*?).md\\)", rep="](/topics/$fname)") | regex_replace(pattern="\\[(?P.*?)\\]:\\s+\\.\\./topics/(?P.*?).md", rep="[$token]: /topics/$fname") | regex_replace(pattern="\\]\\((?P[\\w\\.-]*?)\\.md#(?P.*?)\\)", rep="](/commands/$fname#$hash)") | regex_replace(pattern="\\]\\((?P[\\w\\.-]*?)\\.md\\)", rep="](/commands/$fname)") diff --git a/templates/macros/docs.html b/templates/macros/docs.html index 5d1101e9..560a14b0 100644 --- a/templates/macros/docs.html +++ b/templates/macros/docs.html @@ -26,7 +26,9 @@ {{ parts[2:] | join(sep="---") | safe }} {% endcomponent extract_markdown %} -{% component fix_links_docs(content) %} +{# repo_url: links from docs/commands/ or docs/topics/ to elsewhere in the + page's repo (../../COMPATIBILITY.md) go to that file on GitHub. #} +{% component fix_links_docs(content, repo_url="") %}{% if repo_url %}{% set content = content | regex_replace(pattern="\\]\\(\\.\\./\\.\\./(?P[^)]*)\\)", rep="](" ~ repo_url ~ "$path)") %}{% endif %} {{ content | regex_replace(pattern="\\]\\(#(?P.*?\\))", rep="](--$hash") | regex_replace(pattern="\\]\\((?Phttpsd?:\\/\\/.*?\\))", rep="](-$url") diff --git a/templates/macros/nav.html b/templates/macros/nav.html index 69aa38b5..800ac868 100644 --- a/templates/macros/nav.html +++ b/templates/macros/nav.html @@ -5,7 +5,7 @@ The core menu defines the sections. A source's menu file can add topics to a core section ("section: ") or add a new section ("id: ..."), optionally placed after a core section ("after: "). The files are - merged in the order given by config.extra.nav_sources. + merged in the order of the doc sources (build/doc-sources.toml). The menu is lenient: it leaves out what doesn't fit instead of failing the build. Topics that don't exist, entries for unknown sections, and @@ -36,7 +36,8 @@ {#- Menu files of other sources that exist. Entries that refer to unknown sections are never matched below, so they're left out. -#} {%- set sources = [] -%} - {%- for name in extra.nav_sources -%} + {%- set doc_sources = load_data(path=extra.doc_sources_path, format="toml") -%} + {%- for name in [s.name for s in doc_sources.source if s.role != "core"] -%} {%- set entries = load_data(path=extra.nav_sources_path ~ name ~ ".yml", format="yaml", required=false) -%} {%- if entries -%} {%- set_global sources = [...sources, {"name": name, "entries": entries}] -%} @@ -132,7 +133,7 @@ All commands that have a page, as a JSON list of {"name": "CONFIG GET", "container": "CONFIG", "group": "server", "slug": "config-get"}. The data comes from the command pages' front matter, written by - build/init-commands.sh from the command JSON files. For pages without it + build/init-docs.sh from the command JSON files. For pages without it (no jq, or stubs from an older init run), the command JSON file is read instead: same result, slower build. -#} @@ -143,7 +144,7 @@ {%- if page.extra?.command_name -%} {%- set_global index = [...index, {"name": page.extra.command_name, "container": page.extra.command_container, "group": page.extra.command_group, "slug": page.slug}] -%} {%- else -%} - {%- for json_path in [extra.command_json_path, extra.command_bloom_json_path, extra.command_json_json_path, extra.command_search_json_path, extra.command_large_object_json_path] -%} + {%- for json_path in [extra.command_json_path] -%} {%- set data = load_data(path=json_path ~ page.slug ~ ".json", required=false) -%} {%- if data -%} {%- set key = data | keys | first -%} @@ -262,6 +263,15 @@ {%- endif %} {% endcomponent nav_pager %} +{#- The label shown next to a doc source's menu entries: "module" for the + repos with the role "module" in build/doc-sources.toml, otherwise none. -#} +{% component nav_badge(source, extra) %} +{%- set doc_sources = load_data(path=extra.doc_sources_path, format="toml") -%} +{%- for s in doc_sources.source -%} + {%- if s.name == source and s.role == "module" -%}module{%- endif -%} +{%- endfor -%} +{% endcomponent nav_badge %} + {#- A topic's title: `title` if set, otherwise the title in the topic's front matter. -#} {% component nav_topic_title(slug, extra, title="") %} {%- if title -%}{{ title }}{%- else -%} @@ -284,7 +294,7 @@ row is the toggle for its commands instead. -#} {% component nav_menu_item(slug, title, source, current, related, extra, commands=[], current_command="", label="") %} -{%- set badge = extra.nav_badges[source] | default(value="") -%} +{%- set badge %}{{< nav_badge source={source} extra={extra} />}}{% endset -%} {%- if commands and slug == current %}
  • @@ -388,7 +398,7 @@

    Documentation

    {%- else %}
  • - {%- set section_badge = extra.nav_badges[section.source] | default(value="") %} + {%- set section_badge %}{{< nav_badge source={section.source} extra={extra} />}}{% endset %} {{ section.title }}{% if section_badge %} {{ section_badge }}{% endif %}
      {%- if section.landing %}