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 fastify = require('fastify');
|
||||||
const fastifyView = require('@fastify/view');
|
const fastifyView = require('@fastify/view');
|
||||||
const fastifyMarkdown = require('fastify-markdown');
|
|
||||||
const fastifyStatic = require('@fastify/static');
|
const fastifyStatic = require('@fastify/static');
|
||||||
const ejs = require('ejs');
|
const ejs = require('ejs');
|
||||||
const fs = require('fs');
|
|
||||||
const path = require('path');
|
|
||||||
|
|
||||||
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 homepagePath = path.join(__dirname, '..', 'HOMEPAGE.md');
|
||||||
|
|
||||||
|
const processor = unified()
|
||||||
|
.use(remarkParse)
|
||||||
|
.use(remarkRehype)
|
||||||
|
.use(rehypeStringify)
|
||||||
|
|
||||||
const homepageMD = fs.readFileSync(homepagePath, 'utf8');
|
const homepageMD = fs.readFileSync(homepagePath, 'utf8');
|
||||||
|
const homepageHTML = processor.processSync(homepageMD)
|
||||||
|
|
||||||
const app = fastify({logger: true});
|
const app = fastify({logger: true});
|
||||||
|
|
||||||
app.register(fastifyView, {
|
app.register(fastifyView, { engine: {ejs}, root: viewsPath });
|
||||||
engine: {ejs},
|
|
||||||
root: viewsPath,
|
|
||||||
});
|
|
||||||
|
|
||||||
app.register(fastifyMarkdown, {
|
app.register(fastifyStatic, { root: staticsPath });
|
||||||
src: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
app.register(fastifyStatic, {
|
|
||||||
root: staticsPath,
|
|
||||||
});
|
|
||||||
|
|
||||||
app.get('/', (req, reply) => {
|
app.get('/', (req, reply) => {
|
||||||
const markdown = reply.markdown().parse(homepageMD);
|
reply.view('index.ejs', {markdown: homepageHTML});
|
||||||
reply.view('index.ejs', {markdown});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/invite', (req, reply) => {
|
app.get('/invite', (req, reply) => {
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
"require": "./lib/index.js"
|
"require": "./lib/index.js"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"type": "commonjs",
|
"type": "module",
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=16"
|
"node": ">=16"
|
||||||
},
|
},
|
||||||
|
@ -28,7 +28,10 @@
|
||||||
"@fastify/view": "7.4.1",
|
"@fastify/view": "7.4.1",
|
||||||
"ejs": "3.1.9",
|
"ejs": "3.1.9",
|
||||||
"fastify": "4.17.0",
|
"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": {
|
"devDependencies": {
|
||||||
"c8": "7",
|
"c8": "7",
|
||||||
|
|
Loading…
Reference in New Issue