Skip to content

Commit

Permalink
refactor: use async walk
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Feb 5, 2025
1 parent f553e47 commit f86b6fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/core/prerender/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ export async function prerender(nitro: Nitro) {

// Crawl route links
if (!_route.error && (isImplicitHTML || route.endsWith(".html"))) {
const extractedLinks = extractLinks(
const extractedLinks = await extractLinks(
dataBuff.toString("utf8"),
route,
res,
Expand Down
6 changes: 3 additions & 3 deletions src/core/prerender/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { colors } from "consola/utils";
import type { PrerenderRoute } from "nitropack/types";
import { parseURL } from "ufo";
import { parse as parseHTML, walkSync } from "ultrahtml";
import { parse as parseHTML, walk } from "ultrahtml";

const allowedExtensions = new Set(["", ".json"]);

Expand All @@ -22,7 +22,7 @@ function escapeHtml(text: string) {
);
}

export function extractLinks(
export async function extractLinks(
html: string,
from: string,
res: Response,
Expand All @@ -33,7 +33,7 @@ export function extractLinks(

// Extract from any <TAG href=""> to crawl
if (crawlLinks) {
walkSync(parseHTML(html), (node) => {
await walk(parseHTML(html), (node) => {
if (!node.attributes.href) {
return;
}
Expand Down

0 comments on commit f86b6fc

Please sign in to comment.