Skip to content

Commit

Permalink
Factor out getBlogPostUrl
Browse files Browse the repository at this point in the history
  • Loading branch information
ianobermiller committed Sep 28, 2019
1 parent 153204f commit 01cc97a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 3 additions & 5 deletions gatsby-config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const {getBlogPostUrl} = require('./src/utils');

module.exports = {
siteMetadata: {
title: 'Ian Obermiller',
Expand Down Expand Up @@ -27,11 +29,7 @@ module.exports = {
return Object.assign({}, edge.node.frontmatter, {
description: edge.node.frontmatter.title,
date: edge.node.frontmatter.date,
url:
site.siteMetadata.siteUrl +
edge.node.fileAbsolutePath
.replace(/.*\/blog\//, '/blog/')
.replace('.mdx', ''),
url: site.siteMetadata.siteUrl + getBlogPostUrl(edge.node),
});
});
},
Expand Down
5 changes: 2 additions & 3 deletions src/pages/blog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import React, {ReactElement} from 'react';
import DateText from '../../templates/DateText';
import Layout from '../../templates/Layout';
import {max as maxDate, differenceInYears, min as minDate} from 'date-fns';
import {getBlogPostUrl} from '../../utils';

// Please note that you can use https://github.com/dotansimha/graphql-code-generator
// to generate all types from graphQL schema
Expand Down Expand Up @@ -42,9 +43,7 @@ export default function BlogIndex({data}: Props): ReactElement {

return {
id: node.id,
url: node.fileAbsolutePath
.replace(/.*\/blog\//, '/blog/')
.replace('.mdx', ''),
url: getBlogPostUrl(node),
title: node.frontmatter.title,
date,
dateString,
Expand Down
9 changes: 9 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
function getBlogPostUrl(node) {
return node.fileAbsolutePath
.replace(/.*\/blog\//, '/blog/')
.replace('.mdx', '');
}

module.exports = {
getBlogPostUrl,
};

0 comments on commit 01cc97a

Please sign in to comment.