How can I get markdown files with pagination form the disk with next js?

Viewed 113

I create a blog with Next.js. I have markdown files that I must show in the "blogs" page , so I am using the getInitialProps() with rquire.context() to load markdown files from the disk. My question is, how can I load the markdown files with pagination ?

        const keys = context.keys()
        const values = keys.map(context)
        const data = keys.map((key, index) => {
            // Create slug from filename
            const slug = key
                .replace(/^.*[\\\/]/, '')
                .split('.')
                .slice(0, -1)
                .join('.')
            const value = values[index]
            // Parse yaml metadata & markdownbody in document
            const md = new MarkdownIt()
            const doc = matter((value as any).default)
            const {orig,...document} = doc
            return {
                document,
                slug,
            }
        })
        return data
    })(require.context('../posts', true, /\.md$/))
0 Answers
Related