Skip to content

Commit 7657e36

Browse files
committed
fix(tools): realign subpath url across dev-server and docs
1 parent e6fbddc commit 7657e36

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

tools/pfe-tools/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface SiteOptions {
1313
stylesheets?: string[];
1414
/** Title for main page of the demo */
1515
title?: string;
16-
/** Site subpath for components. e.g. 'elements'. default: 'components' */
16+
/** Site subpath for components. e.g. 'components'. default: 'components' */
1717
componentSubpath?: string;
1818
}
1919

tools/pfe-tools/dev-server/config.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,6 @@ async function renderURL(context: Context, options: PfeDevServerInternalConfig):
7575
const demos = manifests
7676
.flatMap(manifest => manifest.getTagNames()
7777
.flatMap(tagName => manifest.getDemoMetadata(tagName, options as PfeDevServerInternalConfig)));
78-
/* Rewrite the permalink to match location of the dev server componentSubpath */
79-
demos.forEach(demo => {
80-
if (demo?.permalink) {
81-
demo.permalink = demo.permalink.replace(options.site.componentSubpath, options.elementsDir);
82-
}
83-
});
8478
const demo = demos.find(x => x.permalink === url.pathname);
8579
const manifest = demo?.manifest;
8680

@@ -101,7 +95,7 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
10195
name: 'pfe-dev-server',
10296
async serverStart({ fileWatcher, app }) {
10397
const { elementsDir, tagPrefix } = options;
104-
98+
const { componentSubpath } = options.site;
10599
const router =
106100
new Router()
107101
.get(/\/pf-icon\/icons\/.*\.js$/, (ctx, next) => {
@@ -112,23 +106,28 @@ function pfeDevServerPlugin(options: PfeDevServerInternalConfig): Plugin {
112106
ctx.body = await makeDemoEnv(options.rootDir);
113107
ctx.type = 'application/javascript';
114108
})
109+
// Redirect `components/jazz-hands/*.js` to `components/pf-jazz-hands/*.ts`
110+
.get(`/${componentSubpath}/:element/:fileName.js`, async ctx => {
111+
const { element, fileName } = ctx.params;
112+
ctx.redirect(`/${elementsDir}/${element}/${fileName}.ts`);
113+
})
115114
// Redirect `elements/jazz-hands/*.js` to `elements/pf-jazz-hands/*.ts`
116115
.get(`/${elementsDir}/:element/:fileName.js`, async ctx => {
117116
const { element, fileName } = ctx.params;
118117
ctx.redirect(`/${elementsDir}/${element}/${fileName}.ts`);
119118
})
120-
// Redirect `elements/jazz-hands/demo/*.js|css` to `elements/pf-jazz-hands/demo/*.js|css`
121-
// If request is `elements/jazz-hands/demo/some-other-demo/*.js|css redirect files to `elements/pf-jazz-hands/demo/*.js|css`
122-
.get(`/${elementsDir}/:element/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
119+
// Redirect `components/jazz-hands/demo/*.js|css` to `components/pf-jazz-hands/demo/*.js|css`
120+
// If request is `components/jazz-hands/demo/some-other-demo/*.js|css redirect files to `components/pf-jazz-hands/demo/*.js|css`
121+
.get(`/${componentSubpath}/:element/demo/:demoSubDir?/:fileName.:ext`, async (ctx, next) => {
123122
const { element, fileName, ext } = ctx.params;
124123
if (!element.includes(tagPrefix)) {
125124
ctx.redirect(`/${elementsDir}/${tagPrefix}-${element}/demo/${fileName}.${ext}`);
126125
} else {
127126
return next();
128127
}
129128
})
130-
// Redirect `elements/jazz-hands/*` to `elements/pf-jazz-hands/*` for requests not previously handled
131-
.get(`/${elementsDir}/:element/:splatPath*`, async (ctx, next) => {
129+
// Redirect `components/jazz-hands/*` to `components/pf-jazz-hands/*` for requests not previously handled
130+
.get(`/${componentSubpath}/:element/:splatPath*`, async (ctx, next) => {
132131
const { element, splatPath } = ctx.params;
133132
if (splatPath.includes('demo')) {
134133
/* if its the demo directory return */

0 commit comments

Comments
 (0)