Skip to content

Commit

Permalink
Simplify create_manifest_data (#4370)
Browse files Browse the repository at this point in the history
* simplify a bit

* simplify more

* simplify

* centralise pattern generation

* simplify more

* remove segments from manifest data

* tidy up

* lint

* oops

* remove logging

* reduce indirection
  • Loading branch information
Rich-Harris authored Mar 17, 2022
1 parent 992dc45 commit 79cd456
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 309 deletions.
23 changes: 6 additions & 17 deletions packages/kit/src/core/adapt/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ export function create_builder({ config, build_data, prerendered, log }) {
/** @type {import('types').RouteDefinition[]} */
const facades = routes.map((route) => ({
type: route.type,
segments: route.segments,
segments: route.id.split('/').map((segment) => ({
dynamic: segment.includes('['),
rest: segment.includes('[...'),
content: segment
})),
pattern: route.pattern,
methods: route.type === 'page' ? ['get'] : build_data.server.methods[route.file]
}));
Expand Down Expand Up @@ -68,22 +72,7 @@ export function create_builder({ config, build_data, prerendered, log }) {
// also be included, since the page likely needs the endpoint
filtered.forEach((route) => {
if (route.type === 'page') {
const length = route.segments.length;

const endpoint = routes.find((candidate) => {
if (candidate.segments.length !== length) return false;

for (let i = 0; i < length; i += 1) {
const a = route.segments[i];
const b = candidate.segments[i];

if (i === length - 1) {
return b.content === `${a.content}.json`;
}

if (a.content !== b.content) return false;
}
});
const endpoint = routes.find((candidate) => candidate.id === route.id + '.json');

if (endpoint) {
filtered.add(endpoint);
Expand Down
Loading

0 comments on commit 79cd456

Please sign in to comment.