From 2e1fbe203be32e9fcf717ad483e8c7200c4d3df0 Mon Sep 17 00:00:00 2001 From: Anastasia Rodionova Date: Tue, 8 Jun 2021 19:45:13 +0200 Subject: [PATCH] Do not add / for html pages in rewriteDocLinks Signed-off-by: Anastasia Rodionova --- .changeset/seven-wolves-clean.md | 5 +++++ .../techdocs/src/reader/transformers/rewriteDocLinks.test.ts | 1 + plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 .changeset/seven-wolves-clean.md diff --git a/.changeset/seven-wolves-clean.md b/.changeset/seven-wolves-clean.md new file mode 100644 index 0000000000..3b807b1af6 --- /dev/null +++ b/.changeset/seven-wolves-clean.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-techdocs': patch +--- + +Do not add trailing slash for .html pages during doc links rewriting diff --git a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.test.ts b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.test.ts index 01467f665d..4ebd7411ac 100644 --- a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.test.ts +++ b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.test.ts @@ -82,6 +82,7 @@ describe('normalizeUrl', () => { ['http://example.org/folder#intro', 'http://example.org/folder/#intro'], ['http://example.org/folder/#intro', 'http://example.org/folder/#intro'], ['http://example.org/folder#', 'http://example.org/folder/#'], + ['http://example.org/page.html', 'http://example.org/page.html'], ])('should handle %s', (url, expected) => { expect(normalizeUrl(url)).toEqual(expected); }); diff --git a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts index 8c4bc29201..8d8fafa454 100644 --- a/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts +++ b/plugins/techdocs/src/reader/transformers/rewriteDocLinks.ts @@ -58,7 +58,7 @@ export const rewriteDocLinks = (): Transformer => { export function normalizeUrl(input: string): string { const url = new URL(input); - if (!url.pathname.endsWith('/')) { + if (!url.pathname.endsWith('/') && !url.pathname.endsWith('.html')) { url.pathname += '/'; }