forked from cilium/cilium.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
200 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,64 @@ | ||
import React from 'react'; | ||
import { useStaticQuery, graphql } from 'gatsby'; | ||
import React, { Fragment } from 'react'; | ||
|
||
import BlogPostCard from 'components/shared/blog-post-card'; | ||
import Container from 'components/shared/container'; | ||
import Heading from 'components/shared/heading'; | ||
import List from 'components/shared/list'; | ||
import useWindowSize from 'hooks/use-window-size'; | ||
|
||
const title = 'Latest News & Blogs'; | ||
const TABLET_WIDTH = 1024; | ||
const title = 'Learn about Cilium & eBPF'; | ||
|
||
const featuredBlogs = { | ||
title: 'Featured Blogs', | ||
items: [ | ||
{ | ||
linkUrl: 'https://isovalent.com/blog/post/2021-09-aws-eks-anywhere-chooses-cilium', | ||
linkTarget: '_blank', | ||
linkText: 'AWS picks Cilium for Networking & Security on EKS Anywhere', | ||
}, | ||
{ | ||
linkUrl: 'https://cilium.io/blog/2021/08/03/best-of-echo', | ||
linkText: 'eBPF and Cilium Office Hours - Highlights from Season 1', | ||
}, | ||
{ | ||
linkUrl: 'https://cilium.io/blog/2021/05/20/cilium-110', | ||
linkText: | ||
'Cilium 1.10: WireGuard, BGP Support, Egress IP Gateway, New Cilium CLI, XDP Load Balancer, Alibaba Cloud Integration and more', | ||
}, | ||
{ | ||
linkUrl: 'https://cilium.io/blog/2021/05/11/cni-benchmark', | ||
linkText: 'CNI Benchmark: Understanding Cilium Network Performance', | ||
}, | ||
{ | ||
linkUrl: 'https://cilium.io/blog/2021/04/19/openshift-certification', | ||
linkText: 'Introducing the Cilium Certified OpenShift Plug-in', | ||
}, | ||
], | ||
buttonUrl: '/blog', | ||
buttonText: 'Read more', | ||
const Learn = () => { | ||
const { width } = useWindowSize(); | ||
const isDesktop = width >= TABLET_WIDTH; | ||
const { | ||
allMdx: { posts }, | ||
} = useStaticQuery(graphql` | ||
query blogQuery { | ||
allMdx(sort: { order: DESC, fields: frontmatter___date }, limit: 5) { | ||
posts: nodes { | ||
frontmatter { | ||
path | ||
externalUrl | ||
title | ||
date(locale: "en", formatString: "MMM DD, yyyy") | ||
ogImageUrl | ||
ogImage { | ||
childImageSharp { | ||
gatsbyImageData(width: 512) | ||
} | ||
} | ||
ogSummary | ||
} | ||
} | ||
} | ||
} | ||
`); | ||
|
||
return ( | ||
<section className="mt-10 md:mt-20 lg:mt-28"> | ||
<Container> | ||
<Heading tag="h2">{title}</Heading> | ||
<div className="grid grid-cols-1 lg:grid-cols-2 gap-8 mt-6 md:mt-8 lg:mt-11 lg:grid-rows-4"> | ||
{posts.map(({ frontmatter }, index) => ( | ||
<Fragment key={index}> | ||
{index === 0 ? ( | ||
<BlogPostCard | ||
className="lg:row-span-full" | ||
size={isDesktop ? 'lg' : 'sm'} | ||
isLandscapeView={!isDesktop} | ||
{...frontmatter} | ||
/> | ||
) : ( | ||
<BlogPostCard size="sm" isLandscapeView {...frontmatter} /> | ||
)} | ||
</Fragment> | ||
))} | ||
</div> | ||
</Container> | ||
</section> | ||
); | ||
}; | ||
const Learn = () => ( | ||
<section className="mt-10 md:mt-20 lg:mt-28"> | ||
<Container> | ||
<Heading tag="h2">{title}</Heading> | ||
<div className="grid grid-cols-1 mt-6 md:mt-10 lg:mt-14 lg:grid-cols-12 gap-x-8"> | ||
<List className="lg:col-span-10" {...featuredBlogs} /> | ||
</div> | ||
</Container> | ||
</section> | ||
); | ||
|
||
export default Learn; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { useState, useEffect } from 'react'; | ||
// Hook | ||
function useWindowSize() { | ||
// Initialize state with undefined width/height so server and client renders match | ||
// Learn more here: https://joshwcomeau.com/react/the-perils-of-rehydration/ | ||
const [windowSize, setWindowSize] = useState({ | ||
width: undefined, | ||
height: undefined, | ||
}); | ||
useEffect(() => { | ||
// Handler to call on window resize | ||
function handleResize() { | ||
// Set window width/height to state | ||
setWindowSize({ | ||
width: window.innerWidth, | ||
height: window.innerHeight, | ||
}); | ||
} | ||
// Add event listener | ||
window.addEventListener('resize', handleResize); | ||
// Call handler right away so state gets updated with initial window size | ||
handleResize(); | ||
// Remove event listener on cleanup | ||
return () => window.removeEventListener('resize', handleResize); | ||
}, []); // Empty array ensures that effect is only run on mount | ||
return windowSize; | ||
} | ||
|
||
export default useWindowSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters