-
Notifications
You must be signed in to change notification settings - Fork 12
/
AppBlogPostList.tsx
51 lines (43 loc) · 1.26 KB
/
AppBlogPostList.tsx
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
import React, { ComponentType } from 'react';
import AppBlogPostListGenerated from './AppBlogPostList.generated';
import { sortBy } from 'lodash';
export type AppBlogPost = {
default: ComponentType<{}>,
frontmatter: {
slug: string;
title: string;
author: string;
date: string;
hero: { uri: string };
excerpt: string;
secret?: boolean;
};
};
let BlogPosts = AppBlogPostListGenerated as AppBlogPost[];
// Sort by date
BlogPosts = sortBy(
BlogPosts,
(blogPost) => blogPost.frontmatter.date,
).reverse();
const ShowSecretBlogPostsInDev = false; // toggle this if needed
// Remove blog posts with secret: true frontmatter
BlogPosts =
__DEV__ && ShowSecretBlogPostsInDev
? BlogPosts
: BlogPosts.filter((blogPost) => !blogPost.frontmatter.secret);
export const AppBlogPosts = BlogPosts;
AppBlogPosts.forEach((p) => {
// add ability, to infer a slug automatically?
if (!p.frontmatter.slug) {
throw new Error(
'Blog post slug frontmatter is required for the mobile app',
);
}
});
export const getBlogPostBySlug = (slug: string): AppBlogPost => {
const blogPost = AppBlogPosts.find((p) => p.frontmatter.slug === slug);
if (!blogPost) {
throw new Error('no post found for slug=' + slug);
}
return blogPost;
};