Skip to content

Commit 74f31f2

Browse files
authored
Merge pull request #242 from HarvardOpenData/kh-short-form-schema
Adding Short Form Feature to the HODP front page
2 parents b12f01b + b4757d4 commit 74f31f2

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

studio/schemas/shortForm.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ export default {
1919
maxLength: 96,
2020
},
2121
},
22+
{
23+
name: "mainImage",
24+
title: "Main image",
25+
type: "mainImage",
26+
},
2227
{
2328
name: "slideshow",
2429
title: "Slideshow",

web/src/pages/index.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react";
22
import { graphql } from "gatsby";
3-
import { Grid } from "theme-ui";
3+
import { Divider, Grid, Themed } from "theme-ui";
44
import { mapEdgesToNodes, filterOutDocsWithoutSlugs } from "../lib/helpers";
5+
import ArticlePreview from "../components/article-layouts/article-preview";
56
import BlockContent from "../components/block-content";
67
import Container from "../components/core/container";
78
import GraphQLErrorList from "../components/core/graphql-error-list";
@@ -63,6 +64,45 @@ export const query = graphql`
6364
}
6465
}
6566
}
67+
shortForms: allSanityShortForm(
68+
limit: 1
69+
sort: { fields: [publishedAt], order: DESC }
70+
) {
71+
edges {
72+
node {
73+
id
74+
publishedAt
75+
mainImage {
76+
crop {
77+
_key
78+
_type
79+
top
80+
bottom
81+
left
82+
right
83+
}
84+
hotspot {
85+
_key
86+
_type
87+
x
88+
y
89+
height
90+
width
91+
}
92+
asset {
93+
_id
94+
}
95+
alt
96+
}
97+
title
98+
_rawExcerpt
99+
_rawMembers(resolveReferences: { maxDepth: 5 })
100+
slug {
101+
current
102+
}
103+
}
104+
}
105+
}
66106
}
67107
`;
68108

@@ -83,6 +123,10 @@ const IndexPage = (props) => {
83123
? mapEdgesToNodes(data.projects).filter(filterOutDocsWithoutSlugs)
84124
: [];
85125

126+
const shortFormNodes = (data || {}).shortForms
127+
? mapEdgesToNodes(data.shortForms).filter(filterOutDocsWithoutSlugs)
128+
: [];
129+
86130
if (!site) {
87131
throw new Error(
88132
'Missing "Site settings". Open the studio at http://localhost:3333 and add some content to "Site settings" and restart the development server.'
@@ -128,6 +172,15 @@ const IndexPage = (props) => {
128172
<BlockContent blocks={page._rawBody || []} />
129173
<Spacer height={5} />
130174
<Section header="Quick Links">
175+
<Themed.h3>Featured Short Form</Themed.h3>
176+
{shortFormNodes && (
177+
<ArticlePreview
178+
key={1}
179+
{...shortFormNodes[0]}
180+
link={shortFormNodes[0].slug.current}
181+
/>
182+
)}
183+
<Divider mb={3} color="text" />
131184
<BlockContent blocks={page._rawBodySecondary || []} />
132185
</Section>
133186
</div>

0 commit comments

Comments
 (0)