Skip to content

Commit 85ef244

Browse files
committed
wip(web): load swagger and mermaid only where used, single jQuery
1 parent d056d77 commit 85ef244

4 files changed

Lines changed: 45 additions & 2 deletions

File tree

‎web/SITES_MERGE_PLAYBOOK.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,23 @@ Also removed here: leftover unconditional `needs: []` on the web jobs (from
481481
an earlier iteration — independence from the product pipeline is opt-in via
482482
`BUILD_GL_PAGES`, step 16's CI note).
483483

484+
### 24. Docs asset diet: conditional swagger/mermaid, one jQuery
485+
486+
sg-doc loaded swagger-ui (two JS bundles + CSS, twice) and mermaid on every
487+
docs page; exactly one page uses swagger (`sg-swaggerui` shortcode on the API
488+
reference) and none currently use mermaid. The doc header/footer partials now
489+
gate those assets with `.HasShortcode`. The docs' jQuery 3.3.1 was replaced by
490+
the main site's 3.4.1 (one jQuery site-wide; the theme's 3.3.1 file is
491+
unreferenced). Also fixed the `sg-swaggerui` shortcode (project override): it
492+
built the spec URL as `BaseURL + "/sg-swagger.yaml"`, which yields the
493+
protocol-relative `//sg-swagger.yaml` when baseURL is `/` (artifact preview) —
494+
now `relURL`, correct for every baseURL shape.
495+
496+
Found while verifying, NOT fixed here: the vendored swagger-ui is a 3.x-era
497+
build and rejects the operator's OpenAPI **3.1** spec ("Unable to render this
498+
definition") — **the live stackgres.io API reference page is broken the same
499+
way**. Fix = vendor swagger-ui v5 (supports 3.1). Recorded under known gaps.
500+
484501
## Verified
485502

486503
- `hugo` builds with **0 errors** (379 pages)
@@ -522,5 +539,11 @@ an earlier iteration — independence from the product pipeline is opt-in via
522539
that only resolve via the live site's redirect-to-docs-home fallback.
523540
Converting them to `relurl`/markdown links is a mechanical follow-up pass.
524541
- **RSS/sitemap dedup** between the three sections was not reviewed.
542+
- **Operator API reference doesn't render** (pre-existing, also broken on
543+
live stackgres.io): the operator's swagger is OpenAPI 3.1, the vendored
544+
swagger-ui bundle only supports ≤3.0. Upgrade to swagger-ui v5 (drop-in:
545+
`swagger-ui-bundle.js`, `swagger-ui-standalone-preset.js`,
546+
`swagger-ui.css` as project static overrides; the shortcode API is
547+
unchanged in v5).
525548
- **CI/deploy.** Each source repo had its own pipeline; the umbrella needs one
526549
(build + link-check + deploy).

‎web/layouts/partials/doc/footer.html‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@
6767
<script src="{{"js/learn.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
6868
<script src="{{"js/hugo-learn.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
6969

70+
{{ if .HasShortcode "mermaid" }}
7071
<link href="{{"mermaid/mermaid.css" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" />
7172
<script src="{{"mermaid/mermaid.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
7273
<script>
7374
mermaid.initialize({ startOnLoad: true });
7475
</script>
76+
{{ end }}
77+
{{ if .HasShortcode "sg-swaggerui" }}
7578
<link href="{{"css/swagger-ui.css" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet" />
7679
<script src="{{"js/swagger-ui-bundle.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
7780
<script src="{{"js/swagger-ui-standalone-preset.js" | relURL}}{{ if not .Site.Params.disableAssetsBusting }}?{{ now.Unix }}{{ end }}"></script>
81+
{{ end }}
7882

7983
{{ partial "custom-footer.html" . }}
8084
</body>

‎web/layouts/partials/doc/header.html‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
{{with .Site.Params.themeVariant}}
2424
<link href="{{(printf "css/theme-%s.css" .) | relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}" rel="stylesheet">
2525
{{end}}
26-
<link href="{{ "css/swagger-ui.css" | relURL }}" rel="stylesheet" type="text/css">
26+
{{ if .HasShortcode "sg-swaggerui" }}<link href="{{ "css/swagger-ui.css" | relURL }}" rel="stylesheet" type="text/css">{{ end }}
2727

28-
<script src="{{"js/jquery-3.3.1.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
28+
<script src="{{"js/jquery-3.4.1.min.js"| relURL}}{{ if $assetBusting }}?{{ now.Unix }}{{ end }}"></script>
2929

3030
<style>
3131
:root #header + #content > #left > #rlblock_left{
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<div id="ohpen_swagger_ui"></div>
2+
<script>
3+
window.onload = function() {
4+
const ui = SwaggerUIBundle({
5+
url: "{{ "sg-swagger.yaml" | relURL }}",
6+
dom_id: '#ohpen_swagger_ui',
7+
presets: [
8+
SwaggerUIBundle.presets.apis,
9+
SwaggerUIStandalonePreset
10+
],
11+
docExpansion: "list"
12+
})
13+
14+
window.ui = ui
15+
}
16+
</script>

0 commit comments

Comments
 (0)