refactor: replace URL-parsing in shortcodes with cascade product data#6883
refactor: replace URL-parsing in shortcodes with cascade product data#6883jstirnaman merged 7 commits intomasterfrom
Conversation
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.
7093cad to
ce2c426
Compare
sanderson
left a comment
There was a problem hiding this comment.
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.
|
⏺ All 163 tests pass (157 + 6). ⏺ Here's the summary of everything completed: Results 157 cascade shortcode tests (shortcodes.cy.js) — all pass:
6 real-page shortcode tests (shortcodes-real-pages.cy.js)
Total coverage: 27 of 28 shortcodes tested (96%). The only |
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.
|
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. |
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/elsechain mapping URLsegments to
products.ymlkeys, and any new product or path change requiredupdating every shortcode.
Hugo's cascade frontmatter already propagates
productandversionparams toevery page in a section. This PR replaces the URL-parsing logic with a single
shared partial (
product/get-data.html) that looks up the cascadeproductparam in
data/products.yml. Each shortcode now calls that partial instead ofre-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
productkey from any section's_index.mdand directly look up theproduct's full metadata in
data/products.yml. The product identity is explicitin the content structure rather than implicit in URL conventions.
Summary
layouts/partials/product/get-data.html— single lookup partialproductandversionparams to all product section_index.mdfilesproductkey for each product indata/products.ymlTest plan
node cypress/support/run-e2e-specs.js --spec "cypress/e2e/content/shortcodes.cy.js" --no-mappingnode cypress/support/run-e2e-specs.js --spec "cypress/e2e/content/index.cy.js" --no-mapping/influxdb3/core/,/telegraf/v1/)npx hugo --quiet