refactor homepage markdown logic

This commit is contained in:
Andre Staltz 2023-06-06 14:34:25 +03:00
parent 13a8f59f44
commit 979ab1589e
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 20 additions and 14 deletions

19
lib/homepage.js Normal file
View File

@ -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

View File

@ -1,10 +1,6 @@
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 homepageHTML from './homepage.js'
const require = createRequire(import.meta.url)
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 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 })