diff --git a/www/src/templates/template-blog-post.js b/www/src/templates/template-blog-post.js index 70612df84c390..993ff0b7275b1 100644 --- a/www/src/templates/template-blog-post.js +++ b/www/src/templates/template-blog-post.js @@ -24,6 +24,25 @@ const renderAst = new rehypeReact({ }, }).Compiler +function extractHostname(url) { + var hostname; + //find & remove protocol (http, ftp, etc.) and get hostname + + if (url.indexOf("//") > -1) { + hostname = url.split('/')[2]; + } + else { + hostname = url.split('/')[0]; + } + + //find & remove port number + hostname = hostname.split(':')[0]; + //find & remove "?" + hostname = hostname.split('?')[0]; + + return hostname; +} + class BlogPostTemplate extends React.Component { render() { const post = this.props.data.markdownRemark @@ -213,7 +232,9 @@ class BlogPostTemplate extends React.Component { (originally published at {` `} - {post.frontmatter.publishedAt} + {post.frontmatter.publishedAt + ? post.frontmatter.publishedAt + : extractHostname(post.frontmatter.canonicalLink)} )