Skip to content

refactor: replace URL-parsing in shortcodes with cascade product data#6883

Merged
jstirnaman merged 7 commits intomasterfrom
refactor/cascade-product-key
Feb 27, 2026
Merged

refactor: replace URL-parsing in shortcodes with cascade product data#6883
jstirnaman merged 7 commits intomasterfrom
refactor/cascade-product-key

Conversation

@jstirnaman
Copy link
Copy Markdown
Contributor

@jstirnaman jstirnaman commented Feb 26, 2026

Why

The 28 shortcodes that resolve product names, versions, hosts, and limits all
parsed the page URL at render time to figure out which product they belonged to.
This was brittle—every shortcode duplicated a long if/else chain mapping URL
segments to products.yml keys, and any new product or path change required
updating every shortcode.

Hugo's cascade frontmatter already propagates product and version params to
every page in a section. This PR replaces the URL-parsing logic with a single
shared partial (product/get-data.html) that looks up the cascade product
param in data/products.yml. Each shortcode now calls that partial instead of
re-implementing the lookup.

This also benefits AI agents working in the repo. Instead of reverse-engineering
URL segments to understand which product a page belongs to, agents can read the
cascade product key from any section's _index.md and directly look up the
product's full metadata in data/products.yml. The product identity is explicit
in the content structure rather than implicit in URL conventions.

Summary

  • Add layouts/partials/product/get-data.html — single lookup partial
  • Refactor 28 shortcodes to use the partial instead of URL parsing
  • Add cascade product and version params to all product section _index.md files
  • Add product key for each product in data/products.yml
  • Fix product links E2E test to iterate actual home page links instead of all products.yml entries
  • Add 82 Cypress tests validating shortcode output across all 14 product/version combos, with expectations derived from products.yml at runtime

Test plan

  • Run shortcode tests: node cypress/support/run-e2e-specs.js --spec "cypress/e2e/content/shortcodes.cy.js" --no-mapping
  • Run product links test: node cypress/support/run-e2e-specs.js --spec "cypress/e2e/content/index.cy.js" --no-mapping
  • Verify shortcode output on sample pages (e.g., /influxdb3/core/, /telegraf/v1/)
  • Hugo build succeeds: npx hugo --quiet
⏺ Background command "Run shortcode E2E tests" completed (exit code 0)

⏺ All 82 tests passing. Rebase didn't break anything.

  Tests:    82
  Passing:  82
  Failing:  0

@jstirnaman jstirnaman requested a review from a team as a code owner February 26, 2026 22:34
@jstirnaman jstirnaman requested review from sanderson and removed request for a team February 26, 2026 22:34
@jstirnaman jstirnaman marked this pull request as draft February 26, 2026 22:35
Replace duplicated URL-parsing logic across 28 shortcodes with Hugo's
cascade frontmatter. Each product section's _index.md now cascades
`product` (data key) and `version` (URL segment) to all descendants.

Key changes:
- Add cascade frontmatter to 15 product _index.md files
- Create layouts/partials/product/get-data.html shared partial
- Refactor 28 shortcodes to use the partial instead of parsing URLs
- Add version_label, limits, and distributed_architecture metadata
  to data/products.yml to eliminate hardcoded dicts in shortcodes
- Fix lefthook lint-markdown-instructions glob format (YAML array)
- Fix pre-existing Vale exclamation point errors in cloud and v2
…odes

Lefthook's glob option only triggers whether a command runs — it does
not filter {staged_files}. This caused remark-lint to process .md
shortcode files in layouts/, escaping underscores, brackets, and
parentheses that are valid Hugo template syntax.

Add layouts/ exclusion to the existing content/ filter in the
lint-markdown-instructions run command. Also fix the 3 shortcode files
that were damaged by remark-lint in the previous commit.
Add Cypress tests validating all refactored shortcodes across 14
product/version combos (82 tests). Test expectations are derived
from products.yml at runtime via cy.task('getData').

Fix the product links test to iterate actual home page links
instead of all products.yml entries.

