Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion hugo.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ outputs:
home:
- HTML
- RSS
- ComponentsJSON

# Static file configuration
staticDir:
staticDir:
- static

mediaTypes:
Expand All @@ -165,6 +166,12 @@ outputFormats:
mediaType: image/svg+xml
isPlainText: true
isHTML: false
ComponentsJSON:
mediaType: application/json
baseName: components
isPlainText: true
isHTML: false
path: ""

module:
mounts:
Expand Down
20 changes: 8 additions & 12 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
[build]
publish = "public"
command = "make netlify"
environment = { BASE_URL = "https://esphome.io", API_DOCS_URL = "https://api-docs.esphome.io", PYTHON_VERSION = "3.12", HUGO_VERSION = "0.147.8" }
environment = { HUGO_BASEURL = "https://esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs.esphome.io", PYTHON_VERSION = "3.12", HUGO_VERSION = "0.147.8" }

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

[context.next]
environment = { BASE_URL = "https://next.esphome.io", API_DOCS_URL = "https://api-docs-dev.esphome.io" }

[context.new]
environment = { BASE_URL = "https://new.esphome.io", API_DOCS_URL = "https://api-docs-dev.esphome.io" }
environment = { HUGO_BASEURL = "https://next.esphome.io", HUGOxPARAMSxAPI_DOCS_URL = "https://api-docs-dev.esphome.io" }

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


# Caching HTML - 1 week
Expand Down Expand Up @@ -77,7 +74,7 @@ status = 301
[[redirects]]
from = "/devices/esp32.html"
to = "/components/esp32.html"
status = 301
status = 301


[[redirects]]
Expand All @@ -96,17 +93,17 @@ status = 301
status = 301

[[redirects]]
from = "/components/ota_http_request.html"
from = "/components/ota_http_request*"
to = "/components/ota/http_request.html"
status = 301

[[redirects]]
from = "/components/sensor/mmc5063.html"
from = "/components/sensor/mmc5063*"
to = "/components/sensor/mmc5603.html"
status = 301

[[redirects]]
from = "/components/sensor/kalman_combinator.html"
from = "/components/sensor/kalman_combinator*"
to = "/components/sensor/combination.html"
status = 301

Expand Down Expand Up @@ -326,4 +323,3 @@ status = 301
from = "/components/display/qspi_amoled.html"
to = "/components/display/mipi_spi.html"
status = 301

52 changes: 52 additions & 0 deletions themes/esphome-theme/layouts/index.componentsjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{{- $components := dict -}}
{{- $baseURL := .Site.BaseURL -}}
{{- if eq $baseURL "" -}}
{{- $baseURL = "https://esphome.io" -}}
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hardcoded fallback URL 'https://esphome.io' should be configurable or use a site parameter to avoid maintenance issues when the default domain changes.

Suggested change
{{- $baseURL = "https://esphome.io" -}}
{{- if .Site.Params.fallbackBaseURL -}}
{{- $baseURL = .Site.Params.fallbackBaseURL -}}
{{- else -}}
{{- $baseURL = "https://esphome.io" -}}
{{- end -}}

Copilot uses AI. Check for mistakes.
{{- end -}}

{{- range .Site.Pages -}}
{{- if (in .RelPermalink "/components/") -}}
{{- $relPath := strings.TrimPrefix "/components/" .RelPermalink -}}
{{- $relPath = strings.TrimSuffix "/" $relPath -}}

{{- if ne $relPath "" -}}
{{- $key := "" -}}
{{- $path := "" -}}
{{- $image := "" -}}

{{- $pathParts := split $relPath "/" -}}
{{- if eq .File.BaseFileName "_index" -}}
{{- /* This is an _index page for a component category */ -}}
{{- if gt (len $pathParts) 0 -}}
{{- $parentDir := index $pathParts 0 -}}
{{- $key = $parentDir -}}
{{- $path = printf "components/%s" $parentDir -}}
{{- end -}}
{{- else if gt (len $pathParts) 1 -}}
{{- /* This is a component page in a subfolder */ -}}
{{- $parentDir := index $pathParts 0 -}}
{{- $fileName := .File.BaseFileName -}}
{{- $key = printf "%s_%s" $parentDir $fileName -}}
{{- $path = printf "components/%s" $fileName -}}
{{- else -}}
{{- /* This is a root-level component */ -}}
{{- $key = .File.BaseFileName -}}
{{- $path = printf "components/%s" .File.BaseFileName -}}
{{- end -}}

{{- with .Params.seo.image -}}
{{- $image = printf "%simages/%s" $baseURL . -}}
Copy link

Copilot AI Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The image URL construction assumes $baseURL doesn't end with a slash. This could create malformed URLs like 'https://example.com//images/file.png' if $baseURL includes a trailing slash.

Copilot uses AI. Check for mistakes.
{{- end -}}

{{- $component := dict
"title" .Title
"url" .Permalink
"path" $path
"image" $image -}}

{{- $components = merge $components (dict $key $component) -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- $components | jsonify (dict "indent" " ") -}}