Skip to content

Commit b6cfdff

Browse files
committed
fix(tools): build filePath using elementsDir if not present in demo source parts
1 parent 61e2990 commit b6cfdff

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

tools/pfe-tools/custom-elements-manifest/lib/Manifest.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,12 +314,20 @@ export class Manifest {
314314
// strict removes all special characters from slug
315315
slug = slugify(slug, { strict: true, lower: true });
316316
const primaryElementName = deslugify(slug, options.rootDir);
317-
const filePath = path.normalize(
318-
path.posix.join(
319-
options.rootDir,
320-
options.elementsDir,
321-
decodeURIComponent(demo.source?.href.replace(options.sourceControlURLPrefix, '') ?? ''),
322-
));
317+
const demoSource =
318+
decodeURIComponent(demo.source?.href.replace(options.sourceControlURLPrefix, '') ?? '');
319+
// split the demoSource into an array of parts
320+
const demoSourceParts = demoSource.split('/');
321+
// if demoSourceParts contains options.elementsDir, then build the filePath from the rootDir and the demoSource
322+
let filePath;
323+
if (demoSourceParts.includes(options.elementsDir)) {
324+
filePath =
325+
path.normalize(path.posix.join(options.rootDir, demoSource));
326+
// otherwise, build the filePath from the rootDir, options.elementsDir, and the demoSource
327+
} else {
328+
filePath =
329+
path.normalize(path.posix.join(options.rootDir, options.elementsDir, demoSource));
330+
}
323331
const [last = ''] = filePath.split(path.sep).reverse();
324332
const filename = last.replace('.html', '');
325333
const isMainElementDemo = filename === 'index';

tools/pfe-tools/dev-server/plugins/dev-server-templates.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,7 @@ export function pfeDevServerTemplateMiddleware(config: PfeDevServerInternalConfi
6969
if (config.loadDemo && !(method !== 'HEAD' && method !== 'GET' || path.includes('.'))) {
7070
const url = new URL(ctx.request.url, `http://${ctx.request.headers.host}`);
7171
const demos = await getDemos(config);
72-
// const demo = demos.find(x => x.permalink === url.pathname);
73-
let demo = demos.find(x => x.permalink === url.pathname);
74-
// Handle case where URL ends with /demo/ but permalink was shortened to just /
75-
// e.g., request for /compoennts/jazz-hands/demo/ should match demo with permalink /components/jazz-hands/
76-
if (!demo && url.pathname.endsWith('/demo/')) {
77-
const alternativePathname = url.pathname.replace('/demo/', '/');
78-
demo = demos.find(x => x.permalink === alternativePathname);
79-
}
72+
const demo = demos.find(x => x.permalink === url.pathname);
8073
const manifest = demo?.manifest;
8174
const templateContent = await getTemplateContent(demo);
8275
ctx.cwd = process.cwd();

0 commit comments

Comments
 (0)