Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more detail about authors for SEO #550

Merged
merged 6 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions shared.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { htmlToText } from 'html-to-text';
import { features } from './src/components/DeploymentOptionsPage/shared';
import { Author } from './src/templates/author/shared';

export const webinarsUrl =
'https://try.estuary.dev/webinar-estuary101-ondemand';
Expand Down Expand Up @@ -35,6 +37,48 @@ export const estuaryAddress = {
export const getAuthorPathBySlug = (slug: string) =>
`/author/${slug.toLowerCase()}`;

export const getAuthorSeoJson = (author: Author, siteUrl: string) => {
const authorBio = author.bio.data.bio
? htmlToText(author.bio.data.bio, { wordwrap: false })
: 'Blog post author.';

const sameAs: string[] = [];

if (author.socials.linked_in) {
sameAs.push(author.socials.linked_in);
}

if (author.socials.twitter) {
sameAs.push(author.socials.twitter);
}

if (author.socials.other) {
sameAs.push(author.socials.other);
}

return {
'@context': 'https://schema.org',
'@type': 'Person',
'name': author.name,
'url': `${siteUrl}${getAuthorPathBySlug(author.slug)}/`,
'jobTitle': author.role,
'description': authorBio,
'worksFor': {
'@type': 'Organization',
'name': 'Estuary',
'url': 'https://estuary.dev/',
},
sameAs,
'image': author.picture?.localFile?.childImageSharp?.fixedImg?.images
?.fallback?.src
? {
'@type': 'ImageObject',
'url': `${siteUrl}${author.picture.localFile.childImageSharp.fixedImg.images.fallback.src}`,
}
: undefined,
};
};

export const getComparisonSlug = (
xVendorSlugKey: string,
yVendorSlugKey: string
Expand Down
2 changes: 1 addition & 1 deletion src/components/SocialLinks/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const iconColor = '#47506D';

interface SocialLinks {
socialLinks: {
linkedIn: string;
linked_in: string;
twitter: string;
other: string;
};
Expand Down
29 changes: 19 additions & 10 deletions src/templates/author/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { graphql } from 'gatsby';
import React from 'react';
import { htmlToText } from 'html-to-text';
import Layout from '../../components/Layout';
import Seo from '../../components/seo';
import { getAuthorSeoJson } from '../../../shared';
import SectionOne from './SectionOne';
import { Author } from './shared';
import SectionTwo from './SectionTwo';
Expand Down Expand Up @@ -43,23 +43,31 @@ export default AuthorPage;

export const Head = ({
data: {
author: { name, bio },
author,
site: {
siteMetadata: { siteUrl },
},
},
}) => {
const seoJson = getAuthorSeoJson(author, siteUrl);

return (
<Seo
title={name}
description={
bio.data.bio
? htmlToText(bio.data.bio, { wordwrap: false })
: 'Blog post author.'
}
/>
<>
<Seo title={author.name} description={seoJson.description} />
<script type="application/ld+json">
{JSON.stringify(seoJson)}
</script>
</>
);
};

export const pageQuery = graphql`
query AuthorById($id: String!) {
site {
siteMetadata {
siteUrl
}
}
author: strapiAuthor(id: { eq: $id }) {
id
name: Name
Expand All @@ -71,6 +79,7 @@ export const pageQuery = graphql`
height: 208
placeholder: BLURRED
)
fixedImg: gatsbyImageData(layout: FIXED, width: 60)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/templates/author/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export interface Author {
picture: any;
slug: string;
socials: {
linkedIn: string;
linked_in: string;
twitter: string;
other: string;
};
Expand Down
216 changes: 114 additions & 102 deletions src/templates/blog-post/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import Seo from '../../components/seo';
import logoUrl from '../../images/combination-mark__multi-blue.png';
import { costPerGB } from '../../utils';
import ReadingTimeIcon from '../../svgs/time.svg';
import { dashboardRegisterUrl, getAuthorPathBySlug } from '../../../shared';
import {
dashboardRegisterUrl,
getAuthorPathBySlug,
getAuthorSeoJson,
} from '../../../shared';
import Avatar from '../../components/Avatar';
import SocialLinks from '../../components/SocialLinks';
import BlogBanner from '../../components/BlogBanner';
Expand Down Expand Up @@ -203,113 +207,126 @@ const BlogPostTemplate = ({ data: { post } }) => {
</div>
</section>
) : null}
<section className={nextStepsAndAboutAuthorSection}>
{/* <div className={nextSteps}>
{post?.authors.length >= 1 ? (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this condition to show the author section only if the blog post has at least one author.

It solves this issue:
image

<section className={nextStepsAndAboutAuthorSection}>
{/* <div className={nextSteps}>
<h3>Next steps</h3>
<NextStepsLink href="">Read about Lorem ipsum dolor sit amet, consectetur</NextStepsLink>
<NextStepsLink href="">Learn about Lorem ipsum dolor sit amet</NextStepsLink>
<NextStepsLink href="">Lorem ipsum dolor sit amet</NextStepsLink>
</div> */}

<div className={aboutAuthor}>
<h2>
{post?.authors.length === 1
? hasAtLeastOneBio
? 'About the author'
: 'Author'
: hasAtLeastOneBio
? 'About the authors'
: 'Authors'}
</h2>
{post?.authors?.map((author, index) => {
const authorImage =
author?.picture &&
getImage(
author.picture.localFile.childImageSharp
.gatsbyImageData
);
<div className={aboutAuthor}>
<h2>
{post?.authors.length === 1
? hasAtLeastOneBio
? 'About the author'
: 'Author'
: hasAtLeastOneBio
? 'About the authors'
: 'Authors'}
</h2>
{post?.authors?.map((author, index) => {
const authorImage =
author?.picture &&
getImage(
author.picture.localFile.childImageSharp
.gatsbyImageData
);

const authorBio = author?.bio.data.bio;
const authorBio = author?.bio.data.bio;

const authorSocialLinks = author?.socials;
const authorSocialLinks = author?.socials;

return (
<>
<div key={index} className={authorInfo}>
<Link
to={getAuthorPathBySlug(
author?.slug
)}
className={authorMainInfoContainer}
>
<div
return (
<>
<div key={index} className={authorInfo}>
<Link
to={getAuthorPathBySlug(
author?.slug
)}
className={
authorAvatarContainer
authorMainInfoContainer
}
>
<Avatar
image={authorImage}
alt={`Picture of ${author?.name}`}
name={author.name}
loading="lazy"
size={60}
/>
</div>
<div className={authorNameAndRole}>
{author?.name ? (
<span
className={authorName}
>
{author.name}
</span>
) : null}
{author?.role ? (
<span
className={authorRole}
>
{author.role}
</span>
) : null}
</div>
</Link>
{authorSocialLinks ? (
<>
<Divider
orientation="vertical"
variant="middle"
flexItem
sx={{
minHeight: '57px',
width: '1px',
borderColor: '#d7dce5',
margin: '0 30px 0 20px',
[theme.breakpoints.down(
520
)]: {
display: 'none',
},
}}
/>
<SocialLinks
socialLinks={
authorSocialLinks
<div
className={
authorAvatarContainer
}
/>
</>
>
<Avatar
image={authorImage}
alt={`Picture of ${author?.name}`}
name={author.name}
loading="lazy"
size={60}
/>
</div>
<div
className={
authorNameAndRole
}
>
{author?.name ? (
<span
className={
authorName
}
>
{author.name}
</span>
) : null}
{author?.role ? (
<span
className={
authorRole
}
>
{author.role}
</span>
) : null}
</div>
</Link>
{authorSocialLinks ? (
<>
<Divider
orientation="vertical"
variant="middle"
flexItem
sx={{
minHeight: '57px',
width: '1px',
borderColor:
'#d7dce5',
margin: '0 30px 0 20px',
[theme.breakpoints.down(
520
)]: {
display: 'none',
},
}}
/>
<SocialLinks
socialLinks={
authorSocialLinks
}
/>
</>
) : null}
</div>
{authorBio ? (
<div
dangerouslySetInnerHTML={{
__html: author.bio.data.bio,
}}
/>
) : null}
</div>
{authorBio ? (
<div
dangerouslySetInnerHTML={{
__html: author.bio.data.bio,
}}
/>
) : null}
</>
);
})}
</div>
</section>
</>
);
})}
</div>
</section>
) : null}
<section className={popularArticlesWrapper}>
<h2>Popular Articles</h2>
<PopularArticles />
Expand Down Expand Up @@ -391,14 +408,9 @@ export const Head = ({
},
},
}) => {
const mappedAuthors = post.authors.map((author) => ({
name: author.name,
url: author.link,
image: author.picture && {
'@type': 'ImageObject',
'url': `${siteUrl}/${author.picture.localFile.childImageSharp.fixedImg.gatsbyImageData}`,
},
}));
const mappedAuthors = post.authors.map((author) =>
getAuthorSeoJson(author, siteUrl)
);

const postTags = post.tags
.filter((tag) => tag.type === 'tag')
Expand Down
Loading