replace fastify-markdown with remark

This commit is contained in:
Andre Staltz 2023-06-06 14:23:53 +03:00
parent 854e376a6a
commit e6e65df94e
No known key found for this signature in database
GPG Key ID: 9EDE23EA7E8A4890
2 changed files with 26 additions and 18 deletions

View File

@ -1,34 +1,39 @@
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'
const require = createRequire(import.meta.url);
const __dirname = path.dirname(new URL(import.meta.url).pathname);
const fastify = require('fastify');
const fastifyView = require('@fastify/view');
const fastifyMarkdown = require('fastify-markdown');
const fastifyStatic = require('@fastify/static');
const ejs = require('ejs');
const fs = require('fs');
const path = require('path');
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});
app.register(fastifyView, {
engine: {ejs},
root: viewsPath,
});
app.register(fastifyView, { engine: {ejs}, root: viewsPath });
app.register(fastifyMarkdown, {
src: false,
});
app.register(fastifyStatic, {
root: staticsPath,
});
app.register(fastifyStatic, { root: staticsPath });
app.get('/', (req, reply) => {
const markdown = reply.markdown().parse(homepageMD);
reply.view('index.ejs', {markdown});
reply.view('index.ejs', {markdown: homepageHTML});
});
app.get('/invite', (req, reply) => {

View File

@ -19,7 +19,7 @@
"require": "./lib/index.js"
}
},
"type": "commonjs",
"type": "module",
"engines": {
"node": ">=16"
},
@ -28,7 +28,10 @@
"@fastify/view": "7.4.1",
"ejs": "3.1.9",
"fastify": "4.17.0",
"fastify-markdown": "0.4.0"
"unified": "10.1.2",
"remark-parse": "10.0.2",
"remark-rehype": "10.1.0",
"rehype-stringify": "9.0.3"
},
"devDependencies": {
"c8": "7",