|
2 | 2 | * Remark plugin: rewrite relative .md links to Astro-compatible URLs. |
3 | 3 | * |
4 | 4 | * 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). |
6 | 6 | * |
7 | 7 | * Also prepends DOCS_BASE to bare root-relative internal links (e.g. `/grids/grid/...`) |
8 | 8 | * 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. |
9 | 14 | */ |
10 | 15 |
|
11 | 16 | import { visit } from 'unist-util-visit'; |
@@ -36,7 +41,9 @@ function rewriteMdLink(url: string, filePath: string, docsDir: string): string { |
36 | 41 | const slug = rel.endsWith('.md') ? rel.slice(0, -3) : rel; |
37 | 42 |
|
38 | 43 | 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; |
40 | 47 | } |
41 | 48 |
|
42 | 49 | /** Remark plugin that rewrites relative .md links, prepends DOCS_BASE, and fixes relative image paths. */ |
|
0 commit comments