({
baseUrl,
content,
actions,
options,
aliasedSource,
}: CreateAllRoutesParam)
| 51 | } |
| 52 | |
| 53 | export async function buildAllRoutes({ |
| 54 | baseUrl, |
| 55 | content, |
| 56 | actions, |
| 57 | options, |
| 58 | aliasedSource, |
| 59 | }: CreateAllRoutesParam): Promise<RouteConfig[]> { |
| 60 | const { |
| 61 | blogListComponent, |
| 62 | blogPostComponent, |
| 63 | blogTagsListComponent, |
| 64 | blogAuthorsListComponent, |
| 65 | blogAuthorsPostsComponent, |
| 66 | blogTagsPostsComponent, |
| 67 | blogArchiveComponent, |
| 68 | routeBasePath, |
| 69 | archiveBasePath, |
| 70 | authorsBasePath, |
| 71 | postsPerPage, |
| 72 | pageBasePath, |
| 73 | } = options; |
| 74 | const pluginId = options.id; |
| 75 | const {createData} = actions; |
| 76 | const { |
| 77 | blogTitle, |
| 78 | blogDescription, |
| 79 | blogSidebarTitle, |
| 80 | blogPosts, |
| 81 | blogTags, |
| 82 | blogTagsListPath, |
| 83 | authorsMap, |
| 84 | } = content; |
| 85 | |
| 86 | const blogBasePath = normalizeUrl([baseUrl, routeBasePath]); |
| 87 | const authorsListPath = normalizeUrl([blogBasePath, authorsBasePath]); |
| 88 | |
| 89 | const listedBlogPosts = blogPosts.filter(shouldBeListed); |
| 90 | |
| 91 | const blogPostsById = _.keyBy(blogPosts, (post) => post.id); |
| 92 | function getBlogPostById(id: string): BlogPost { |
| 93 | const blogPost = blogPostsById[id]; |
| 94 | if (!blogPost) { |
| 95 | throw new Error(`unexpected, can't find blog post id=${id}`); |
| 96 | } |
| 97 | return blogPost; |
| 98 | } |
| 99 | |
| 100 | const sidebarBlogPosts = |
| 101 | options.blogSidebarCount === 'ALL' |
| 102 | ? blogPosts |
| 103 | : blogPosts.slice(0, options.blogSidebarCount); |
| 104 | |
| 105 | async function createSidebarModule() { |
| 106 | const sidebarProp = toBlogSidebarProp({ |
| 107 | blogSidebarTitle, |
| 108 | blogPosts: sidebarBlogPosts, |
| 109 | }); |
| 110 | const modulePath = await createData( |
searching dependent graphs…