Skip to content

Commit 5550f11

Browse files
committed
feat: 🌐 add schema org for blog post
1 parent 1087196 commit 5550f11

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

src/components/seo.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,16 @@ let SEO = ({ title, isBlogPost, schemaOrgItems = () => [] }) => (
5555

5656
{/* Schema.org tags */}
5757
<script type="application/ld+json">
58-
{JSON.stringify([baseSchema, ...schemaOrgItems({ url })])}
58+
{JSON.stringify([
59+
baseSchema,
60+
...schemaOrgItems({
61+
url,
62+
author: {
63+
'@type': 'Person',
64+
name: 'Nikita Kirsanov',
65+
},
66+
}),
67+
])}
5968
</script>
6069
</Helmet>
6170
)

src/pages/portfolio.js

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ let formatDate = format('MMMM, yyyy')
1313
let isMobile =
1414
typeof window !== 'undefined' && typeof window.orientation !== 'undefined'
1515

16-
let buildSchemaOrg = projects => () => [
16+
let buildSchemaOrg = projects => ({ author }) => [
1717
{
1818
'@context': 'http://schema.org',
1919
'@type': 'CollectionPage',
@@ -22,26 +22,19 @@ let buildSchemaOrg = projects => () => [
2222
name: 'Projects',
2323
itemListOrder: 'http://schema.org/ItemListOrderDescending',
2424
itemListElement: projects.map(
25-
({ name, url, description, technologies, customer }) => {
26-
let author = {
27-
'@type': 'Person',
28-
name: 'Nikita Kirsanov',
29-
}
30-
31-
return {
32-
'@type': url ? 'WebSite' : 'CreativeWork',
33-
name,
34-
url: url || undefined,
35-
description: description || undefined,
36-
author,
37-
creator: author,
38-
keywords: technologies.join(','),
39-
funder: {
40-
'@type': 'Organization',
41-
name: customer,
42-
},
43-
}
44-
}
25+
({ name, url, description, technologies, customer }) => ({
26+
'@type': url ? 'WebSite' : 'CreativeWork',
27+
name,
28+
url: url || undefined,
29+
description: description || undefined,
30+
author,
31+
creator: author,
32+
keywords: technologies.join(','),
33+
funder: {
34+
'@type': 'Organization',
35+
name: customer,
36+
},
37+
})
4538
),
4639
},
4740
},

src/templates/blog-post.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,36 @@ import { differenceInWeeks, format } from 'date-fns/fp'
44
import { Box, Flex } from '@rebass/grid'
55

66
import Tag from '../components/tag'
7+
import SEO from '../components/seo'
78

89
let formatDate = format('MMMM dd, yyyy')
910

11+
let buildSchemaOrg = ({ title, createdAt, updatedAt, tags }) => ({
12+
author,
13+
}) => [
14+
{
15+
'@context': 'http://schema.org',
16+
'@type': 'BlogPosting',
17+
dateModified: updatedAt,
18+
datePublished: createdAt,
19+
headline: title,
20+
keywords: tags.join(', '),
21+
author,
22+
},
23+
]
24+
1025
let BlogPost = ({
1126
data: {
1227
post: { title, createdAt, updatedAt, tags, content },
1328
},
1429
}) => (
1530
<>
31+
<SEO
32+
title={title}
33+
isBlogPost
34+
schemaOrgItems={buildSchemaOrg({ title, createdAt, updatedAt, tags })}
35+
/>
36+
1637
<h1>{title}</h1>
1738

1839
<small>{formatDate(createdAt)}</small>

0 commit comments

Comments
 (0)