Skip to content

Commit

Permalink
fix: content for alias path pages (tscanlin#16)
Browse files Browse the repository at this point in the history
* fix: content for alias path pages

* switch to fullUrl to fix next export
  • Loading branch information
tscanlin authored Nov 18, 2019
1 parent 1499241 commit 2c04733
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions pages/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function Index(props) {
}
`}</style>
<Page
siteTitle={`${CONFIG.siteTitle} - ${pageJson.title}`}
siteTitle={`${CONFIG.siteTitle} - ${pageJson && pageJson.title}`}
heroTitle={CONFIG.siteTitle}
description={CONFIG.description}
stylesheets={CONFIG.stylesheets}
Expand All @@ -49,7 +49,7 @@ function Index(props) {
)
}

function Body(props) {
function Body(props = {}) {
return (
<div className="content center mw6 pa3 pa4-ns">
<h1 className="mt0 lh-title">{props.title}</h1>
Expand All @@ -59,10 +59,18 @@ function Body(props) {
}

Index.getInitialProps = async function (req) {
if (req.asPath && req.asPath.indexOf('posts') !== -1) {
return import(`../content${req.asPath}.json`)
if (req.pathname === '/post') {
return import(`../content${
req.query.filePath ? req.query.filePath
.replace('content', '')
.replace('.json', '') : req.query.fullUrl
}.json`)
.then((d) => {
return { pageJson: d.default }
return {
pageJson: d.default
}
}).catch((e) => {
console.log(e)
})
}
return {}
Expand Down

0 comments on commit 2c04733

Please sign in to comment.