Search index only for /latest (#423)

This commit is contained in:
Pete Lumbis 2023-05-01 10:12:39 -04:00 committed by GitHub
parent 5844fef0e5
commit bff3de632c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 101 additions and 30 deletions

View File

@ -5,7 +5,7 @@ about: Cut a Crossplane release
labels: release
---
- [ ] Update the `/latest` redirect in [netlify.toml](https://github.com/crossplane/docs/blob/master/netlify.toml#L9)
- [ ] Update the `$LATEST_VER` parameter in [netlify_build.sh](https://github.com/crossplane/docs/blob/master/netlify_build.sh#L3)
- [ ] Update `params.latest` in [config.yaml](https://github.com/crossplane/docs/blob/master/config.yaml#L48)
- [ ] Update `version` in the `_index.md` file of `/content/<new latest>`
- [ ] Create a [new release/tag](https://github.com/crossplane/docs/releases/new) named "v<EOL version>-archive" to snapshot EOL'd docs.

View File

@ -4,21 +4,16 @@
command = "hugo --minify "
[[redirects]]
from = "/latest/*"
to = "/v1.12/:splat"
status = 302
[[redirects]]
from = "/docs/*"
to = "/:splat"
status = 302
[context.deploy-preview]
command = "sed -i 's/# writeStats: true/writeStats: true/g' config.yaml && cat config.yaml && hugo --minify"
command = "bash netlify_build.sh"
[context.production]
command = "sed -i 's/# writeStats: true/writeStats: true/g' config.yaml && hugo --minify"
command = "bash netlify_build.sh"
# Use [dev] to set configuration overrides for local
# development environments run using Netlify Dev - except

17
netlify_build.sh Normal file
View File

@ -0,0 +1,17 @@
#!/usr/bin/env bash
LATEST_VER="1.12"
cp -R content/v$LATEST_VER content/latest
sed -i "s/^\s*version: \"$LATEST_VER\"//g" content/latest/_index.md
sed -i 's/# writeStats: true/writeStats: true/g' config.yaml
cat config.yaml
if [ $CONTEXT = "production"]
then
hugo --minify --baseURL $URL
else
hugo --minify --baseURL $DEPLOY_URL
fi

View File

@ -0,0 +1,17 @@
{{ printf "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>" | safeHTML }}
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
{{ range where .Site.Pages "Section" "latest" }}
<url>
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}
</url>
{{ end }}
{{/* For KB and Contrib guides */}}
{{ range where .Site.Pages "Params.version" "0" }}
<url>
<loc>{{ .Permalink }}</loc>{{ if not .Lastmod.IsZero }}
<lastmod>{{ safeHTML ( .Lastmod.Format "2006-01-02T15:04:05-07:00" ) }}</lastmod>{{ end }}
</url>
{{ end }}
</urlset>

View File

@ -15,9 +15,41 @@
{{ end }}
{{ end }}
{{ $ver := .Page.Params.version | default .Site.Params.latest }}
<title>
{{- if .IsHome -}}{{- .Site.Title | markdownify }} · {{.Site.Params.subtitle | markdownify }} {{- else }}{{- .Title | markdownify}} · {{ .Site.Title | markdownify }} {{ if and (ne .Page.Params.version "0") (ne .Page.Params.version "master")}}v{{.Page.Params.version }}{{end}}{{if eq .Page.Params.version "master"}}{{.Page.Params.version }}{{end}}{{ end }}</title>
<link rel="canonical" href="https://docs.crossplane.io{{ .Permalink }}">
{{- if .IsHome -}}{{- .Site.Title | markdownify }} · {{.Site.Params.subtitle | markdownify }} {{- else }}{{- .Title | markdownify}} · {{ .Site.Title | markdownify }} {{ if and (ne .Page.Params.version "0") (ne .Page.Params.version "master")}}v{{ $ver }}{{end}}{{if eq .Page.Params.version "master"}}{{.Page.Params.version }}{{end}}{{ end }}</title>
{{/* Don't do the URL processing for KB and Contrib guides */}}
{{ if not .Page.Params.Product }}
{{/* Strip out the version from the path to get just the section + page */}}
{{ $sectionPage := replaceRE (printf "v%s/" .Page.Params.version) "" .RelPermalink }}
{{/* Handle the /latest directory */}}
{{ if not .Page.Params.version }}
{{ $sectionPage = replaceRE "/latest" "" .RelPermalink }}
{{ end }}
{{/* Handle the /master directory */}}
{{ if eq .Page.Params.version "master" }}
{{ $sectionPage = replaceRE "/master" "" .RelPermalink }}
{{ end }}
{{/* Strip training / so .GetPage works */}}
{{ $sectionPage = strings.TrimRight "/" $sectionPage }}
{{/* Look for the Page matching this page, but in the latest directory */}}
{{ $latestPage := .Site.GetPage (printf "/latest%s" $sectionPage) }}
{{/* If it exists set the canonical URL to the latest, otherwise we are canonical */}}
{{ if $latestPage }}
<link rel="canonical" href="{{$latestPage.Permalink }}">
{{ end }}
{{ else }}
<link rel="canonical" href="{{.Permalink}}">
{{ end }}
{{ partialCached "stylesheet-cached" . }}
{{ partial "stylesheet-dynamic" . }}

View File

@ -63,9 +63,11 @@
<div class="bd-content ps-lg-2 DocSearch-content">
{{ if $.Param "docs" }}
{{ $pageVer := .Page.Params.version | default .Site.Params.latest }}
{{- if eq .Page.Params.version "master" -}}
{{ partialCached "master-version-alert" . }}
{{- else if ne .Page.Params.version .Site.Params.latest -}}
{{- else if ne $pageVer .Site.Params.latest -}}
{{ partialCached "old-version-alert" . .Section }}
{{ end }}
{{ end }}

View File

@ -2,7 +2,7 @@
{{ $majordict := dict }}
{{ $majorlist := slice }}
{{ $sorted_list := slice }}
{{ $cur_ver := .Page.Params.version }}
{{ $cur_ver := .Page.Params.version | default .Site.Params.latest }}
<!-- get all the versions and break out semver order -->
{{ range .Site.Sections }}
@ -28,34 +28,42 @@
<div class="dropdown float-end bd-dropdown">
<a class="btn btn-outline-secondary dropdown-toggle bd-dropdown-item text-reset" href="#" role="button" id="dropdownMenuLink" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ if ne .Page.Params.version "master" }}v{{ end }}{{ .Page.Params.version }}
{{ if eq .Page.Params.version .Site.Params.latest }}
{{ if ne .Page.Params.version "master" }}v{{ end }}{{ $cur_ver }}
{{ if eq $cur_ver .Site.Params.latest }}
<div class="badge rounded-pill latest">Latest</div>
{{ end }}
</a>
<div class="dropdown-menu bd-border-color bd-dropdown" aria-labelledby="dropdownMenuLink">
{{ $master_url := replaceRE "v[0-9].[0-9]" "master" .Permalink }}
{{/* Iterate over the ordered list of available versions. */}}
{{/* Iterate over the ordered list of available versions. */}}
{{ range $sorted_list }}
{{/* For a version, see if there is a page with an identical title to the page we're on. If not use the page at /content/v<version> */}}
{{ $versionPage := index (where (where $.Site.Pages "Title" $.Title) ".Page.Params.version" .) 0 | default ($.Site.GetPage (printf "v%s" .)) }}
{{/* If the version is master get the master page since "vmaster" doesn't exist */}}
{{ if not $versionPage }}
{{ $versionPage = $.Site.GetPage "master" }}
{{ end }}
{{ with $versionPage }}
<a class="dropdown-item bd-dropdown-item {{- if eq .Page.Params.version $cur_ver }} active {{- end}}" {{- if eq .Page.Params.version $cur_ver }}aria-current="true"{{end}} href="{{ .Permalink }}">
{{ if eq .Page.Params.version "master" }}
master
{{/* For a version, see if there is a page with an identical title to the page we're on. If not use the page at /content/v<version> */}}
{{ $versionPage := index (where (where $.Site.Pages "Title" $.Title) ".Page.Params.version" .) 0 | default ($.Site.GetPage (printf "v%s" .)) }}
{{/* If the version is master get the master page since "vmaster" doesn't exist */}}
{{ if not $versionPage }}
{{ $versionPage = $.Site.GetPage "master" }}
{{ end }}
{{ with $versionPage }}
{{ $isLatest := false }}
{{ if or (eq .Page.Params.version "") (eq .Page.Params.version $cur_ver) }}
{{ $isLatest = true }}
{{ end }}
<a class="dropdown-item bd-dropdown-item {{- if $isLatest }} active {{- end}}" {{- if $isLatest }}aria-current="true"{{end}} href="{{ .Permalink }}">
{{ if eq .Page.Params.version "master" }}
master
{{ else }}
{{ if eq .Page.Params.version "" }}
{{ (printf "v%s" .Site.Params.latest) }}
{{ else }}
{{ (printf "v%s" .Page.Params.version) }}
{{ end }}
{{ if eq .Page.Params.version .Site.Params.latest }}
<div class="badge rounded-pill latest">Latest</div>
{{ end }}
</a>
{{ end }}
{{ end }}
{{ if or (eq .Page.Params.version .Site.Params.latest) (eq .Page.Params.version "") }}
<div class="badge rounded-pill latest">Latest</div>
{{ end }}
</a>
{{ end }}
{{ end }}
</div>
</div>