Skip to content

Commit 5d07471

Browse files
authored
Merge pull request #199 from IgniteUI/sstoychev/fix-in-topic-links
fix(astro): changing remark md links to respect trailingslash rules
2 parents 9d3a8b7 + dfe5623 commit 5d07471

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/integration.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,7 @@ export function createDocsSite(options: CreateDocsSiteOptions = {} as CreateDocs
574574
}
575575
process.env.DOCS_BUILD_MODE = mode;
576576
process.env.DOCS_BASE = base ? base.replace(/\/$/, '') : '';
577+
process.env.DOCS_TRAILING_SLASH = (astroExtra.trailingSlash as string) ?? 'ignore';
577578
if (!process.env.DOCS_ENV) {
578579
process.env.DOCS_ENV = mode;
579580
}

src/plugins/remark-md-links.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22
* Remark plugin: rewrite relative .md links to Astro-compatible URLs.
33
*
44
* Transforms `[label](./some-page.md)` or `[label](../folder/page.md#section)`
5-
* into root-relative URLs like `/products/.../some-page/` (with DOCS_BASE prepended).
5+
* into root-relative URLs like `/products/.../some-page` (with DOCS_BASE prepended).
66
*
77
* Also prepends DOCS_BASE to bare root-relative internal links (e.g. `/grids/grid/...`)
88
* that are already absolute but missing the site base path.
9+
*
10+
* Respects trailing slash preference via DOCS_TRAILING_SLASH env var, which can be 'always', 'never', or 'ignore'.
11+
* By default both Angular and Xplat astro docs use trailing slash 'never'.
12+
*
13+
* Non-relative links (starting with http://, https://, /, #, or mailto:) and non-.md links are left unchanged.
914
*/
1015

1116
import { visit } from 'unist-util-visit';
@@ -36,7 +41,9 @@ function rewriteMdLink(url: string, filePath: string, docsDir: string): string {
3641
const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel;
3742

3843
const docsBase = (process.env.DOCS_BASE ?? '').replace(/\/$/, '');
39-
return docsBase + '/' + slug.toLowerCase() + '/' + suffix;
44+
const trailingSlash = process.env.DOCS_TRAILING_SLASH ?? 'ignore';
45+
const trail = trailingSlash === 'never' ? '' : '/';
46+
return docsBase + '/' + slug.toLowerCase() + trail + suffix;
4047
}
4148

4249
/** Remark plugin that rewrites relative .md links, prepends DOCS_BASE, and fixes relative image paths. */

0 commit comments

Comments
 (0)