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

add meta tags for SEO #1136

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions src/components/HamburgerIcon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import React from 'react'

import styles from './styles.module.css'

interface IHamburgetProps {
interface IHamburgerProps {
opened?: boolean
}

const HamburgerIcon: React.FC<IHamburgetProps> = ({ opened }) => (
const HamburgerIcon: React.FC<IHamburgerProps> = ({ opened }) => (
<div className={cn(styles.wrapper, opened && styles.opened)}>
<div className={cn(styles.line, styles.first)} />
<div className={cn(styles.line, styles.second)} />
Expand Down
58 changes: 34 additions & 24 deletions src/components/Page/DefaultSEO/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import React from 'react'
import ReactHelmet from 'react-helmet'
import Helmet from 'react-helmet'

import { MetaProps } from '../../SEO'
import { IPaginatorPageInfo } from '../../Paginator'
import getSiteMeta from '../../../queries/siteMeta'

interface IDefaultSEOProps {
pageInfo?: IPaginatorPageInfo
pathname: string
}

const DefaultSEO: React.FC<IDefaultSEOProps> = ({ pageInfo }) => {
const metaImage = {
src: '/social-share.png',
width: '1200',
height: '630'
}

const DefaultSEO: React.SFC<IDefaultSEOProps> = ({ pathname }) => {
const siteMeta = getSiteMeta()
const metaTitle =
pageInfo && pageInfo.currentPage > 1
? `${siteMeta.title} page ${pageInfo.currentPage}`
: siteMeta.title
const metaTitle = siteMeta.title
const metaDescription = siteMeta.description
const metaKeywords = siteMeta.keywords
const metaImage = '/social-share.png'
const fullUrl = siteMeta.siteUrl + pathname

const meta: MetaProps[] = [
{
Expand All @@ -28,6 +30,10 @@ const DefaultSEO: React.FC<IDefaultSEOProps> = ({ pageInfo }) => {
name: 'keywords',
content: metaKeywords
},
{
property: 'og:url',
content: fullUrl
},
{
property: 'og:title',
content: metaTitle
Expand All @@ -42,11 +48,23 @@ const DefaultSEO: React.FC<IDefaultSEOProps> = ({ pageInfo }) => {
},
{
property: 'og:image',
content: metaImage
content: metaImage.src
},
{
property: 'og:image:width',
content: metaImage.width
},
{
property: 'og:image:height',
content: metaImage.height
},
{
property: 'og:image:secure_url',
content: metaImage
content: metaImage.src
},
{
name: 'twitter:site',
content: '@dvcORG'
},
{
name: 'twitter:card',
Expand All @@ -62,12 +80,12 @@ const DefaultSEO: React.FC<IDefaultSEOProps> = ({ pageInfo }) => {
},
{
name: 'twitter:image',
content: encodeURI(`${siteMeta.siteUrl}${metaImage}`)
content: encodeURI(`${siteMeta.siteUrl}${metaImage.src}`)
}
]

return (
<ReactHelmet
<Helmet
htmlAttributes={{
lang: 'en'
}}
Expand All @@ -76,21 +94,13 @@ const DefaultSEO: React.FC<IDefaultSEOProps> = ({ pageInfo }) => {
meta={meta}
link={[
{
rel: 'shortcut icon',
rel: 'icon',
type: 'image/vnd.microsoft.icon',
Copy link
Member

Choose a reason for hiding this comment

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

is this type required? legacy?

href: '/favicon.ico'
},
{
rel: 'icon',
Copy link
Member

Choose a reason for hiding this comment

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

why are we removing these?

type: 'image/png',
href: '/favicon-32x32.png',
sizes: '32x32'
},
{
rel: 'icon',
type: 'image/png',
href: '/favicon-16x16.png',
sizes: '16x16'
rel: 'canonical',
href: fullUrl
}
]}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const Page: React.FC<IPageProps> = props => {

return (
<>
<DefaultSEO />
<DefaultSEO pathname={props.location.pathname} />
<LayoutComponent {...props} />
</>
)
Expand Down
22 changes: 18 additions & 4 deletions src/components/SEO/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ interface ISEOProps {
defaultMetaTitle?: boolean
description?: string
keywords?: string
image?: string
image?: {
src: string
presentationWidth: number
presentationHeight: number
}
meta?: MetaProps[]
pageInfo?: IPaginatorPageInfo
children?: React.ReactNode
Expand Down Expand Up @@ -72,18 +76,28 @@ const SEO: React.FC<ISEOProps> = ({
}

if (image) {
const imageUrl = siteMeta.siteUrl + image.src

prebuildMeta.push(
{
property: 'og:image',
content: image
content: imageUrl
},
{
property: 'og:image:secure_url',
content: image
content: imageUrl
},
{
property: 'og:image:width',
content: String(image.presentationWidth)
},
{
property: 'og:image:height',
content: String(image.presentationHeight)
},
{
name: 'twitter:image',
content: encodeURI(`${siteMeta.siteUrl}${image}`)
Copy link
Member

Choose a reason for hiding this comment

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

was encodeURI actually needed? cc @iAdramelk ?

Copy link
Contributor

Choose a reason for hiding this comment

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

To be hones I'm not sure. The one who originally added it to the blog was you https://github.com/iterative/blog/commit/3b5c975363fd4f86ef66dd102a2a130759df8fcb . I think then that you where fixing some kind of bug that we have without escaping, but if not, I'm not sure that we need it.

Copy link
Member

Choose a reason for hiding this comment

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

Good question. I see that I was solving a different problem in the first place - absolute URL vs relative one. Don't remember at all why did I put encodeURI to be honest.

content: imageUrl
}
)
}
Expand Down
16 changes: 6 additions & 10 deletions src/templates/blog-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import SEO from '../components/SEO'
import Post from '../components/Blog/Post'

interface IFluidObject extends FluidObject {
presentationWidth?: number
presentationWidth: number
presentationHeight: number
}

export interface IGatsbyImageProps extends GatsbyImageProps {
Expand Down Expand Up @@ -67,24 +68,17 @@ interface IBlogPostPageProps {
data: {
markdownRemark: IBlogPostData
}
pageContext: {
next: IBlogPostData
previous: IBlogPostData
}
}

const BlogPostPage: React.FC<IBlogPostPageProps> = ({ data }) => {
const BlogPostPage: React.SFC<IBlogPostPageProps> = ({ data }) => {
Copy link
Member

Choose a reason for hiding this comment

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

SFC is deprecated?

const post = data.markdownRemark

return (
<>
<SEO
title={post.frontmatter.title}
description={post.frontmatter.description}
image={
post.frontmatter.picture &&
post.frontmatter.picture.childImageSharp.fluid.src
}
image={post.frontmatter.picture?.childImageSharp?.fluid}
/>
<Post {...post} />
</>
Expand Down Expand Up @@ -128,7 +122,9 @@ export const pageQuery = graphql`
childImageSharp {
fluid(maxWidth: 850) {
...GatsbyImageSharpFluid_withWebp
src
presentationWidth
presentationHeight
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions static/robots.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Sitemap: https://blog.dvc.org/sitemap.xml

User-agent: *
Disallow: