Skip to content

Commit

Permalink
fix transitive preloads (#979)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock authored Mar 4, 2024
1 parent b07b78f commit 97aa3ce
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,15 +176,19 @@ function prettyPath(path: string): string {
return path.replace(/\/index$/, "/") || "/";
}

function renderHead(parse: MarkdownPage, resolvers: Resolvers, {scripts, head, root}: RenderOptions): Html {
function renderHead(
parse: MarkdownPage,
{stylesheets, staticImports, resolveImport, resolveStylesheet}: Resolvers,
{scripts, head, root}: RenderOptions
): Html {
if (parse.data?.head !== undefined) head = parse.data.head;
const resolveScript = (src: string) => (/^\w+:/.test(src) ? src : resolvers.resolveImport(relativePath(root, src)));
const resolveScript = (src: string) => (/^\w+:/.test(src) ? src : resolveImport(relativePath(root, src)));
return html`<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>${
Array.from(resolvers.stylesheets, (i) => renderStylesheetPreload(resolvers.resolveStylesheet(i))) // <link rel=preload as=style>
Array.from(new Set(Array.from(stylesheets, (i) => resolveStylesheet(i))), renderStylesheetPreload) // <link rel=preload as=style>
}${
Array.from(resolvers.stylesheets, (i) => renderStylesheet(resolvers.resolveStylesheet(i))) // <link rel=stylesheet>
Array.from(new Set(Array.from(stylesheets, (i) => resolveStylesheet(i))), renderStylesheet) // <link rel=stylesheet>
}${
Array.from(resolvers.staticImports, (i) => renderModulePreload(resolvers.resolveImport(i))) // <link rel=modulepreload>
Array.from(new Set(Array.from(staticImports, (i) => resolveImport(i))), renderModulePreload) // <link rel=modulepreload>
}${
head ? html`\n${html.unsafe(head)}` : null // arbitrary user content
}${
Expand Down
1 change: 1 addition & 0 deletions src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ export async function getResolvers(page: MarkdownPage, {root, path}: {root: stri
const path = resolvePath(value, i.name);
const specifier = `npm:${resolveNpmSpecifier(path)}`;
staticImports.add(specifier);
npmStaticResolutions.add(path);
}
}
}
Expand Down

0 comments on commit 97aa3ce

Please sign in to comment.