-
Notifications
You must be signed in to change notification settings - Fork 10.3k
/
template-starter-page.js
177 lines (169 loc) · 4.85 KB
/
template-starter-page.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import React from "react"
import Helmet from "react-helmet"
import { graphql } from "gatsby"
import Layout from "../components/layout"
import presets from "../utils/presets"
import StarterHeader from "../views/starter/header"
import StarterMeta from "../views/starter/meta"
import StarterScreenshot from "../views/starter/screenshot"
import StarterSource from "../views/starter/source"
import StarterDetails from "../views/starter/details"
class StarterTemplate extends React.Component {
state = {
showAllDeps: false,
}
render() {
const { startersYaml } = this.props.data
const {
url: demoUrl,
repo: repoUrl,
fields: { starterShowcase },
childScreenshot: { screenshotFile },
} = startersYaml
// preprocessing of dependencies
const { miscDependencies = [], gatsbyDependencies = [] } = starterShowcase
const allDeps = [
...gatsbyDependencies.map(([name, ver]) => name),
...miscDependencies.map(([name, ver]) => name),
]
const shownDeps = this.state.showAllDeps ? allDeps : allDeps.slice(0, 15)
const showMore =
!this.state.showAllDeps && allDeps.length - shownDeps.length > 0
// plug for now
const isModal = false
const repoName = starterShowcase.name
return (
<Layout
location={this.props.location}
isModal={isModal}
modalBackgroundPath="/showcase"
>
<div
css={{
alignItems: `center`,
display: `flex`,
flexDirection: `column`,
maxWidth: isModal ? false : 1080,
margin: isModal ? false : `0 auto`,
}}
>
<div
css={{
width: `100%`,
}}
>
<Helmet>
<title>{`${repoName}: Gatsby Starter`}</title>
<meta
property="og:image"
content={screenshotFile.childImageSharp.fluid.src}
/>
<meta property="og:image:alt" content="Gatsby Logo" />
<meta
name="twitter:image"
content={screenshotFile.childImageSharp.fluid.src}
/>
<meta
name="description"
content={`Gatsby Starter: ${repoName}`}
/>
<meta
property="og:description"
content={`Gatsby Starter: ${repoName}`}
/>
<meta
name="twitter:description"
content={`Gatsby Starter: ${repoName}`}
/>
<meta property="og:site_name" content={repoName} />
<meta property="og:title" content={repoName} />
<meta property="og:type" content="article" />
<meta name="twitter.label1" content="Reading time" />
<meta name="twitter:data1" content={`1 min read`} />
</Helmet>
<StarterHeader stub={starterShowcase.stub} />
<div
css={{
display: `flex`,
flexDirection: `column-reverse`,
[presets.Phablet]: {
flexDirection: `column`,
},
}}
>
<StarterMeta
starter={starterShowcase}
repoName={repoName}
imageSharp={screenshotFile}
demo={demoUrl}
/>
<StarterScreenshot
imageSharp={screenshotFile}
repoName={repoName}
/>
</div>
<StarterSource repoUrl={repoUrl} startersYaml={startersYaml} />
<StarterDetails
startersYaml={startersYaml}
allDeps={allDeps}
shownDeps={shownDeps}
showMore={showMore}
showAllDeps={this.showAllDeps}
/>
</div>
</div>
</Layout>
)
}
showAllDeps = () => {
this.setState({ showAllDeps: true })
}
}
export default StarterTemplate
export const pageQuery = graphql`
query TemplateStarter($slug: String!) {
startersYaml(fields: { starterShowcase: { slug: { eq: $slug } } }) {
id
fields {
starterShowcase {
slug
stub
description
stars
lastUpdated
owner
name
githubFullName
allDependencies
gatsbyDependencies
miscDependencies
}
}
url
repo
description
tags
features
internal {
type
}
childScreenshot {
screenshotFile {
childImageSharp {
fluid(maxWidth: 700) {
...GatsbyImageSharpFluid
}
resize(
width: 1500
height: 1500
cropFocus: CENTER
toFormat: JPG
) {
src
}
}
}
}
}
}
`