Fix search with mkdocs typescript patches (vendored). (#6392)

Hopefully, this can be fixed upstream via PR shortly.
This commit is contained in:
Evan Anderson 2025-09-19 05:08:02 -07:00
parent 19ef9f716a
commit 3bc14fb91c
5 changed files with 56 additions and 12 deletions

View File

@ -47,6 +47,7 @@ mkdir "$TEMP/content/docs/docs"
for path in .nav.yml bookstore client concepts eventing functions getting-started install reference samples serving; do
mv "$TEMP/content/docs/$path" "$TEMP/content/docs/docs/$path"
done
echo "" >> "$TEMP/content/docs/docs/README.md" # Placeholder to ensure sitemap entry (for versioning)
echo " docs/README.md: docs/concepts/README.md" >> "$TEMP/content/config/redirects.yml"
# Copy images for now, until we clean up the above:
cp -r "$TEMP/content/docs/images" "$TEMP/content/docs/docs/images"
@ -54,7 +55,7 @@ cp -r "$TEMP/content/docs/images" "$TEMP/content/docs/docs/images"
# Point top-level nav to docs directory.
echo -e "nav:\n- docs\n- about\n- blog\n- community" > "$TEMP/content/docs/.nav.yml"
# We use samples_branch to flag that the documentation is versioned
echo -e "\n\nsamples_branch: main" >> "$TEMP/content/docs/docs/.meta.yml"
echo -e "\n\nsamples_branch: main\nversion: development" >> "$TEMP/content/docs/docs/.meta.yml"
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"
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"
versionjson="{\"version\": \"docs\", \"title\": \"(Pre-release)\", \"aliases\": [\"\"]}"
@ -64,9 +65,15 @@ BUILD_VERSIONS="yes"
if [ "$BUILD_VERSIONS" != "no" ]; then
mv $TEMP/content/docs/docs $TEMP/content/docs/development
# Remove pre-release documents from search. This has to be applied to each markdown, unfortunately.
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
# and the seconds inserts commands into the front-matter.
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
find "$TEMP/content/docs/development" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
echo "- Docs: development" >> "$TEMP/content/docs/.nav.yml"
echo " development/README.md: development/concepts/README.md" >> "$TEMP/content/config/redirects.yml"
versionjson="{\"version\": \"docs\", \"title\": \"v$latest\", \"aliases\": [\"\"]}," # Clear existing content, we'll add development at the _end_.
versionjson="{\"version\": \"docs\", \"title\": \"v$latest\", \"aliases\": [\"v$latest\"]}," # Clear existing content, we'll add development at the _end_.
# Handle current release specially, as we don't include a version slug
# TODO: can we make one clone and reuse it, possibly with git worktrees?
@ -82,12 +89,12 @@ if [ "$BUILD_VERSIONS" != "no" ]; then
# Smoketests were written for Hugo, not mkdocs, so remove
rm "$TEMP/content/docs/docs/smoketest.md"
# Fill in meta content for macros.py
echo -e "\n\nknative_version: ${VERSIONS[0]}.0\nsamples_branch: ${DOCS_BRANCHES[0]}" >> "$TEMP/content/docs/docs/.meta.yml"
echo -e "\n\nknative_version: ${latest}.0\nsamples_branch: ${DOCS_BRANCHES[0]}\nversion: v${latest}" >> "$TEMP/content/docs/docs/.meta.yml"
for i in "${!previous[@]}"; do
version=${previous[$i]}
versionjson+="{\"version\": \"v$version-docs\", \"title\": \"v$version\", \"aliases\": [\"\"]},"
versionjson+="{\"version\": \"v$version-docs\", \"title\": \"v$version\", \"aliases\": [\"v$version\"]},"
echo "Building for previous version $version"
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
sed '/- Blog:/,$d' "$TEMP/docs-$version/config/nav.yml" >> "$TEMP/content/docs/v$version-docs/.nav.yml"
fi
# Fill in meta content for macros.py
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"
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"
# Remove older-version documents from search. This has to be applied to each markdown, unfortunately.
# This needs to be done as two commands: the first ensures front-matter in files that don't have it,
# and the seconds inserts commands into the front-matter.
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '1s/^\([^-]\)/---\n---\n\1/'
find "$TEMP/content/docs/v$version-docs" -type f -name '*.md' | xargs sed -i '2isearch:\n exclude: true'
done
# Put the development version at the end of the JSON list of documentation,

View File

@ -108,4 +108,4 @@ extra:
provider: google
property: G-YRMNFYE32R
version:
provider: mike
provider: directory

View File

@ -8,6 +8,14 @@
NODE_VERSION= "22"
PYTHON_VERSION = "3.13"
[[plugins]]
package = "@netlify/plugin-sitemap"
[plugins.inputs]
prettyURLs = true
# The trailing slash is needed for MkDocs navigation
trailingSlash = true
# Deploy Preview context: all deploys generated from a pull/merge request will
# inherit these settings.
[context.deploy-preview]
@ -31,3 +39,4 @@
from = "/docs/help/contributor/*"
to = "https://github.com/knative/docs/blob/main/contribute-to-docs/README.md"
status = 301

File diff suppressed because one or more lines are too long

View File

@ -15,8 +15,9 @@
{% endif %}
{% endblock %}
{# TEMPORARY HACK: replace {{ super() }} with the asset link, to use custom JSON build. #}
{% block scripts %}
{{ super() }}
<script src="{{ 'assets/javascripts/bundle.0af37618.min.js' | url }}"></script>
<!-- For now, load Jquery and Bootstrap because the cookie warning (built from the hugo-based website) uses them -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
@ -32,17 +33,23 @@
<!-- Versioning -->
{# This is changed from upstream to only show version picker on versioned pages #}
{%- if page and (page.meta.samples_branch) -%}
{%- if config.extra.version -%}
{%- if config.extra.version.provider == "mike" -%}
{%- set mike = config.plugins.mike -%}
{%- if not mike or mike.config.version_selector -%}
{%- set _.version = config.extra.version -%}
{%- if not mike or mike.config.version_selector -%}
{%- set _.version = config.extra.version -%}
{%- endif -%}
{%- elif config.extra.version.provider == "directory" -%}
{%- if page and (page.meta.version) -%}
{%- set _.version = {"provider":"directory", "declared_version": page.meta.version | string} -%}
{%- endif -%}
{%- endif -%}
{%- endif -%}
<!-- Configuration -->
<script id="__config" type="application/json">
{{- {
"base": base_url | replace("../", "", 1),
"base": base_url,
"features": features,
"translations": {
"clipboard.copy": lang.t("clipboard.copy"),
@ -56,7 +63,7 @@
"search.result.term.missing": lang.t("search.result.term.missing"),
"select.version": lang.t("select.version")
},
"search": "assets/javascripts/workers/search.js" | url,
"search": "assets/javascripts/workers/search.973d3a69.min.js" | url,
"tags": _.tags or none,
"version": _.version or none
} | tojson -}}