Skip to content

Commit cb15f0c

Browse files
committed
add support for canonical urls
1 parent 3469f89 commit cb15f0c

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/Post.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {query as postRootQuery} from './PostRoot';
2929
import {query as postsRootQuery} from './PostsRoot';
3030
import CommentsIcon from './CommentsIcon';
3131
import parseMarkdown from './lib/parseMarkdown';
32+
import Head from 'next/head';
3233

3334
import type {Post_post} from './__generated__/Post_post.graphql';
3435

@@ -513,20 +514,20 @@ function postBackmatter(post) {
513514
return backmatter;
514515
}
515516

516-
export function computePostDate(post: {
517-
+body: string,
518-
+createdAt: string,
519-
}): Date {
520-
const backmatter = postBackmatter(post);
517+
export function computePostDate({backmatter, createdAt}): Date {
521518
if (backmatter.publishedDate) {
522519
return new Date(backmatter.publishedDate);
523520
}
524-
return new Date(post.createdAt);
521+
return new Date(createdAt);
525522
}
526523

527524
export const Post = ({relay, post, context}: Props) => {
528525
const environment = useRelayEnvironment();
529-
const postDate = React.useMemo(() => computePostDate(post), [post]);
526+
const backmatter = React.useMemo(() => postBackmatter(post), [post]);
527+
const postDate = React.useMemo(
528+
() => computePostDate({backmatter, createdAt: post.createdAt}),
529+
[post],
530+
);
530531
const number = post.number;
531532

532533
const {loginStatus} = React.useContext(UserContext);
@@ -573,6 +574,11 @@ export const Post = ({relay, post, context}: Props) => {
573574
const authors = post.assignees.nodes || [];
574575
return (
575576
<PostBox>
577+
<Head>
578+
{backmatter.canonical ? (
579+
<link rel="canonical" href={backmatter.canonical} />
580+
) : null}
581+
</Head>
576582
<Box pad="medium">
577583
<Heading level={1} margin="none">
578584
{context === 'details' ? (

0 commit comments

Comments
 (0)