Skip to content

Commit 2dbd789

Browse files
committed
fix(homepage): set news to latest 4 articles
1 parent 84d855e commit 2dbd789

File tree

1 file changed

+8
-78
lines changed

1 file changed

+8
-78
lines changed

src/components/homepage/News.tsx

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,12 @@ function sortPosts(posts: Query['allMarkdownRemark']['edges']) {
1616
}
1717

1818
type QueryType = Query & {
19-
latest: Query['allMarkdownRemark']
20-
danielArticle: Query['allMarkdownRemark']
21-
elizabethArticle: Query['allMarkdownRemark']
22-
mikeArticle: Query['allMarkdownRemark']
19+
articles: Query['allMarkdownRemark']
2320
}
2421

2522
export default function News() {
2623
const data = useStaticQuery<QueryType>(newsQuery)
27-
const posts = data.latest.edges.concat(
28-
data.danielArticle.edges.concat(
29-
data.elizabethArticle.edges.concat(data.mikeArticle.edges)
30-
)
31-
)
24+
const posts = data.articles.edges
3225
return (
3326
<div id="news" className="ie-fix" css={styles.container}>
3427
<h2>News &amp; Tutorials</h2>
@@ -47,7 +40,9 @@ export default function News() {
4740
date={post.frontmatter.date}
4841
header={post.frontmatter.title}
4942
to={post.fields.slug}
50-
type={author === 'daniel' ? 'Tutorial' : 'Blog'}
43+
type={
44+
post.frontmatter.tags.includes('Tutorial') ? 'Tutorial' : 'Blog'
45+
}
5146
/>
5247
)
5348
})}
@@ -92,79 +87,13 @@ const styles = {
9287

9388
const newsQuery = graphql`
9489
query newsQuery {
95-
latest: allMarkdownRemark(
90+
articles: allMarkdownRemark(
9691
filter: {
9792
fileAbsolutePath: { regex: "/blog/" }
9893
frontmatter: { draft: { ne: true } }
9994
}
100-
sort: { fields: [frontmatter___date], order: ASC }
101-
limit: 1
102-
) {
103-
edges {
104-
node {
105-
id
106-
fields {
107-
slug
108-
}
109-
frontmatter {
110-
author
111-
date(formatString: "MMM DD, YYYY")
112-
title
113-
}
114-
}
115-
}
116-
}
117-
danielArticle: allMarkdownRemark(
118-
filter: {
119-
fileAbsolutePath: { regex: "/blog/" }
120-
frontmatter: { draft: { ne: true }, author: { eq: "daniel" } }
121-
}
122-
sort: { fields: [frontmatter___date], order: ASC }
123-
limit: 1
124-
) {
125-
edges {
126-
node {
127-
id
128-
fields {
129-
slug
130-
}
131-
frontmatter {
132-
author
133-
date(formatString: "MMM DD, YYYY")
134-
title
135-
}
136-
}
137-
}
138-
}
139-
elizabethArticle: allMarkdownRemark(
140-
filter: {
141-
fileAbsolutePath: { regex: "/blog/" }
142-
frontmatter: { draft: { ne: true }, author: { eq: "elizabeth" } }
143-
}
144-
sort: { fields: [frontmatter___date], order: DESC }
145-
limit: 1
146-
) {
147-
edges {
148-
node {
149-
id
150-
fields {
151-
slug
152-
}
153-
frontmatter {
154-
author
155-
date(formatString: "MMM DD, YYYY")
156-
title
157-
}
158-
}
159-
}
160-
}
161-
mikeArticle: allMarkdownRemark(
162-
filter: {
163-
fileAbsolutePath: { regex: "/blog/" }
164-
frontmatter: { draft: { ne: true }, author: { eq: "mike" } }
165-
}
16695
sort: { fields: [frontmatter___date], order: DESC }
167-
limit: 1
96+
limit: 4
16897
) {
16998
edges {
17099
node {
@@ -175,6 +104,7 @@ const newsQuery = graphql`
175104
frontmatter {
176105
author
177106
date(formatString: "MMM DD, YYYY")
107+
tags
178108
title
179109
}
180110
}

0 commit comments

Comments
 (0)