Skip to content

Commit

Permalink
fix metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
biltongza committed Nov 19, 2024
1 parent b265d83 commit 02b316d
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
16 changes: 4 additions & 12 deletions frontend/src/lib/stores.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { writable } from 'svelte/store';
import { defaultMetadata } from './__consts';

let title: string = $state<string | undefined>(undefined);
let meta: Record<string, string> = $state(defaultMetadata);
let meta: Record<string, string> = $state({});

export function useTitle() {
return {
Expand All @@ -23,16 +20,11 @@ export function usePageMetadata() {
},

clear() {
meta = defaultMetadata;
meta = {};
},

push(metas: Record<string, string>) {
meta = {
...meta,
...metas
};
set(newMeta: Record<string, string>) {
meta = newMeta;
}
};
}

export const metaStore = writable<{ [key: string]: string }>(defaultMetadata);
7 changes: 4 additions & 3 deletions frontend/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@
import { defaultMetadata } from '$lib/__consts';
import Footer from '$lib/footer/footer.svelte';
import Header from '$lib/header/header.svelte';
import { metaStore, useTitle } from '$lib/stores.svelte';
import { usePageMetadata, useTitle } from '$lib/stores.svelte';
</script>

<script lang="ts">
let { children } = $props();
let title = useTitle();
const title = useTitle();
const metadata = usePageMetadata();
let pageTitle = $derived(
`${title.value ? title.value + ' - ' : ''}Logan Dam - Software Engineer, Photographer`
);
let metas = $derived(
Object.entries({ ...defaultMetadata, ...$metaStore }).map(([key, value]) => ({
Object.entries({ ...defaultMetadata, ...metadata.value }).map(([key, value]) => ({
key,
value
}))
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/blog/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
onMount(() => {
title.value = post.metadata.title;
metadata.push({
metadata.set({
'og:type': 'article',
'og:title': post.metadata.title,
'og:description': post.metadata.excerpt
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/collections/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
onMount(() => {
title.value = 'Collections';
metadata.push({
metadata.set({
'twitter:card': 'summary',
'og:type': 'article',
'og:title': 'Collections',
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/image/[imageId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
heightRatio > widthRatio
? HighResMaxDimension
: (heightRatio / widthRatio) * HighResMaxDimension;
pageMetadata.push({
pageMetadata.set({
'twitter:card': 'summary_large_image',
'og:type': 'article',
'og:image': src,
Expand Down

0 comments on commit 02b316d

Please sign in to comment.