From e99703014c3b637b1a0baced4d1e15ea1475a913 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Thu, 9 Feb 2023 23:51:30 -0600 Subject: [PATCH] :art: (docs): Strip homepage line during mdBook build --- docs/book.toml | 3 +++ docs/hack/prepare-docs.sh | 3 +-- docs/hack/preprocessor/replace-content.sh | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 docs/hack/preprocessor/replace-content.sh diff --git a/docs/book.toml b/docs/book.toml index acbe26750..097e41447 100644 --- a/docs/book.toml +++ b/docs/book.toml @@ -22,3 +22,6 @@ level = 1 [output.html.search] limit-results = 15 + +[preprocessor.strip-homepage] +command = '''./hack/preprocessor/replace-content.sh "\*\*Homepage:\*\*.+\n" ""''' diff --git a/docs/hack/prepare-docs.sh b/docs/hack/prepare-docs.sh index b31d37fe0..56ee89951 100755 --- a/docs/hack/prepare-docs.sh +++ b/docs/hack/prepare-docs.sh @@ -14,8 +14,7 @@ CHARTS=() while IFS= read -r -d '' f; do mkdir -p "docs/src/$(dirname "$f")" - sed '/^\*\*Homepage:\*\*/,+1d' "$f" \ - | sed "s|(\./\(.*\.yaml\))|($repo_path/blob/main/$(dirname "$f")/\1)|g" \ + sed "s|(\./\(.*\.yaml\))|($repo_path/blob/main/$(dirname "$f")/\1)|g" "$f" \ > "docs/src/$f" CHARTS+=("$(basename "$(dirname "$f")")") diff --git a/docs/hack/preprocessor/replace-content.sh b/docs/hack/preprocessor/replace-content.sh new file mode 100755 index 000000000..eb414e78c --- /dev/null +++ b/docs/hack/preprocessor/replace-content.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail +export IFS=$'\n\t' + +# require yq +command -v yq >/dev/null 2>&1 || { + echo >&2 'yq (https://github.com/mikefarah/yq) is not installed. Aborting.' + exit 1 +} + +if [[ "${3:-}" == supports ]]; then + exit +fi + +export FIND="$1" REPLACE="$2" +yq -o json '.[1] | (.. | select(key == "content")) |= sub(strenv(FIND), strenv(REPLACE))' -