-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathpopular.tsx
More file actions
57 lines (47 loc) · 1.5 KB
/
popular.tsx
File metadata and controls
57 lines (47 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { ReactElement } from 'react';
import { graphql, PageProps } from 'gatsby';
import SEO from 'src/components/SEO';
import Wrapper from 'src/components/Wrapper';
import { getTextPreviews, getPostLinks } from './index';
import { AllPostsQueryType } from 'src/types/queries.d';
const TEXT_PREVIEW_POSTS = 10;
const POST_LINKS = 10;
export type PropsType = PageProps<AllPostsQueryType, null>;
// Note: strange to make this component lowercase, but we want a final path of /popular/
// and our eslint rules want this component name to match the filename.
export default function popular({ location, data }: PropsType): ReactElement | null {
const posts = data.allMarkdownRemark.edges.map(item => item.node);
const title = 'Popular Posts';
const text = posts.slice(0, TEXT_PREVIEW_POSTS);
const link = posts.slice(TEXT_PREVIEW_POSTS, TEXT_PREVIEW_POSTS + POST_LINKS);
return (
<Wrapper location={location}>
<SEO pageTitle={title} location={location} />
<h1>{title}</h1>
<ol>
{[...getTextPreviews(text), ...getPostLinks(link)].map((item, index) => (
<li key={index}>{item}</li>
))}
</ol>
</Wrapper>
);
}
export const pageQuery = graphql`
query {
allMarkdownRemark(limit: 20, sort: { fields: [frontmatter___rank], order: ASC }) {
edges {
node {
textPreview
fields {
slug
}
frontmatter {
title
rank
date
}
}
}
}
}
`;