Create _test/shortcodes.md pages in each product section
exercising product-name, product-key, current-version,
influxdb/host, and InfluxDB3-specific shortcodes.
@jstirnaman jstirnaman force-pushed the refactor/cascade-product-key branch from 7093cad to ce2c426 Compare February 26, 2026 22:41
@jstirnaman jstirnaman marked this pull request as ready for review February 26, 2026 22:46
Copy link
Copy Markdown
Collaborator

@sanderson sanderson left a comment

Choose a reason for hiding this comment

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

I like it! Question... does it not break anything? 😄

@jstirnaman
Copy link
Copy Markdown
Contributor Author

I like it! Question... does it not break anything? 😄

Had a feeling you'd say that. I'm still checking - I'll probably add more tests.

Add shortcode invocations to all 14 test pages and corresponding
Cypress assertions for version lookups, namespace URLs, product
name text, placeholder_host, version visibility, CTA links, and
site-level data.

Add shortcodes-real-pages.cy.js for 6 shortcodes that require real
page context (cli/mapped, children, flux/list-all-functions,
telegraf/plugins, html-diagram/sso-auth-flow, cli/influxd-flags).

Suppress Vale on test pages — they contain only shortcode syntax,
not prose.

163 tests total, all passing.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 27, 2026

PR Preview Action v1.4.8
🚀 Deployed preview to https://influxdata.github.io/docs-v2/pr-preview/pr-6883/
on branch gh-pages at 2026-02-27 15:35 UTC

@jstirnaman
Copy link
Copy Markdown
Contributor Author

jstirnaman commented Feb 27, 2026

I like it! Question... does it not break anything? 😄

Had a feeling you'd say that. I'm still checking - I'll probably add more tests.

⏺ All 163 tests pass (157 + 6).

⏺ Here's the summary of everything completed:

Results

157 cascade shortcode tests (shortcodes.cy.js) — all pass:

  • Covering 21 shortcodes across 14 product
    test pages
  • Fixed the cli/influx-creds-note failures (Hugo
    auto-generates heading permalink anchors; the test was
    grabbing the wrong with .first())

6 real-page shortcode tests (shortcodes-real-pages.cy.js)
— all pass:

  • cli/mapped on /influxdb/v2/reference/cli/influx/bucket/
  • children on /telegraf/v1/data_formats/
  • flux/list-all-functions on
    /flux/v0/stdlib/all-functions/
  • telegraf/plugins on /telegraf/v1/plugins/
  • html-diagram/sso-auth-flow on
    /influxdb3/cloud-dedicated/admin/sso/
  • cli/influxd-flags on /influxdb/v2/reference/cli/influxd/

Total coverage: 27 of 28 shortcodes tested (96%). The only
untested shortcode is nav-icon, which uses the identical
clockface version lookup already tested by icon.

Rename test page directories from _test to __tests__ to align with
JS testing conventions. Add noindex: true to all 14 test page
frontmatter to prevent search engine indexing in production.
Update Cypress URL pattern to match new paths.
@sanderson
Copy link
Copy Markdown
Collaborator

Cool. Let's do it!

Side note: There are other places I used the URL-parsing technique outside of shortcodes. I did it in layouts as well. Most notable is probably the menu layout. It uses the URL to determine which menu to load. I'm not sure this method will work in those cases, but I may be wrong.

@jstirnaman
Copy link
Copy Markdown
Contributor Author

Cool. Let's do it!

Side note: There are other places I used the URL-parsing technique outside of shortcodes. I did it in layouts as well. Most notable is probably the menu layout. It uses the URL to determine which menu to load. I'm not sure this method will work in those cases, but I may be wrong.

Thanks for the tip! I'll look.

@jstirnaman jstirnaman merged commit 8035366 into master Feb 27, 2026
5 of 6 checks passed
@jstirnaman jstirnaman deleted the refactor/cascade-product-key branch February 27, 2026 15:47
github-actions Bot added a commit that referenced this pull request Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants