11import React from "react" ;
22import { graphql } from "gatsby" ;
3- import { Grid } from "theme-ui" ;
3+ import { Divider , Grid , Themed } from "theme-ui" ;
44import { mapEdgesToNodes , filterOutDocsWithoutSlugs } from "../lib/helpers" ;
5+ import ArticlePreview from "../components/article-layouts/article-preview" ;
56import BlockContent from "../components/block-content" ;
67import Container from "../components/core/container" ;
78import 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