Skip to content

Commit

Permalink
[core] Fix deploy preview links (mui#36203)
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp authored Feb 15, 2023
1 parent 10761a8 commit 718d377
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
22 changes: 15 additions & 7 deletions dangerfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,26 @@ function addDeployPreviewUrls() {
* e.g. ['docs/data/joy/components/button/button.md']
*/
function formatFileToLink(path: string) {
const url = path.replace('docs/data', '').replace(/\/[^/]+\.md$/, '/');
let url = path.replace('docs/data', '').replace(/\.md$/, '');

const fragments = url.split('/').reverse();
if (fragments[0] === fragments[1]) {
// check if the end of pathname is the same as the one before
// e.g. `/data/material/getting-started/overview/overview.md
url = fragments.slice(1).reverse().join('/');
}

if (url.startsWith('/material')) {
// needs to convert to correct material legacy folder structure to the existing url.
return replaceUrl(url.replace('/material', ''), '').replace(/^\//, '');
url = replaceUrl(url.replace('/material', ''), '/material-ui').replace(/^\//, '');
} else {
url = url
.replace(/^\//, '') // remove initial `/`
.replace('joy/', 'joy-ui/')
.replace('components/', 'react-');
}

return url
.replace(/^\//, '') // remove initial `/`
.replace('joy/', 'joy-ui/')
.replace('components/', 'react-')
.replace(/\/[^/]+\.md$/, '/');
return url;
}

const netlifyPreview = `https://deploy-preview-${danger.github.pr.number}--material-ui.netlify.app/`;
Expand Down
6 changes: 6 additions & 0 deletions packages/api-docs-builder/utils/replaceUrl.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ describe('replaceUrl', () => {
expect(replaceMaterialLinks(`/discover-more/related-projects/`)).to.equal(
`/material-ui/discover-more/related-projects/`,
);
expect(replaceMaterialLinks(`/experimental-api/css-theme-variables/overview/`)).to.equal(
`/material-ui/experimental-api/css-theme-variables/overview/`,
);
expect(replaceMaterialLinks(`/migration/migration-grid-v2/`)).to.equal(
`/material-ui/migration/migration-grid-v2/`,
);
});

it('should not change if links have been updated', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/api-docs-builder/utils/replaceUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ export const replaceMaterialLinks = (url: string) => {
if (isNewLocation(url)) {
return url;
}
return url.replace(/(guides|customization|getting-started|discover-more)/, 'material-ui/$1');
return url.replace(
/(guides|customization|getting-started|discover-more|experimental-api|migration)/,
'material-ui/$1',
);
};

export const replaceComponentLinks = (url: string) => {
Expand Down

0 comments on commit 718d377

Please sign in to comment.