mirror of https://codeberg.org/pzp/pzp-hub.git
refactor homepage markdown logic
This commit is contained in:
parent
13a8f59f44
commit
979ab1589e
|
@ -0,0 +1,19 @@
|
||||||
|
import { unified } from 'unified'
|
||||||
|
import remarkParse from 'remark-parse'
|
||||||
|
import remarkRehype from 'remark-rehype'
|
||||||
|
import rehypeStringify from 'rehype-stringify'
|
||||||
|
import fs from 'fs'
|
||||||
|
import path from 'path'
|
||||||
|
|
||||||
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||||
|
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md')
|
||||||
|
|
||||||
|
const processor = unified()
|
||||||
|
.use(remarkParse)
|
||||||
|
.use(remarkRehype)
|
||||||
|
.use(rehypeStringify)
|
||||||
|
|
||||||
|
const homepageMD = fs.readFileSync(homepagePath, 'utf8')
|
||||||
|
const homepageHTML = processor.processSync(homepageMD)
|
||||||
|
|
||||||
|
export default homepageHTML
|
15
lib/index.js
15
lib/index.js
|
@ -1,10 +1,6 @@
|
||||||
import { createRequire } from 'module'
|
import { createRequire } from 'module'
|
||||||
import { unified } from 'unified'
|
|
||||||
import remarkParse from 'remark-parse'
|
|
||||||
import remarkRehype from 'remark-rehype'
|
|
||||||
import rehypeStringify from 'rehype-stringify'
|
|
||||||
import fs from 'fs'
|
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
|
import homepageHTML from './homepage.js'
|
||||||
|
|
||||||
const require = createRequire(import.meta.url)
|
const require = createRequire(import.meta.url)
|
||||||
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
const __dirname = path.dirname(new URL(import.meta.url).pathname)
|
||||||
|
@ -16,15 +12,6 @@ const ejs = require('ejs')
|
||||||
|
|
||||||
const staticsPath = path.join(__dirname, 'public')
|
const staticsPath = path.join(__dirname, 'public')
|
||||||
const viewsPath = path.join(__dirname, 'views')
|
const viewsPath = path.join(__dirname, 'views')
|
||||||
const homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md')
|
|
||||||
|
|
||||||
const processor = unified()
|
|
||||||
.use(remarkParse)
|
|
||||||
.use(remarkRehype)
|
|
||||||
.use(rehypeStringify)
|
|
||||||
|
|
||||||
const homepageMD = fs.readFileSync(homepagePath, 'utf8')
|
|
||||||
const homepageHTML = processor.processSync(homepageMD)
|
|
||||||
|
|
||||||
const app = fastify({ logger: true })
|
const app = fastify({ logger: true })
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue