Skip to content

Commit dbaafd4

Browse files
authored
Fix components.json and api ref urls for beta/next (#5348)
1 parent 4b10305 commit dbaafd4

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

hugo.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ outputs:
150150
home:
151151
- HTML
152152
- RSS
153+
- ComponentsJSON
153154

154155
# Static file configuration
155-
staticDir:
156+
staticDir:
156157
- static
157158

158159
mediaTypes:
@@ -165,6 +166,12 @@ outputFormats:
165166
mediaType: image/svg+xml
166167
isPlainText: true
167168
isHTML: false
169+
ComponentsJSON:
170+
mediaType: application/json
171+
baseName: components
172+
isPlainText: true
173+
isHTML: false
174+
path: ""
168175

169176
module:
170177
mounts:

netlify.toml

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
[build]
22
publish = "public"
33
command = "make netlify"
4-
environment = { BASE_URL = "https://esphome.io", API_DOCS_URL = "https://api-docs.esphome.io", PYTHON_VERSION = "3.12", HUGO_VERSION = "0.147.8" }
4+
environment = { HUGO_BASEURL = "https://esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs.esphome.io", PYTHON_VERSION = "3.12", HUGO_VERSION = "0.147.8" }
55

66
[context.beta]
7-
environment = { BASE_URL = "https://beta.esphome.io", API_DOCS_URL = "https://api-docs-beta.esphome.io" }
7+
environment = { HUGO_BASEURL = "https://beta.esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs-beta.esphome.io" }
88

99
[context.next]
10-
environment = { BASE_URL = "https://next.esphome.io", API_DOCS_URL = "https://api-docs-dev.esphome.io" }
11-
12-
[context.new]
13-
environment = { BASE_URL = "https://new.esphome.io", API_DOCS_URL = "https://api-docs-dev.esphome.io" }
10+
environment = { HUGO_BASEURL = "https://next.esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs-dev.esphome.io" }
1411

1512
[context.production]
16-
environment = { BASE_URL = "https://esphome.io", API_DOCS_URL = "https://api-docs.esphome.io", PRODUCTION = "YES" }
13+
environment = { HUGO_BASEURL = "https://esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs.esphome.io" }
1714

1815

1916
# Caching HTML - 1 week
@@ -77,7 +74,7 @@ status = 301
7774
[[redirects]]
7875
from = "/devices/esp32.html"
7976
to = "/components/esp32.html"
80-
status = 301
77+
status = 301
8178

8279

8380
[[redirects]]
@@ -96,17 +93,17 @@ status = 301
9693
status = 301
9794

9895
[[redirects]]
99-
from = "/components/ota_http_request.html"
96+
from = "/components/ota_http_request*"
10097
to = "/components/ota/http_request.html"
10198
status = 301
10299

103100
[[redirects]]
104-
from = "/components/sensor/mmc5063.html"
101+
from = "/components/sensor/mmc5063*"
105102
to = "/components/sensor/mmc5603.html"
106103
status = 301
107104

108105
[[redirects]]
109-
from = "/components/sensor/kalman_combinator.html"
106+
from = "/components/sensor/kalman_combinator*"
110107
to = "/components/sensor/combination.html"
111108
status = 301
112109

@@ -326,4 +323,3 @@ status = 301
326323
from = "/components/display/qspi_amoled.html"
327324
to = "/components/display/mipi_spi.html"
328325
status = 301
329-
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{{- $components := dict -}}
2+
{{- $baseURL := .Site.BaseURL -}}
3+
{{- if eq $baseURL "" -}}
4+
{{- $baseURL = "https://esphome.io" -}}
5+
{{- end -}}
6+
7+
{{- range .Site.Pages -}}
8+
{{- if (in .RelPermalink "/components/") -}}
9+
{{- $relPath := strings.TrimPrefix "/components/" .RelPermalink -}}
10+
{{- $relPath = strings.TrimSuffix "/" $relPath -}}
11+
12+
{{- if ne $relPath "" -}}
13+
{{- $key := "" -}}
14+
{{- $path := "" -}}
15+
{{- $image := "" -}}
16+
17+
{{- $pathParts := split $relPath "/" -}}
18+
{{- if eq .File.BaseFileName "_index" -}}
19+
{{- /* This is an _index page for a component category */ -}}
20+
{{- if gt (len $pathParts) 0 -}}
21+
{{- $parentDir := index $pathParts 0 -}}
22+
{{- $key = $parentDir -}}
23+
{{- $path = printf "components/%s" $parentDir -}}
24+
{{- end -}}
25+
{{- else if gt (len $pathParts) 1 -}}
26+
{{- /* This is a component page in a subfolder */ -}}
27+
{{- $parentDir := index $pathParts 0 -}}
28+
{{- $fileName := .File.BaseFileName -}}
29+
{{- $key = printf "%s_%s" $parentDir $fileName -}}
30+
{{- $path = printf "components/%s" $fileName -}}
31+
{{- else -}}
32+
{{- /* This is a root-level component */ -}}
33+
{{- $key = .File.BaseFileName -}}
34+
{{- $path = printf "components/%s" .File.BaseFileName -}}
35+
{{- end -}}
36+
37+
{{- with .Params.seo.image -}}
38+
{{- $image = printf "%simages/%s" $baseURL . -}}
39+
{{- end -}}
40+
41+
{{- $component := dict
42+
"title" .Title
43+
"url" .Permalink
44+
"path" $path
45+
"image" $image -}}
46+
47+
{{- $components = merge $components (dict $key $component) -}}
48+
{{- end -}}
49+
{{- end -}}
50+
{{- end -}}
51+
52+
{{- $components | jsonify (dict "indent" " ") -}}

0 commit comments

Comments
 (0)