Skip to content

Instantly share code, notes, and snippets.

@sumitkharche
Created June 26, 2019 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sumitkharche/a7caf712e4cb0b0fd2a3a8e1eaf70b05 to your computer and use it in GitHub Desktop.
Save sumitkharche/a7caf712e4cb0b0fd2a3a8e1eaf70b05 to your computer and use it in GitHub Desktop.
static.config.js
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