This commit is contained in:
Jon McClure 2022-08-26 13:50:26 +01:00
parent 9addc5d346
commit a0ab866ee5
4 changed files with 19 additions and 7 deletions

View file

@ -10,7 +10,7 @@
import {
withComponentDocs,
withStoryDocs,
withStoryDocs
} from '$lib/docs/utils/withParams.js';
const meta = {
@ -30,6 +30,7 @@
<Story
name="Default"
args="{{
origin: 'https://graphics.reuters.com',
url: new URL('https://graphics.reuters.com/hello-world/'),
publishTime: new Date('2020-09-15').toISOString(),
}}"
@ -38,6 +39,7 @@
<Story
name="🚀 QUICKIT"
args="{{
origin: 'https://graphics.reuters.com',
url: new URL('https://graphics.reuters.com/hello-world/'),
publishTime: new Date('2020-09-15').toISOString(),
}}"

View file

@ -2,6 +2,12 @@
import analytics from './analytics';
import publisherTags from './publisherTags';
/**
* [URL origin](https://developer.mozilla.org/en-US/docs/Web/API/URL/origin) for the page.
* @required
* @type {string}
*/
export let origin: string = '';
/**
* [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object for the page.
* @required
@ -69,9 +75,11 @@
*/
export let includeAnalytics: boolean = false;
$: canonicalUrl = origin + url.pathname;
// Only fire analytics on prod sites
if (typeof window !== 'undefined' && includeAnalytics) {
analytics(url, seoTitle);
analytics(canonicalUrl, seoTitle);
publisherTags();
}
@ -93,10 +101,10 @@
'@context': 'http://schema.org',
'@type': 'NewsArticle',
headline: seoTitle,
url: url.href,
url: canonicalUrl,
mainEntityOfPage: {
'@type': 'WebPage',
'@id': url.href,
'@id': canonicalUrl,
},
thumbnailUrl: shareImgPath,
image: [
@ -129,7 +137,7 @@
<html lang="{lang}"></html>
<title>{seoTitle}</title>
<meta name="description" content="{seoDescription}" />
<link rel="canonical" href="{url.href}" />
<link rel="canonical" href="{canonicalUrl}" />
<link
rel="shortcut icon"
type="image/x-icon"
@ -154,7 +162,7 @@
sizes="96x96"
/>
<meta property="og:url" content="{url.href}" />
<meta property="og:url" content="{canonicalUrl}" />
<meta property="og:type" content="article" />
<meta property="og:title" content="{shareTitle}" itemprop="name" />
<meta
@ -172,7 +180,7 @@
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@ReutersGraphics" />
<meta name="twitter:creator" content="@ReutersGraphics" />
<meta name="twitter:domain" content="{url.origin}" />
<meta name="twitter:domain" content="{origin}" />
<meta name="twitter:title" content="{shareTitle}" />
<meta name="twitter:description" content="{shareDescription}" />
<meta name="twitter:image:src" content="{shareImgPath}" />

View file

@ -6,6 +6,7 @@ The `SEO` component adds essential metadata to published pages.
</script>
<SEO
origin="https://graphics.reuters.com"
url={new URL('https://graphics.reuters.com/world-coronavirus-tracker-and-maps/')}
seoTitle="A title for Google"
seoDescription="A description for Google"

View file

@ -13,6 +13,7 @@ Most of the fields are filled in by other sources, like your Google Doc and pack
<SEO
lang="en"
origin={import.meta.env.BASE_URL}
url={$page.url}
seoTitle="{content.SEOTitle}"
seoDescription="{content.SEODescription}"