diff --git a/src/routes/+layout.js b/src/routes/+layout.js index d99cd63..dabae08 100644 --- a/src/routes/+layout.js +++ b/src/routes/+layout.js @@ -19,6 +19,7 @@ export async function load({ fetch, data, url }) { return { seoData: remoteSeoData, + pathname: url.pathname, ...data, }; } diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index e2b069e..e7fb8cc 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -53,29 +53,38 @@ publishDate: undefined }) + const resetSeo = () => { + seoInfo.set({ + title: data.MainInfo.name, + description: undefined, + url: $page.url.href, + siteName: data.MainInfo.name, + imageUrl: undefined, + type: undefined, + publishDate: undefined + }) + } + + resetSeo() + $: if (data.seoData) { - seoInfo.update((seoInfo) => { - seoInfo.title = data.seoData.title - seoInfo.description = data.seoData.description - seoInfo.imageUrl = data.seoData.image.url - seoInfo.url = $page.url.href - seoInfo.type = undefined - seoInfo.publishDate = undefined - - return seoInfo + seoInfo.update((seo) => { + seo.title = data.seoData.title + seo.description = data.seoData.description + seo.imageUrl = data.seoData.image.url + seo.url = $page.url.href + seo.type = undefined + seo.publishDate = undefined + + if (data.pathname.startsWith("/news/")) { + seo.type = "article" + seo.publishDate = data.seoData.lastUpdate + } + + return seo }) } else { - if (!$page.url.pathname.startsWith("/news/")) { - seoInfo.set({ - title: data.MainInfo.name, - description: undefined, - url: $page.url.href, - siteName: data.MainInfo.name, - imageUrl: undefined, - type: undefined, - publishDate: undefined - }) - } + resetSeo() } diff --git a/src/routes/news/[id]/+page.svelte b/src/routes/news/[id]/+page.svelte index 213d0e8..0dd5b67 100644 --- a/src/routes/news/[id]/+page.svelte +++ b/src/routes/news/[id]/+page.svelte @@ -2,7 +2,6 @@ import { setLayout, tertiaryLayout, tertiaryLayoutDark } from "$lib/setLayout"; import { env } from "$env/dynamic/public"; import BlockRenderer from "$lib/BlockRenderer.svelte"; - import { seoInfo } from "$lib/seoInfo"; import { onMount } from "svelte"; import DarkModeIcon from "$lib/DarkModeIcon.svelte"; import LightModeIcon from "$lib/LightModeIcon.svelte"; @@ -13,15 +12,6 @@ export let data; - seoInfo.update(seoInfo => { - seoInfo.title = data.News.title - seoInfo.description = data.News.description - seoInfo.type = "article" - seoInfo.publishDate = data.News.publishDate - - return seoInfo - }) - let mode = "light" let buttonColor let textColor