Skip to content

Fix components.json and api ref urls for beta/next#5348

Merged
jesserockz merged 2 commits intocurrentfrom
jesserockz-2025-420
Sep 11, 2025
Merged

Fix components.json and api ref urls for beta/next#5348
jesserockz merged 2 commits intocurrentfrom
jesserockz-2025-420

Conversation

@jesserockz
Copy link
Copy Markdown
Member

Description:

Related issue (if applicable): fixes

Pull request in esphome with YAML changes (if applicable):

  • esphome/esphome#

Checklist:

  • I am merging into next because this is new documentation that has a matching pull-request in esphome as linked above.
    or

  • I am merging into current because this is a fix, change and/or adjustment in the current documentation and is not for a new component or feature.

  • Link added in /components/index.rst when creating new documents for new components or cookbook.

New Component Images

If you are adding a new component to ESPHome, you can automatically generate a standardized black and white component name image for the documentation.

To generate a component image:

  1. Comment on this pull request with the following command, replacing COMPONENT_NAME with your component name in UPPER_CASE format with underscores (e.g., BME280, SHT3X, DALLAS_TEMP):

    @esphomebot generate image COMPONENT_NAME
    
  2. The ESPHome bot will respond with a downloadable ZIP file containing the SVG image.

  3. Extract the SVG file and place it in the images/ folder of this repository.

  4. Use the image in your component's index table entry in /components/index.rst.

Example: For a component called "DHT22 Temperature Sensor", use:

@esphomebot generate image DHT22

Copilot AI review requested due to automatic review settings September 10, 2025 21:54
@esphome esphome bot added the current label Sep 10, 2025
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes configuration issues for components.json generation and API reference URLs across different deployment environments (beta/next). The changes ensure proper URL handling for different build contexts by switching from generic environment variables to Hugo-specific ones.

  • Updates environment variable naming in netlify.toml to use Hugo-prefixed variables
  • Creates components.json layout template to generate component data with proper base URLs
  • Configures Hugo to output components.json format and minor formatting fixes

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
themes/esphome-theme/layouts/index.componentsjson New template for generating components.json with proper URL handling
netlify.toml Updates environment variables to Hugo-specific format and removes unused context
hugo.yaml Adds ComponentsJSON output format and fixes formatting

{{- $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 -}}

