Skip to content

Commit

Permalink
fix(homepage): set news to latest 4 articles
Browse files Browse the repository at this point in the history
  • Loading branch information
timmywil committed Sep 22, 2020
1 parent 84d855e commit 2dbd789
Showing 1 changed file with 8 additions and 78 deletions.
86 changes: 8 additions & 78 deletions src/components/homepage/News.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ function sortPosts(posts: Query['allMarkdownRemark']['edges']) {
}

type QueryType = Query & {
latest: Query['allMarkdownRemark']
danielArticle: Query['allMarkdownRemark']
elizabethArticle: Query['allMarkdownRemark']
mikeArticle: Query['allMarkdownRemark']
articles: Query['allMarkdownRemark']
}

export default function News() {
const data = useStaticQuery<QueryType>(newsQuery)
const posts = data.latest.edges.concat(
data.danielArticle.edges.concat(
data.elizabethArticle.edges.concat(data.mikeArticle.edges)
)
)
const posts = data.articles.edges
return (
<div id="news" className="ie-fix" css={styles.container}>
<h2>News &amp; Tutorials</h2>
Expand All @@ -47,7 +40,9 @@ export default function News() {
date={post.frontmatter.date}
header={post.frontmatter.title}
to={post.fields.slug}
type={author === 'daniel' ? 'Tutorial' : 'Blog'}
type={
post.frontmatter.tags.includes('Tutorial') ? 'Tutorial' : 'Blog'
}
/>
)
})}
Expand Down Expand Up @@ -92,79 +87,13 @@ const styles = {

const newsQuery = graphql`
query newsQuery {
latest: allMarkdownRemark(
articles: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/blog/" }
frontmatter: { draft: { ne: true } }
}
sort: { fields: [frontmatter___date], order: ASC }
limit: 1
) {
edges {
node {
id
fields {
slug
}
frontmatter {
author
date(formatString: "MMM DD, YYYY")
title
}
}
}
}
danielArticle: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/blog/" }
frontmatter: { draft: { ne: true }, author: { eq: "daniel" } }
}
sort: { fields: [frontmatter___date], order: ASC }
limit: 1
) {
edges {
node {
id
fields {
slug
}
frontmatter {
author
date(formatString: "MMM DD, YYYY")
title
}
}
}
}
elizabethArticle: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/blog/" }
frontmatter: { draft: { ne: true }, author: { eq: "elizabeth" } }
}
sort: { fields: [frontmatter___date], order: DESC }
limit: 1
) {
edges {
node {
id
fields {
slug
}
frontmatter {
author
date(formatString: "MMM DD, YYYY")
title
}
}
}
}
mikeArticle: allMarkdownRemark(
filter: {
fileAbsolutePath: { regex: "/blog/" }
frontmatter: { draft: { ne: true }, author: { eq: "mike" } }
}
sort: { fields: [frontmatter___date], order: DESC }
limit: 1
limit: 4
) {
edges {
node {
Expand All @@ -175,6 +104,7 @@ const newsQuery = graphql`
frontmatter {
author
date(formatString: "MMM DD, YYYY")
tags
title
}
}
Expand Down

0 comments on commit 2dbd789

Please sign in to comment.