Skip to content

Commit

Permalink
fix: page sorting by file name order is not working
Browse files Browse the repository at this point in the history
  • Loading branch information
mihar-22 committed Feb 27, 2022
1 parent 0242426 commit 783b1a4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions packages/core/src/node/app/create/resolvePages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ export async function resolvePages(
}

app.pages = filterDuplicateRoutes(
sortPages(Array.from(resolvedPages.values())),
sortPages(Array.from(resolvedPages.values())).map((page) => ({
...page,
route: stripOrderFromRoute(page.route),
})),
);

// `pagesResolved` hook
Expand All @@ -75,7 +78,7 @@ async function resolvePage(app: App, filePath: string): Promise<void> {
const relativeFilePath = app.dirs.root.relative(filePath);
const route =
app.options.resolveRoute?.({ filePath, relativeFilePath }) ??
(await filePathToRoute(app, filePath));
(await filePathToRoute(app, filePath, true));

const page = await plugin.resolvePage?.({
id,
Expand Down Expand Up @@ -136,9 +139,14 @@ const FRONTMATTER_RE = /^---(.|\s|\S)*?---/;
const MD_FILE_ROUTE_RE = /route:\s?(.*)/;
const FILE_ROUTE_RE = /export const __route = (?:'|")(.*?)(?:'|")/;

export function stripOrderFromRoute(route: string) {
return route.replace(/\[\d*\]/g, '');
}

export async function filePathToRoute(
app: App,
filePath: string,
keepOrder = false,
): Promise<string> {
const fileContent = (await readRecentlyChangedFile(filePath)).toString();
const fileExt = path.extname(filePath);
Expand All @@ -156,9 +164,8 @@ export async function filePathToRoute(
configuredRoute += '.html';
}

const route =
configuredRoute ??
path.relative(app.dirs.src.path, filePath).replace(/\[\d*\]/g, '');
let route = configuredRoute ?? path.relative(app.dirs.src.path, filePath);
route = keepOrder ? route : stripOrderFromRoute(route);

const url = new URL(route.toLowerCase(), FAKE_HOST).pathname;

Expand Down

0 comments on commit 783b1a4

Please sign in to comment.