Skip to content

Commit

Permalink
SEO metadata improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
flatpickles committed Nov 18, 2023
1 parent 993dfca commit d4eecb9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sketchbook2",
"version": "0.2.3",
"version": "0.2.4",
"private": true,
"scripts": {
"dev": "vite dev",
Expand Down
22 changes: 22 additions & 0 deletions src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,30 @@
export let data: PageData;
const ogMeta = OGContentGen.top(data.requestUrl);
// Generate schema.org markup for the project
$: schemaMarkup = {
'@context': 'http://schema.org',
'@type': 'CollectionPage',
'name': `${ogMeta.title}`
} as Record<string, string>;
$: if (ogMeta.description) {
schemaMarkup['description'] = ogMeta.description;
}
$: if (ogMeta.author) {
schemaMarkup['creator'] = ogMeta.author;
}
</script>

<svelte:head>
<!-- Metadata -->
<title>{content.title}</title>
{#if ogMeta.description}
<meta name="description" content={ogMeta.description} />
{/if}
<link rel="canonical" href={ogMeta.url} />

<!-- Open Graph / Facebook / Twitter -->
<meta property="og:title" content={ogMeta.title} />
<meta name="twitter:title" content={ogMeta.title} />
<meta property="og:site_name" content={ogMeta.siteName} />
Expand All @@ -29,4 +48,7 @@
{:else}
<meta name="twitter:card" content="summary" />
{/if}

<!-- Schema.org -->
{@html `<script type="application/ld+json">${JSON.stringify(schemaMarkup)}</script>`}
</svelte:head>
25 changes: 25 additions & 0 deletions src/routes/[key]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,33 @@
export let data: PageData;
$: ogMeta = OGContentGen.project(data.requestUrl, data.projectKey, data.projectConfig);
// Generate schema.org markup for the project
$: schemaMarkup = {
'@context': 'http://schema.org',
'@type': 'CreativeWork',
'name': `${ogMeta.title}`
} as Record<string, string>;
$: if (ogMeta.description) {
schemaMarkup['description'] = ogMeta.description;
}
$: if (data.projectConfig.date) {
schemaMarkup['dateCreated'] = data.projectConfig.date.toISOString().split('T')[0];
}
$: if (ogMeta.author) {
schemaMarkup['creator'] = ogMeta.author;
}
</script>

<svelte:head>
<!-- Metadata -->
<title>{data.projectConfig.title}</title>
{#if ogMeta.description}
<meta name="description" content={ogMeta.description} />
{/if}
<link rel="canonical" href={ogMeta.url} />

<!-- Open Graph / Facebook / Twitter -->
<meta property="og:title" content={ogMeta.title} />
<meta name="twitter:title" content={ogMeta.title} />
<meta property="og:site_name" content={ogMeta.siteName} />
Expand All @@ -35,6 +57,9 @@
{#if ogMeta.publishedTime}
<meta property="article:published_time" content={ogMeta.publishedTime} />
{/if}

<!-- Schema.org -->
{@html `<script type="application/ld+json">${JSON.stringify(schemaMarkup)}</script>`}
</svelte:head>

{#if data.projectTuple}
Expand Down

0 comments on commit d4eecb9

Please sign in to comment.