{{- 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.
@netlify
Copy link
Copy Markdown

netlify bot commented Sep 10, 2025

Deploy Preview for esphome ready!

Name Link
🔨 Latest commit b039e07
🔍 Latest deploy log https://app.netlify.com/projects/esphome/deploys/68c21412f1ecb200088b50c6
😎 Deploy Preview https://deploy-preview-5348--esphome.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Sep 10, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds a ComponentsJSON Hugo output format and enables it on the home output, adds a template that emits a pretty-printed components.json from pages under /components, and updates Netlify config: renames build/context env vars, removes one context, and generalizes several redirect-from patterns to wildcards.

Changes

Cohort / File(s) Summary
Hugo output configuration
hugo.yaml
Adds ComponentsJSON to outputs.home. Registers outputFormats.ComponentsJSON with mediaType application/json, baseName: components, isPlainText: true, isHTML: false, path: "". Minor whitespace tweak to staticDir.
Netlify environments & redirects
netlify.toml
Renames build/context env keys: BASE_URLHUGO_BASEURL, API_DOCS_URLHUGOxPARAMSxAPI_DOCS_URL; removes [context.new]; updates several redirect from values from exact ...*.html to wildcard ...*. Minor whitespace/line-end adjustments.
Components JSON template
themes/esphome-theme/layouts/index.componentsjson
New Hugo layout that iterates .Site.Pages under /components, computes keys/paths (handles _index and subpages), includes optional SEO image URL using .Site.BaseURL, merges entries into a components dictionary, and emits pretty-printed JSON via jsonify.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Hugo as Hugo Build
  participant Tmpl as index.componentsjson
  participant FS as Public Dir

  rect rgba(200,220,255,0.25)
    Hugo->>Tmpl: Render ComponentsJSON output (outputs.home)
    Tmpl->>Tmpl: Iterate .Site.Pages filtering "/components/"
    Tmpl->>Tmpl: Compute key, path, optional image, merge into map
    Tmpl-->>Hugo: Return components.json (pretty JSON)
    Hugo->>FS: Write /components.json to public root
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • nagyrobi
  • kbx81

Pre-merge checks (2 passed, 1 inconclusive)

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description Check ❓ Inconclusive The PR description is a generic template with placeholders and a checklist but does not summarize the actual file changes (components.json output, new layout, and netlify.toml edits) or link to the related esphome PR/issue, so it is too vague to be helpful to reviewers. Please update the description with a short summary of the concrete changes, include links to the related issue and the esphome PR (if applicable), and mark the correct merge target (current vs next) to make the PR reviewable.
✅ Passed checks (2 passed)
Check name Status Explanation
Title Check ✅ Passed The current title "Fix components.json and api ref urls for beta/next" concisely summarizes the primary changes in this PR — fixing components.json generation and adjusting API reference URLs for beta/next — and aligns with the provided diffs and PR objectives, so it is clear and relevant to reviewers.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jesserockz-2025-420

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
netlify.toml (1)

47-49: Fix broken /api/ redirect — placeholder not populated*

Verified: no sed in Makefile replaces {{API_DOCS_URL}}; netlify.toml still has to = "{{API_DOCS_URL}}/:splat" (line 48); env blocks define HUGOxPARAMSxAPI_DOCS_URL but not API_DOCS_URL (lines 4,7,10,13). Redirects will fail.

Two minimal fixes — pick one:

  • Replace the redirect to use the existing var: change line 48 to to = "{{HUGOxPARAMSxAPI_DOCS_URL}}/:splat".
  • Or reintroduce API_DOCS_URL in the Netlify env blocks (add API_DOCS_URL = "<matching URL>" in [build], [context.beta], [context.next], [context.production]) so the current placeholder resolves.
🧹 Nitpick comments (3)
themes/esphome-theme/layouts/index.componentsjson (3)

7-8: Limit to regular content pages under the components section

Using .Site.Pages + substring match can include non-regular pages. Prefer RegularPages and the Section filter; it naturally excludes sections/_index.

-{{- range .Site.Pages -}}
-  {{- if and (in .RelPermalink "/components/") (ne .Kind "section") (ne .File.BaseFileName "_index") -}}
+{{- range where .Site.RegularPages "Section" "components" -}}
+  {{- /* RegularPages excludes sections and _index automatically */ -}}

9-11: Remove unused variable

$relPath is computed but never used. Safe to drop.

-    {{- $relPath := strings.TrimPrefix "/components/" .RelPermalink -}}
-    {{- $relPath = strings.TrimSuffix "/" $relPath -}}

16-27: Guard against missing .Parent.File on section parents

Some section parents may not have a File; accessing .Parent.File.BaseFileName can be empty. Add a defensive with to avoid surprises.

-    {{- if .Parent -}}
-      {{- if ne .Parent.File.BaseFileName "_index" -}}
-        {{- $key = printf "%s_%s" .Parent.File.BaseFileName .File.BaseFileName -}}
-        {{- $path = printf "components/%s" .Parent.File.BaseFileName -}}
-      {{- else -}}
+    {{- if .Parent -}}
+      {{- with .Parent.File -}}
+        {{- if ne .BaseFileName "_index" -}}
+          {{- $key = printf "%s_%s" .BaseFileName $.File.BaseFileName -}}
+          {{- $path = printf "components/%s" .BaseFileName -}}
+        {{- else -}}
+          {{- $key = $.File.BaseFileName -}}
+          {{- $path = printf "components/%s" $.File.BaseFileName -}}
+        {{- end -}}
+      {{- else -}}
         {{- $key = .File.BaseFileName -}}
         {{- $path = printf "components/%s" .File.BaseFileName -}}
-      {{- end -}}
+      {{- end -}}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b10305 and 4a0ad2a.

📒 Files selected for processing (3)
  • hugo.yaml (2 hunks)
  • netlify.toml (3 hunks)
  • themes/esphome-theme/layouts/index.componentsjson (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • hugo.yaml
  • netlify.toml
  • themes/esphome-theme/layouts/index.componentsjson
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: esphome/esphome-docs#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-24T00:13:13.459Z
Learning: Open pull requests against the correct base branch: use `current` for documentation-only revisions and `next` for changes tied to new features in esphome/esphome
🔇 Additional comments (7)
hugo.yaml (3)

149-154: Registering ComponentsJSON on home output looks good

This will emit /components.json from the home node as intended, given the matching index.componentsjson template.


156-158: No functional change in staticDir

Whitespace-only tweak; nothing to do.


169-175: Output format definition is correct; keep name in sync with template suffix

The format name ComponentsJSON matches the template suffix index.componentsjson, mediaType is JSON, and path "" targets site root. All good.

netlify.toml (4)

4-4: Env rename aligns with Hugo conventions

HUGO_BASEURL and HUGOxPARAMSxAPI_DOCS_URL look good; versions unchanged.


6-14: Context env renames look consistent

beta/next/production now set the new keys; values look correct.


96-109: Wildcard “from” patterns are a useful broadening

Covers both .html and extension-less variants; destinations look correct.


77-78: Whitespace-only change

No action needed.

@jesserockz jesserockz marked this pull request as draft September 10, 2025 23:54
@jesserockz jesserockz marked this pull request as ready for review September 11, 2025 00:44
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

♻️ Duplicate comments (2)
themes/esphome-theme/layouts/index.componentsjson (2)

2-5: Drop manual BaseURL fallback; rely on absURL instead.

Hardcoding a fallback and concatenating strings is brittle across environments; absURL (with urls.JoinPath when needed) handles slashes and base changes.

-{{- $baseURL := .Site.BaseURL -}}
-{{- if eq $baseURL "" -}}
-  {{- $baseURL = "https://esphome.io" -}}
-{{- end -}}

37-39: Fix image URL construction (double “images” and slash issues).

Use absURL and urls.JoinPath; handle already-absolute values.

-    {{- with .Params.seo.image -}}
-      {{- $image = printf "%simages/%s" $baseURL . -}}
-    {{- end -}}
+    {{- with .Params.seo.image -}}
+      {{- $img := . -}}
+      {{- if and (not (hasPrefix $img "/")) (not (hasPrefix $img "http")) -}}
+        {{- $img = (urls.JoinPath "images" $img) -}}
+      {{- end -}}
+      {{- $image = ($img | absURL) -}}
+    {{- end -}}
🧹 Nitpick comments (3)
themes/esphome-theme/layouts/index.componentsjson (3)

7-8: Filter pages by section instead of substring match.

More precise and faster; also removes the extra if block.

-{{- range .Site.Pages -}}
-  {{- if (in .RelPermalink "/components/") -}}
+{{- range where .Site.RegularPages "Section" "components" -}}
@@
-  {{- end -}}

Also applies to: 49-49


41-45: Avoid emitting empty “image” keys.

Only add the field when present to keep JSON clean.

-    {{- $component := dict
-         "title" .Title
-         "url" .Permalink
-         "path" $path
-         "image" $image -}}
+    {{- $component := dict "title" .Title "url" .Permalink "path" $path -}}
+    {{- with $image -}}
+      {{- $component = merge $component (dict "image" .) -}}
+    {{- end -}}

9-11: Derive path parts from file metadata, not URL strings (optional).

Using .File.Dir/.File.BaseFileName avoids edge cases with .RelPermalink formatting.

Example (for reference, not a full patch):

{{- $dir := trim (replace .File.Dir "components/" "" 1) "/" -}}
{{- $pathParts := split $dir "/" -}}

Also applies to: 17-17

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a0ad2a and b039e07.

📒 Files selected for processing (1)
  • themes/esphome-theme/layouts/index.componentsjson (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**

⚙️ CodeRabbit configuration file

  • Do not generate or add any sequence diagrams

Files:

  • themes/esphome-theme/layouts/index.componentsjson
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: esphome/esphome-docs#0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-08-24T00:13:13.459Z
Learning: Open pull requests against the correct base branch: use `current` for documentation-only revisions and `next` for changes tied to new features in esphome/esphome
Learnt from: jesserockz
PR: esphome/esphome-docs#4865
File: .github/workflows/needs-docs.yml:0-0
Timestamp: 2025-05-01T03:29:47.922Z
Learning: In the esphome-docs repository, the "current" label is automatically added by a bot to pull requests, making it a reliable indicator for the target branch.

@jesserockz jesserockz merged commit dbaafd4 into current Sep 11, 2025
4 checks passed
@jesserockz jesserockz deleted the jesserockz-2025-420 branch September 11, 2025 00:58
@github-actions github-actions bot locked and limited conversation to collaborators Sep 12, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants