Skip to content

Commit 2896a02

Browse files
Fix search with mkdocs typescript patches (vendored). (#6392)
Hopefully, this can be fixed upstream via PR shortly.
1 parent c799f99 commit 2896a02

5 files changed

Lines changed: 56 additions & 12 deletions

File tree

hack/build.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,15 @@ mkdir "$TEMP/content/docs/docs"
4747
for path in .nav.yml bookstore client concepts eventing functions getting-started install reference samples serving; do
4848
mv "$TEMP/content/docs/$path" "$TEMP/content/docs/docs/$path"
4949
done
50+
echo "" >> "$TEMP/content/docs/docs/README.md" # Placeholder to ensure sitemap entry (for versioning)
5051
echo " docs/README.md: docs/concepts/README.md" >> "$TEMP/content/config/redirects.yml"
5152
# Copy images for now, until we clean up the above:
5253
cp -r "$TEMP/content/docs/images" "$TEMP/content/docs/docs/images"
5354

5455
# Point top-level nav to docs directory.
5556
echo -e "nav:\n- docs\n- about\n- blog\n- community" > "$TEMP/content/docs/.nav.yml"
5657
# We use samples_branch to flag that the documentation is versioned
57-
echo -e "\n\nsamples_branch: main" >> "$TEMP/content/docs/docs/.meta.yml"
58+
echo -e "\n\nsamples_branch: main\nversion: development" >> "$TEMP/content/docs/docs/.meta.yml"
5859
curl -f -L --show-error https://raw.githubusercontent.com/knative/serving/main/docs/serving-api.md -s > "$TEMP/content/docs/docs/serving/reference/serving-api.md"
5960
curl -f -L --show-error https://raw.githubusercontent.com/knative/eventing/main/docs/eventing-api.md -s > "$TEMP/content/docs/docs/eventing/reference/eventing-api.md"
6061
versionjson="{\"version\": \"docs\", \"title\": \"(Pre-release)\", \"aliases\": [\"\"]}"
@@ -64,9 +65,15 @@ BUILD_VERSIONS="yes"
6465

6566
if [ "$BUILD_VERSIONS" != "no" ]; then
6667
mv $TEMP/content/docs/docs $TEMP/content/docs/development
68+
# Remove pre-release documents from search. This has to be applied to each markdown, unfortunately.
69+
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
70+
# and the seconds inserts commands into the front-matter.
71+
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
72+
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
73+
6774
echo "- Docs: development" >> "$TEMP/content/docs/.nav.yml"
6875
echo " development/README.md: development/concepts/README.md" >> "$TEMP/content/config/redirects.yml"
69-
versionjson="{\"version\": \"docs\", \"title\": \"v$latest\", \"aliases\": [\"\"]}," # Clear existing content, we'll add development at the _end_.
76+
versionjson="{\"version\": \"docs\", \"title\": \"v$latest\", \"aliases\": [\"v$latest\"]}," # Clear existing content, we'll add development at the _end_.
7077

7178
# Handle current release specially, as we don't include a version slug
7279
# TODO: can we make one clone and reuse it, possibly with git worktrees?
@@ -82,12 +89,12 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
8289
# Smoketests were written for Hugo, not mkdocs, so remove
8390
rm "$TEMP/content/docs/docs/smoketest.md"
8491
# Fill in meta content for macros.py
85-
echo -e "\n\nknative_version: ${VERSIONS[0]}.0\nsamples_branch: ${DOCS_BRANCHES[0]}" >> "$TEMP/content/docs/docs/.meta.yml"
92+
echo -e "\n\nknative_version: ${latest}.0\nsamples_branch: ${DOCS_BRANCHES[0]}\nversion: v${latest}" >> "$TEMP/content/docs/docs/.meta.yml"
8693

8794

8895
for i in "${!previous[@]}"; do
8996
version=${previous[$i]}
90-
versionjson+="{\"version\": \"v$version-docs\", \"title\": \"v$version\", \"aliases\": [\"\"]},"
97+
versionjson+="{\"version\": \"v$version-docs\", \"title\": \"v$version\", \"aliases\": [\"v$version\"]},"
9198

9299
echo "Building for previous version $version"
93100
git clone --depth 1 -b ${DOCS_BRANCHES[$i+1]} https://github.com/${GIT_SLUG} "$TEMP/docs-$version"
@@ -104,7 +111,12 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
104111
sed '/- Blog:/,$d' "$TEMP/docs-$version/config/nav.yml" >> "$TEMP/content/docs/v$version-docs/.nav.yml"
105112
fi
106113
# Fill in meta content for macros.py
107-
echo -e "\n\nknative_version: ${VERSIONS[i+1]}.0\nsamples_branch: ${DOCS_BRANCHES[i+1]}\nversion_warning: true" >> "$TEMP/content/docs/v$version-docs/.meta.yml"
114+
echo -e "\n\nknative_version: ${version}.0\nsamples_branch: ${DOCS_BRANCHES[i+1]}\nversion_warning: true\nversion: v${version}" >> "$TEMP/content/docs/v$version-docs/.meta.yml"
115+
# Remove older-version documents from search. This has to be applied to each markdown, unfortunately.
116+
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
117+
# and the seconds inserts commands into the front-matter.
118+
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
119+
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
108120
done
109121

110122
# Put the development version at the end of the JSON list of documentation,

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,4 +108,4 @@ extra:
108108
provider: google
109109
property: G-YRMNFYE32R
110110
version:
111-
provider: mike
111+
provider: directory

netlify.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
NODE_VERSION= "22"
99
PYTHON_VERSION = "3.13"
1010

11+
[[plugins]]
12+
package = "@netlify/plugin-sitemap"
13+
14+
[plugins.inputs]
15+
prettyURLs = true
16+
# The trailing slash is needed for MkDocs navigation
17+
trailingSlash = true
18+
1119
# Deploy Preview context: all deploys generated from a pull/merge request will
1220
# inherit these settings.
1321
[context.deploy-preview]
@@ -31,3 +39,4 @@
3139
from = "/docs/help/contributor/*"
3240
to = "https://github.com/knative/docs/blob/main/contribute-to-docs/README.md"
3341
status = 301
42+

0 commit comments

Comments
 (0)