You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Hydro/hydro/handler/wiki.ts

27 lines
911 B
TypeScript

import { NotFoundError } from '../error';
import { Route, Handler } from '../service/server';
5 years ago
5 years ago
class WikiHandler extends Handler {
4 years ago
async get({ category = 'wiki', page }) {
if (!global.Hydro.wiki[category]) throw new NotFoundError(category);
if (!global.Hydro.wiki[category][page]) throw new NotFoundError(category, page);
const contents = global.Hydro.wiki[category][page];
5 years ago
const path = [
4 years ago
['Hydro', 'homepage'],
4 years ago
[`wiki_${category}`, null],
[`wiki_${category}_${page}`, null],
5 years ago
];
5 years ago
this.response.body = {
4 years ago
path, contents, page_name: `wiki_${category}_${page}`,
5 years ago
};
this.response.template = 'wiki.html';
5 years ago
}
}
export async function apply() {
Route('wiki', '/wiki/:page', WikiHandler);
4 years ago
Route('wiki_with_category', '/wiki/:category/:page', WikiHandler);
5 years ago
}
global.Hydro.handler.wiki = apply;