mirror of https://codeberg.org/pzp/pzp-hub.git
replace fastify-markdown with remark
This commit is contained in:
parent
854e376a6a
commit
e6e65df94e
37
lib/index.js
37
lib/index.js
|
@ -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) => {
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue