- Update ResolverPlugin interface to include context in update and resolve methods - Modify CustomResolver to pass entity state and resolved values to plugins - Update built-in plugins to accept and use the new context parameter - Add comprehensive test for inter-plugin communication - Add documentation for the new view composition patterns This change enables plugins to access each other's states during both update and resolve phases, allowing for more powerful and flexible resolver compositions.
48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import express, {Router} from "express";
|
|
import {RhizomeNode} from "../node";
|
|
import {htmlDocFromMarkdown, MDFiles} from "../utils/md-files";
|
|
|
|
export class HttpHtml {
|
|
router = Router();
|
|
mdFiles: MDFiles;
|
|
|
|
constructor(readonly rhizomeNode: RhizomeNode) {
|
|
this.mdFiles = new MDFiles(this.rhizomeNode);
|
|
|
|
// Serve README
|
|
this.router.get('/README', (_req: express.Request, res: express.Response) => {
|
|
const html = this.mdFiles.getReadmeHTML();
|
|
res.setHeader('content-type', 'text/html').send(html);
|
|
});
|
|
|
|
// Serve markdown files as html
|
|
this.router.get('/:name', (req: express.Request, res: express.Response) => {
|
|
const {name} = req.params;
|
|
let html = this.mdFiles.getHtml(name);
|
|
if (!html) {
|
|
res.status(404);
|
|
html = htmlDocFromMarkdown(`# 404 Not Found: ${name}\n\n ## [Index](/html)`);
|
|
}
|
|
res.setHeader('content-type', 'text/html');
|
|
res.send(html);
|
|
});
|
|
|
|
// Serve index
|
|
this.router.get('/', (_req: express.Request, res: express.Response) => {
|
|
res.setHeader('content-type', 'text/html').send(this.mdFiles.indexHtml);
|
|
});
|
|
}
|
|
|
|
start() {
|
|
// Scan and watch for markdown files
|
|
this.mdFiles.readDir();
|
|
this.mdFiles.readReadme();
|
|
this.mdFiles.watchDir();
|
|
this.mdFiles.watchReadme();
|
|
}
|
|
|
|
stop() {
|
|
this.mdFiles.stop();
|
|
}
|
|
}
|