-
Notifications
You must be signed in to change notification settings - Fork 0
fix(docs): strip .md extension from internal link targets #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -285,6 +285,48 @@ jobs: | |
| f.write_text(new, encoding="utf-8") | ||
| PY | ||
|
|
||
| - name: Strip .md extension from internal link targets | ||
| # Mintlify routes URLs without the `.md` extension; a | ||
| # markdown link like `[label](./foo.md)` is treated as a | ||
| # literal path that 404s in the rendered site, even when | ||
| # `./foo.md` exists on disk. | ||
| # | ||
| # `[label](dir/index.md)` collapses to `[label](dir)` so it | ||
| # matches the splice's strip-/index registration (the parent | ||
| # path resolves to the dir's index landing natively). Plain | ||
| # `.md` leaves get the extension dropped; fragments are | ||
| # preserved. URL-scheme targets (http://, mailto:, data:) | ||
| # are left alone. | ||
| working-directory: ${{ env.OUTPUT_DIR }} | ||
| run: | | ||
| python3 - <<'PY' | ||
| import pathlib | ||
| import re | ||
|
|
||
| link_re = re.compile(r'(?<!\!)\[([^\]]*)\]\(([^)]+)\)') | ||
|
|
||
| def strip_md(target: str) -> str: | ||
| first_seg = target.split("/", 1)[0] | ||
| if ":" in first_seg: | ||
| return target | ||
| path, _, frag = target.partition("#") | ||
| frag = ("#" + frag) if frag else "" | ||
| if path.endswith("/index.md"): | ||
| path = path[: -len("/index.md")] or "." | ||
| elif path.endswith(".md"): | ||
| path = path[:-3] | ||
| return path + frag | ||
|
|
||
| for f in pathlib.Path(".").rglob("*.md"): | ||
| text = f.read_text(encoding="utf-8") | ||
| def fix(m: re.Match) -> str: | ||
| label, target = m.group(1), m.group(2) | ||
| return f"[{label}]({strip_md(target)})" | ||
| new = link_re.sub(fix, text) | ||
| if new != text: | ||
| f.write_text(new, encoding="utf-8") | ||
| PY | ||
|
Comment on lines
+302
to
+328
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This Python script is duplicated from the Rust documentation template. Duplicating complex post-processing logic across multiple workflow files increases maintenance overhead and the risk of inconsistent behavior. Consider extracting this logic into a shared script or a reusable local action to ensure that fixes (such as handling code spans or link titles) are applied consistently across all SDK documentation. |
||
|
|
||
| - name: Strip TypeDoc breadcrumb header | ||
| # Every typedoc-plugin-markdown page begins with a breadcrumb | ||
| # block that links to ../../README.md and similar paths. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Variable: analytics | ||
|
|
||
| > `const` **analytics**: [`Analytics`](../classes/Analytics.md) | ||
| > `const` **analytics**: [`Analytics`](../classes/Analytics) | ||
|
|
||
| Defined in: [index.ts:220](https://github.com/resq-software/npm/blob/f2ab5fc82f4f501236bfdc25d86881be8e1fb643/packages/analytics/src/index.ts#L220) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| # Variable: track | ||
|
|
||
| > `const` **track**: [`Analytics`](../classes/Analytics.md)\[`"track"`\] | ||
| > `const` **track**: [`Analytics`](../classes/Analytics)\[`"track"`\] | ||
|
|
||
| Defined in: [index.ts:224](https://github.com/resq-software/npm/blob/f2ab5fc82f4f501236bfdc25d86881be8e1fb643/packages/analytics/src/index.ts#L224) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| # Function: useAnalytics() | ||
|
|
||
| > **useAnalytics**(): [`UseAnalyticsReturn`](../interfaces/UseAnalyticsReturn.md) | ||
| > **useAnalytics**(): [`UseAnalyticsReturn`](../interfaces/UseAnalyticsReturn) | ||
|
|
||
| Defined in: [react/index.ts:81](https://github.com/resq-software/npm/blob/f2ab5fc82f4f501236bfdc25d86881be8e1fb643/packages/analytics/src/react/index.ts#L81) | ||
|
|
||
| ## Returns | ||
|
|
||
| [`UseAnalyticsReturn`](../interfaces/UseAnalyticsReturn.md) | ||
| [`UseAnalyticsReturn`](../interfaces/UseAnalyticsReturn) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,4 +2,4 @@ | |
|
|
||
| ## Functions | ||
|
|
||
| - [afterFn](./functions/afterFn.md) | ||
| - [afterFn](./functions/afterFn) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The regex-based link stripping logic has several limitations that should be addressed:
`[label](file.md)`). This violates the general rule requiring parsing logic to respect CommonMark inline code span rules to avoid modifying content inside code snippets.[label](url.md "title")). The regex([^)]+)captures the title as part of the target group, causingstrip_mdto fail to remove the extension because the string ends with a quote instead of.md.path.endswith("/index.md")does not match a link that is exactlyindex.md. In that case, it falls through to the.mdstrip logic and becomesindex, whereas./index.mdbecomes./. This inconsistency may affect how Mintlify resolves directory-level pages.Consider using a more robust parsing approach that identifies code spans first and separates the URL from any optional title.
References