Apply getSourceFromFrontmatter fixes to scripts/docs-cli/lib/content-utils.js

Open Beginner friendly
#7,141 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
74/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
javascript
Domain
cli

Research direction

Compare scripts/docs-cli/lib/content-utils.js with the fixed implementation in scripts/lib/content-utils.js and the referenced #7136 commit. Check how scripts/docs-cli/commands/edit.js consumes getSourceFromFrontmatter. Done means the docs-cli copy only reads the top frontmatter block, normalizes the listed shared paths consistently, and returns null for absolute paths or URLs.

Written by the indexing model from the issue text.

Description

good-first-issue

Problem

There are two copies of getSourceFromFrontmatter in the repo:

  • scripts/lib/content-utils.js — fixed in #7136
  • scripts/docs-cli/lib/content-utils.js — still has the original bugs

Both copies should behave the same way. The docs-cli copy is used by docs edit (via scripts/docs-cli/commands/edit.js) to find a shared source file when opening a consumer page. Its bugs are latent there but still real:

Bugs in the docs-cli copy
  1. Regex matches outside the frontmatter block. content.match(/^source:\s*(.+)$/m) matches ^source: anywhere in the file, so a source: key inside a fenced YAML example (for example, Docker Compose docs) gets treated as the page's shared source. docs edit will then try to open the wrong file.

  2. Only normalizes paths starting with /. Frontmatter of the form source: shared/foo.md (without a leading slash) is returned verbatim as shared/foo.md, which is a relative path that doesn't resolve from the caller's cwd. docs edit either fails or opens something unexpected.

Fix

Port the fix from #7136 (commit 5241ff7a5) to the docs-cli copy:

  • Restrict the regex to match only within the top-of-file frontmatter block (between --- delimiters).
  • Normalize /shared/..., shared/..., and content/shared/... consistently.
  • Return null for unexpected shapes (absolute filesystem paths, URLs) rather than returning a misleading path.

Longer term

The two copies are drift-prone. A follow-up refactor could consolidate on a single source of truth — either re-export from one location, or move the helper to a shared module both scripts import.

Context

Flagged during review of #7136, which fixed the CI-path copy but deferred this one to keep PR scope tight.

Dominant language
JavaScript
Stars
82
Forks
326
Avg merge
1d 1h
Merged PRs (30d)
82

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from influxdata/docs-v2

All issues in influxdata/docs-v2

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.