Skip to content

Commit

Permalink
fix: ignore invalid values on image discovery (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
rayblair06 committed Jun 27, 2024
1 parent 477f7c8 commit edd0c88
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions .playground/nuxt.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default defineNuxtConfig({
prerender: {
routes: [
// '/sitemap_index.xml',
'/prerender',
'/should-be-in-sitemap',
'/foo.bar/',
'/test.doc',
Expand Down
18 changes: 18 additions & 0 deletions .playground/pages/prerender.vue

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/util/extractSitemapMetaFromHtml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ export function extractSitemapMetaFromHtml(html: string, options?: { images?: bo
const mainRegex = /<main[^>]*>([\s\S]*?)<\/main>/
const mainMatch = mainRegex.exec(html)
if (mainMatch?.[1] && mainMatch[1].includes('<img')) {
// extract image src using regex on the html
const imgRegex = /<img[^>]+src="([^">]+)"/g
// Extract image src attributes using regex on the HTML, but ignore elements with invalid values such as data:, blob:, or file:
const imgRegex = /<img\s+src=["']((?!data:|blob:|file:)[^"']+?)["'][^>]*>/gi

let match
// eslint-disable-next-line no-cond-assign
while ((match = imgRegex.exec(mainMatch[1])) !== null) {
Expand Down

0 comments on commit edd0c88

Please sign in to comment.