Created
June 26, 2019 17:46
-
-
Save sumitkharche/a7caf712e4cb0b0fd2a3a8e1eaf70b05 to your computer and use it in GitHub Desktop.
static.config.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import path from 'path' | |
import axios from 'axios' | |
import config from './config' | |
const gph_query = `{ | |
getObjects(bucket_slug: "${config.bucket.slug}", input: { | |
type: "posts", | |
limit: 20, | |
read_key: "${config.bucket.read_key}", | |
}) { | |
_id | |
type_slug | |
slug | |
title | |
metadata | |
created_at | |
} | |
}`; | |
export default { | |
getRoutes: async () => { | |
const posts = await axios.post('https://graphql.cosmicjs.com/v1', { | |
query:gph_query | |
}) | |
.then(function (response) { | |
return response.data.data.getObjects | |
}) | |
return [ | |
{ | |
path: '/', | |
getData: () => ({ | |
posts, | |
}), | |
children: posts.map(post => ({ | |
path: `/post/${post._id}`, | |
template: 'src/pages/post', | |
getData: () => ({ | |
post, | |
}), | |
})), | |
}, | |
] | |
}, | |
plugins: [ | |
[ | |
require.resolve('react-static-plugin-source-filesystem'), | |
{ | |
location: path.resolve('./src/pages'), | |
}, | |
], | |
require.resolve('react-static-plugin-reach-router'), | |
require.resolve('react-static-plugin-sitemap'), | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment