Skip to content

Commit 109bc4b

Browse files
authored
try to fix urls (#4740)
1 parent 04df16c commit 109bc4b

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/documentation-framework/components/example/example.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,17 @@ export const Example = ({
218218
? getStaticParams(title, editorCode)
219219
: getReactParams(title, editorCode, scope, lang, relativeImports, relPath, sourceLink)
220220
);
221-
const fullscreenLink =
222-
loc.pathname.replace(/\/$/, '') + (loc.pathname.endsWith(source) ? '' : `/${source}`) + '/' + slugger(title);
221+
const fullscreenLink = (() => {
222+
const cleanPathname = loc.pathname.replace(/\/$/, '');
223+
const sourcePath = `/${source}`;
224+
225+
// Check if the source is already in the pathname to avoid duplication
226+
if (cleanPathname.includes(sourcePath)) {
227+
return `${cleanPathname}/${slugger(title)}`;
228+
} else {
229+
return `${cleanPathname}${sourcePath}/${slugger(title)}`;
230+
}
231+
})();
223232

224233
const hasMetaText = isBeta || isDemo || isDeprecated || false;
225234
const tooltips = (

packages/documentation-framework/scripts/webpack/getHtmlWebpackPlugins.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ async function getHtmlWebpackPlugins(options) {
3636
filename: 'sitemap.xml',
3737
templateParameters: {
3838
urls: Object.entries(routes)
39-
.map(([path, { sources }]) => [path, ...(sources || []).slice(1).map((source) => source.slug)])
39+
.map(([path, { sources }]) => [
40+
path,
41+
...(sources || []).slice(1)
42+
.filter(source => source.slug !== path) // Filter out sources that would create duplicate routes
43+
.map((source) => source.slug)
44+
])
4045
.flat()
4146
},
4247
inject: false,
@@ -54,8 +59,10 @@ async function getHtmlWebpackPlugins(options) {
5459
.concat(Object.entries(fullscreenRoutes))
5560
.map(([url, { sources = [], title, isFullscreen }]) => [
5661
[url, { title, isFullscreen }],
57-
// Add pages for sources
58-
...sources.slice(1).map((source) => [source.slug, source])
62+
// Add pages for sources, but filter out duplicates
63+
...sources.slice(1)
64+
.filter(source => source.slug !== url) // Filter out sources that would create duplicate routes
65+
.map((source) => [source.slug, source])
5966
])
6067
.flat()
6168
.sort();

0 commit comments

Comments
 (0)