This repository has been archived by the owner on Oct 30, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 56
/
index.js
executable file
·74 lines (67 loc) · 2.28 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import React from 'react'
import PropTypes from 'prop-types'
import { graphql } from 'gatsby'
import queryString from "query-string"
import { Layout, PostView, HeaderIndex } from '../components/common'
import { StickyNavContainer, OverlayContainer } from '../components/common/effects'
import { MetaData } from '../components/common/meta'
import { GlobalStateContext } from "../context/GlobalState"
/**
* Main index page (home page)
*
* Loads all posts from Ghost
*
*/
const Index = ({ data, location, pageContext }) => {
const posts = data.allGhostPost.edges
const parsedQuery = location.search && location.search.length > 0 && queryString.parse(location.search)
return (
<GlobalStateContext.Consumer>{ g => (
<React.Fragment>
<MetaData location={location} image={data.file} />
<StickyNavContainer throttle={300} activeClass="fixed-nav-active" render={ sticky => (
<OverlayContainer render={ overlay => (
<Layout parsedQuery={parsedQuery !== '' ? parsedQuery : undefined } isHome={true} header={<HeaderIndex overlay={overlay}/>} sticky={sticky} overlay={overlay} >
<PostView globalState={g} pageContext={pageContext} posts={posts} isHome={true} />
</Layout>
)}/>
)}/>
</React.Fragment>
)}
</GlobalStateContext.Consumer>
)
}
Index.propTypes = {
data: PropTypes.shape({
allGhostPost: PropTypes.object.isRequired,
file: PropTypes.object,
}).isRequired,
location: PropTypes.object.isRequired,
pageContext: PropTypes.object.isRequired,
}
export default Index
// This page query loads all posts
// Note that sorting within $postIds is irrelevant!
export const pageQuery = graphql`
query GhostPostQuery($postIds: [String!]!, $limit: Int!, $skip: Int!) {
allGhostPost(
filter: {id: { in: $postIds }},
limit: $limit,
skip: $skip,
sort: { fields: [featured, published_at], order: [DESC, DESC] }
) {
edges {
node {
...GhostPostFieldsForIndex
}
}
}
file(relativePath: {eq: "site-meta.png"}) {
publicURL
imageMeta {
width
height
}
}
}
`