fix: extract JSON-LD script generation to resolve parsing errors

Refactor inline template literals with nested JSON.stringify() into
separate derived variables. Fixes 6 ESLint parsing errors in route files.
This commit is contained in:
Justin Edmund 2025-11-23 04:47:26 -08:00
parent d60eba6e90
commit ec0431d2b0
6 changed files with 41 additions and 11 deletions

View file

@ -26,11 +26,16 @@
] ]
}) })
) )
const personJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape
`<script type="application/ld+json">${JSON.stringify(personJsonLd)}<\/script>`
)
</script> </script>
<svelte:head> <svelte:head>
<!-- Site-wide JSON-LD --> <!-- Site-wide JSON-LD -->
{@html `<script type="application/ld+json">${JSON.stringify(personJsonLd)}</script>`} {@html personJsonLdScript}
</svelte:head> </svelte:head>
<div class="layout-wrapper" class:admin-route={isAdminRoute}> <div class="layout-wrapper" class:admin-route={isAdminRoute}>

View file

@ -116,6 +116,11 @@
// Generate image gallery JSON-LD // Generate image gallery JSON-LD
const galleryJsonLd = $derived(album ? generateAlbumJsonLd(album, pageUrl) : null) const galleryJsonLd = $derived(album ? generateAlbumJsonLd(album, pageUrl) : null)
const galleryJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape -- Escape required for Svelte parser
galleryJsonLd ? `<script type="application/ld+json">${JSON.stringify(galleryJsonLd)}<\/script>` : null
)
</script> </script>
<svelte:head> <svelte:head>
@ -136,8 +141,8 @@
<link rel="canonical" href={metaTags.other.canonical} /> <link rel="canonical" href={metaTags.other.canonical} />
<!-- JSON-LD --> <!-- JSON-LD -->
{#if galleryJsonLd} {#if galleryJsonLdScript}
{@html `<script type="application/ld+json">${JSON.stringify(galleryJsonLd)}</script>`} {@html galleryJsonLdScript}
{/if} {/if}
</svelte:head> </svelte:head>

View file

@ -48,6 +48,11 @@
}) })
: null : null
) )
const projectJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape -- Escape required for Svelte parser
projectJsonLd ? `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}<\/script>` : null
)
</script> </script>
<svelte:head> <svelte:head>
@ -73,8 +78,8 @@
{/if} {/if}
<!-- JSON-LD --> <!-- JSON-LD -->
{#if projectJsonLd} {#if projectJsonLdScript}
{@html `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}</script>`} {@html projectJsonLdScript}
{/if} {/if}
</svelte:head> </svelte:head>

View file

@ -85,6 +85,11 @@
: null : null
) )
const photoJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape -- Escape required for Svelte parser
photoJsonLd ? `<script type="application/ld+json">${JSON.stringify(photoJsonLd)}<\/script>` : null
)
// Parse EXIF data if available // Parse EXIF data if available
const exifData = $derived( const exifData = $derived(
photo?.exifData && typeof photo.exifData === 'object' ? photo.exifData : null photo?.exifData && typeof photo.exifData === 'object' ? photo.exifData : null
@ -357,8 +362,8 @@
<link rel="canonical" href={metaTags.other.canonical} /> <link rel="canonical" href={metaTags.other.canonical} />
<!-- JSON-LD --> <!-- JSON-LD -->
{#if photoJsonLd} {#if photoJsonLdScript}
{@html `<script type="application/ld+json">${JSON.stringify(photoJsonLd)}</script>`} {@html photoJsonLdScript}
{/if} {/if}
</svelte:head> </svelte:head>

View file

@ -56,6 +56,11 @@
}) })
: null : null
) )
const articleJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape -- Escape required for Svelte parser
articleJsonLd ? `<script type="application/ld+json">${JSON.stringify(articleJsonLd)}<\/script>` : null
)
</script> </script>
<svelte:head> <svelte:head>
@ -81,8 +86,8 @@
{/if} {/if}
<!-- JSON-LD --> <!-- JSON-LD -->
{#if articleJsonLd} {#if articleJsonLdScript}
{@html `<script type="application/ld+json">${JSON.stringify(articleJsonLd)}</script>`} {@html articleJsonLdScript}
{/if} {/if}
</svelte:head> </svelte:head>

View file

@ -51,6 +51,11 @@
: null : null
) )
const projectJsonLdScript = $derived(
// eslint-disable-next-line no-useless-escape -- Escape required for Svelte parser
projectJsonLd ? `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}<\/script>` : null
)
let headerContainer = $state<HTMLElement | null>(null) let headerContainer = $state<HTMLElement | null>(null)
// Spring with aggressive bounce settings // Spring with aggressive bounce settings
@ -111,8 +116,8 @@
{/if} {/if}
<!-- JSON-LD --> <!-- JSON-LD -->
{#if projectJsonLd} {#if projectJsonLdScript}
{@html `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}</script>`} {@html projectJsonLdScript}
{/if} {/if}
</svelte:head> </svelte:head>