File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import { getAllPosts , getPostBySlug , getPostPaths , getPostSlugs } from "cdm-content" ;
2+ import { GetStaticPaths , GetStaticProps } from "next" ;
3+ import { ArticlePage } from "../../views/Article" ;
4+
5+ export const getStaticPaths : GetStaticPaths = async ( ) => {
6+ const posts = await getAllPosts ( ) ;
7+
8+ return {
9+ paths : posts . map ( p => ( { params : { path : p . slug . replace ( '/article/' , '' ) } } ) ) ,
10+ fallback : 'blocking'
11+ }
12+ }
13+
14+ export const getStaticProps : GetStaticProps = async ( context ) => {
15+ const props : Record < string , any > = { } ;
16+ const path = Array . isArray ( context . params . path ) ? context . params . path . join ( '/' ) : context . params . path ;
17+ const posts = await getAllPosts ( ) ;
18+ const post = await getPostBySlug ( path ) ;
19+
20+ if ( post === null ) {
21+ return {
22+ notFound : true
23+ }
24+ }
25+
26+ const postIndex = posts ?. findIndex ( p => p . slug === `/articles/${ post . slug } ` ) ;
27+ const prev = postIndex > - 1 ? posts [ postIndex + 1 ] : null ;
28+ const next = postIndex > - 1 ? posts [ postIndex - 1 ] : null ;
29+
30+ props . post = post ;
31+ if ( next ) props . next = next ;
32+ if ( prev ) props . prev = prev || null ;
33+
34+ return {
35+ props
36+ }
37+ }
38+
39+ export default ArticlePage ;
You can’t perform that action at this time.
0 commit comments