1
0
mirror of https://github.com/oceanprotocol/market.git synced 2024-06-29 00:57:50 +02:00
market/src/@utils/markdownPages.tsx
mihaisc 8d1782a800
Restore order (#1068)
* minor refactors

* minor refactors

* fixes

* buy dt

* consumePrice + estimation

* various fixes

* cleanup

* fix build

* fix ssh issue

* feedback

* build fix

* ssh fix

* remove console.log

* suggested fixes

* other fixes

* switch to decimal

* more fixes

* more fixes

* fix

* some fee refactors

* more fee refactoring

* lib update, fre rename

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* minor refactors

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* build fixes

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* update + more refactoring

* calc price

* fix build

* restore accountId in effect

* fix order

* fix build and update lib

* fix order index

* fix comments

* pool fix

* remove console.log

* fix order fixed rate exchange

* fixed free order and messaging

* add comment

* minor type fix

* more type fixes
2022-02-14 08:27:36 -08:00

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')
const pagesDirectory = './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
}