Skip to content

Commit

Permalink
Fix news OpenGraph not working
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaGanchev committed Sep 26, 2023
1 parent 5086df2 commit d10de3e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/routes/+layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function load({ fetch, data, url }) {

return {
seoData: remoteSeoData,
pathname: url.pathname,
...data,
};
}
49 changes: 29 additions & 20 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
</script>

Expand Down
10 changes: 0 additions & 10 deletions src/routes/news/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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
Expand Down

0 comments on commit d10de3e

Please sign in to comment.