mirror of
https://github.com/oceanprotocol/market.git
synced 2024-06-28 00:27:49 +02:00
* migrate to Next.js * migrate scripts * generate markdown pages * make all the markdown work * fix profile, fix image loading * git+ssh → git+https, again * bump packages * maybe windows build fix * add public to gitignore Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro> * Next.js v12! Webpack 5! No build hacks anymore * json import fixes * fixes Co-authored-by: mihaisc <mihai.scarlat@smartcontrol.ro>
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import fs from 'fs'
|
|
import { join } from 'path'
|
|
import matter from 'gray-matter'
|
|
|
|
//
|
|
// Next.js specifics to be used in getStaticProps / getStaticPaths
|
|
// to automatically generate pages from Markdown files in `src/pages/[slug].tsx`.
|
|
//
|
|
const pagesDirectory = join(process.cwd(), 'content', 'pages')
|
|
|
|
export interface PageData {
|
|
slug: string
|
|
frontmatter: { [key: string]: any }
|
|
content: string
|
|
}
|
|
|
|
export function getPageBySlug(slug: string, subDir?: string): PageData {
|
|
const realSlug = slug.replace(/\.md$/, '')
|
|
const fullPath = subDir
|
|
? join(pagesDirectory, subDir, `${realSlug}.md`)
|
|
: join(pagesDirectory, `${realSlug}.md`)
|
|
const fileContents = fs.readFileSync(fullPath, 'utf8')
|
|
const { data, content } = matter(fileContents)
|
|
|
|
return { slug: realSlug, frontmatter: { ...data }, content }
|
|
}
|
|
|
|
export function getAllPages(subDir?: string): PageData[] {
|
|
const slugs = fs
|
|
.readdirSync(join(pagesDirectory, subDir || ''))
|
|
.filter((slug) => slug.includes('.md'))
|
|
const pages = slugs.map((slug) => getPageBySlug(slug, subDir))
|
|
|
|
return pages
|
|
}
|