Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

embedded assets #1681

Merged
merged 5 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export async function build(
const addStylesheet = (path: string, s: string) => stylesheets.add(/^\w+:/.test(s) ? s : resolvePath(path, s));

// Load pages, building a list of additional assets as we go.
let assetCount = 0;
let pageCount = 0;
for await (const path of config.paths()) {
effects.output.write(`${faint("load")} ${path} `);
const start = performance.now();
Expand All @@ -86,9 +88,18 @@ export async function build(
for (const s of resolvers.stylesheets) addStylesheet(path, s);
effects.output.write(`${faint("in")} ${(elapsed >= 100 ? yellow : faint)(`${elapsed}ms`)}\n`);
outputs.set(path, {type: "module", resolvers});
++assetCount;
continue;
}
}
const file = loaders.find(path);
if (file) {
effects.output.write(`${faint("copy")} ${join(root, path)} ${faint("→")} `);
const sourcePath = join(root, await file.load({useStale: true}, effects));
await effects.copyFile(sourcePath, path);
++assetCount;
continue;
}
const page = await loaders.loadPage(path, options, effects);
if (page.data.draft) {
effects.logger.log(faint("(skipped)"));
Expand All @@ -103,12 +114,14 @@ export async function build(
for (const s of resolvers.stylesheets) addStylesheet(path, s);
effects.output.write(`${faint("in")} ${(elapsed >= 100 ? yellow : faint)(`${elapsed}ms`)}\n`);
outputs.set(path, {type: "page", page, resolvers});
++pageCount;
}

// Check that there’s at least one output.
const outputCount = outputs.size;
const outputCount = pageCount + assetCount;
if (!outputCount) throw new CliError(`Nothing to build: no pages found in your ${root} directory.`);
effects.logger.log(`${faint("built")} ${outputCount} ${faint(`page${outputCount === 1 ? "" : "s"} in`)} ${root}`);
if (pageCount) effects.logger.log(`${faint("built")} ${pageCount} ${faint(`page${pageCount === 1 ? "" : "s"} in`)} ${root}`); // prettier-ignore
if (assetCount) effects.logger.log(`${faint("built")} ${assetCount} ${faint(`asset${assetCount === 1 ? "" : "s"} in`)} ${root}`); // prettier-ignore

// For cache-breaking we rename most assets to include content hashes.
const aliases = new Map<string, string>();
Expand Down Expand Up @@ -349,7 +362,7 @@ export async function build(
}
effects.logger.log("");

Telemetry.record({event: "build", step: "finish", pageCount: outputCount});
Telemetry.record({event: "build", step: "finish", pageCount});
}

function applyHash(path: string, hash: string): string {
Expand Down
3 changes: 2 additions & 1 deletion src/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ async function* indexPages(config: Config, effects: SearchIndexEffects): AsyncIt
}

for await (const path of config.paths()) {
mbostock marked this conversation as resolved.
Show resolved Hide resolved
if (path.endsWith(".js") && findModule(root, path)) continue;
if (path.endsWith(".js") && findModule(root, path)) continue; // ignore modules
if (loaders.find(path)) continue; // ignore assets
const {body, title, data} = await loaders.loadPage(path, {...config, path});

// Skip pages that opt-out of indexing, and skip unlisted pages unless
Expand Down