influxdata / influxdata/docs-v2

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
good-first-issue
Dominant language
JavaScript
Stars
82
Forks
326
Avg merge
1d 1h
Merged PRs (30d)
82

Description

## 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](https://github.com/influxdata/docs-v2/pull/7136/commits/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.

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.