Skip to content

Commit

Permalink
fix(www): fallback to hostname of canonicalLink if publishedAt is not…
Browse files Browse the repository at this point in the history
… specified (#10855)
  • Loading branch information
ivorpad authored and pieh committed Jan 8, 2019
1 parent 1aa27eb commit c8128db
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
13 changes: 12 additions & 1 deletion www/gatsby-node.js
Expand Up @@ -470,14 +470,25 @@ exports.onCreateNode = ({ node, actions, getNode, reporter }) => {
slug = `/${parsedFilePath.dir}/`
}

// Set released status for blog posts.
// Set released status and `published at` for blog posts.
if (_.includes(parsedFilePath.dir, `blog`)) {
let released = false
const date = _.get(node, `frontmatter.date`)
if (date) {
released = moment().isSameOrAfter(moment.utc(date))
}
createNodeField({ node, name: `released`, value: released })

const canonicalLink = _.get(node, `frontmatter.canonicalLink`)
const publishedAt = _.get(node, `frontmatter.publishedAt`)

createNodeField({
node,
name: `publishedAt`,
value: canonicalLink
? publishedAt || url.parse(canonicalLink).hostname
: null,
})
}
}
// Add slugs for package READMEs.
Expand Down
4 changes: 2 additions & 2 deletions www/src/templates/template-blog-post.js
Expand Up @@ -213,7 +213,7 @@ class BlogPostTemplate extends React.Component {
(originally published at
{` `}
<a href={post.frontmatter.canonicalLink}>
{post.frontmatter.publishedAt}
{this.props.data.markdownRemark.fields.publishedAt}
</a>
)
</span>
Expand Down Expand Up @@ -344,14 +344,14 @@ export const pageQuery = graphql`
timeToRead
fields {
slug
publishedAt
}
frontmatter {
title
excerpt
date(formatString: "MMMM Do YYYY")
rawDate: date
canonicalLink
publishedAt
tags
image {
childImageSharp {
Expand Down

0 comments on commit c8128db

Please sign in to comment.