Skip to content

Commit

Permalink
feat: add serializeHtml
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Mar 1, 2025
1 parent 8a5b2b1 commit 6018775
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ module.exports = ({
if (scripts) injectScripts({ $, scripts, type: 'text/javascript' })
if (modules) injectScripts({ $, modules, type: 'module' })

return rewriteUrls ? rewriteCssUrls({ html: $.html(), url }) : $.html()
return rewriteUrls ? rewriteCssUrls({ html: $.html(), url }) : $
}

module.exports.getDate = getDate
12 changes: 8 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ const getContent = PCancelable.fn(
onCancel(() => promise.cancel())

return promise.then(content => {
const html = addHtml({
const $ = addHtml({
...content,
...(isFetchMode ? puppeteerOpts : undefined),
rewriteUrls,
rewriteHtml
})

return { ...content, html }
return { ...content, $ }
})
}
)
Expand All @@ -260,6 +260,7 @@ module.exports = PCancelable.fn(
headers,
mutoolPath = defaultMutoolPath(),
prerender = 'auto',
serializeHtml = $ => ({ html: $.html() }),
puppeteerOpts,
rewriteUrls = false,
rewriteHtml = false
Expand Down Expand Up @@ -291,9 +292,12 @@ module.exports = PCancelable.fn(

onCancel(() => promise.cancel())

const { mode, ...payload } = await promise
const { mode, $, ...payload } = await promise

return Object.assign(payload, { stats: { mode, timing: duration() } })
return Object.assign(payload, {
...serializeHtml($),
stats: { mode, timing: duration() }
})
}
)

Expand Down

0 comments on commit 6018775

Please sign in to comment.