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:
parent
d60eba6e90
commit
ec0431d2b0
6 changed files with 41 additions and 11 deletions
|
|
@ -26,11 +26,16 @@
|
|||
]
|
||||
})
|
||||
)
|
||||
|
||||
const personJsonLdScript = $derived(
|
||||
// eslint-disable-next-line no-useless-escape
|
||||
`<script type="application/ld+json">${JSON.stringify(personJsonLd)}<\/script>`
|
||||
)
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<!-- Site-wide JSON-LD -->
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(personJsonLd)}</script>`}
|
||||
{@html personJsonLdScript}
|
||||
</svelte:head>
|
||||
|
||||
<div class="layout-wrapper" class:admin-route={isAdminRoute}>
|
||||
|
|
|
|||
|
|
@ -116,6 +116,11 @@
|
|||
|
||||
// Generate image gallery JSON-LD
|
||||
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>
|
||||
|
||||
<svelte:head>
|
||||
|
|
@ -136,8 +141,8 @@
|
|||
<link rel="canonical" href={metaTags.other.canonical} />
|
||||
|
||||
<!-- JSON-LD -->
|
||||
{#if galleryJsonLd}
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(galleryJsonLd)}</script>`}
|
||||
{#if galleryJsonLdScript}
|
||||
{@html galleryJsonLdScript}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,11 @@
|
|||
})
|
||||
: 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>
|
||||
|
||||
<svelte:head>
|
||||
|
|
@ -73,8 +78,8 @@
|
|||
{/if}
|
||||
|
||||
<!-- JSON-LD -->
|
||||
{#if projectJsonLd}
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}</script>`}
|
||||
{#if projectJsonLdScript}
|
||||
{@html projectJsonLdScript}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,11 @@
|
|||
: 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
|
||||
const exifData = $derived(
|
||||
photo?.exifData && typeof photo.exifData === 'object' ? photo.exifData : null
|
||||
|
|
@ -357,8 +362,8 @@
|
|||
<link rel="canonical" href={metaTags.other.canonical} />
|
||||
|
||||
<!-- JSON-LD -->
|
||||
{#if photoJsonLd}
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(photoJsonLd)}</script>`}
|
||||
{#if photoJsonLdScript}
|
||||
{@html photoJsonLdScript}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,11 @@
|
|||
})
|
||||
: 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>
|
||||
|
||||
<svelte:head>
|
||||
|
|
@ -81,8 +86,8 @@
|
|||
{/if}
|
||||
|
||||
<!-- JSON-LD -->
|
||||
{#if articleJsonLd}
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(articleJsonLd)}</script>`}
|
||||
{#if articleJsonLdScript}
|
||||
{@html articleJsonLdScript}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@
|
|||
: 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)
|
||||
|
||||
// Spring with aggressive bounce settings
|
||||
|
|
@ -111,8 +116,8 @@
|
|||
{/if}
|
||||
|
||||
<!-- JSON-LD -->
|
||||
{#if projectJsonLd}
|
||||
{@html `<script type="application/ld+json">${JSON.stringify(projectJsonLd)}</script>`}
|
||||
{#if projectJsonLdScript}
|
||||
{@html projectJsonLdScript}
|
||||
{/if}
|
||||
</svelte:head>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue