ドキュメントをmisskey-hubに移行

This commit is contained in:
syuilo 2021-11-05 16:18:52 +09:00
parent c625a3fa5b
commit 8630542146
1355 changed files with 13 additions and 60421 deletions

View file

@ -4,7 +4,6 @@
import * as os from 'os';
import * as fs from 'fs';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import * as ms from 'ms';
import * as Koa from 'koa';
@ -12,8 +11,6 @@ import * as Router from '@koa/router';
import * as send from 'koa-send';
import * as favicon from 'koa-favicon';
import * as views from 'koa-views';
import * as glob from 'glob';
import * as MarkdownIt from 'markdown-it';
import packFeed from './feed';
import { fetchMeta } from '@/misc/fetch-meta';
@ -30,19 +27,7 @@ import * as locales from '../../../locales/index';
const _filename = __filename;
const _dirname = dirname(_filename);
const markdown = MarkdownIt({
html: true
});
const changelog = fs.readFileSync(`${_dirname}/../../../CHANGELOG.md`, { encoding: 'utf8' });
function genDoc(path: string): string {
let md = fs.readFileSync(path, { encoding: 'utf8' });
md = md.replace('<!--[CHANGELOG]-->', changelog);
return md;
}
const staticAssets = `${_dirname}/../../../assets/`;
const docAssets = `${_dirname}/../../../src/docs/`;
const assets = `${_dirname}/../../assets/`;
// Init app
@ -79,14 +64,6 @@ router.get('/static-assets/(.*)', async ctx => {
});
});
router.get('/doc-assets/(.*)', async ctx => {
if (ctx.path.includes('..')) return;
const path = `${_dirname}/../../../src/docs/${ctx.path.replace('/doc-assets/', '')}`;
const doc = genDoc(path);
ctx.set('Content-Type', 'text/plain; charset=utf-8');
ctx.body = doc;
});
router.get('/assets/(.*)', async ctx => {
await send(ctx as any, ctx.path.replace('/assets/', ''), {
root: assets,
@ -149,64 +126,6 @@ router.get('/api.json', async ctx => {
ctx.body = genOpenapiSpec();
});
router.get('/docs.json', async ctx => {
const lang = ctx.query.lang;
const query = ctx.query.q;
if (!Object.keys(locales).includes(lang)) {
ctx.body = [];
return;
}
const dirPath = `${_dirname}/../../../src/docs/${lang}`.replace(/\\/g, '/');
const paths = glob.sync(`${dirPath}/**/*.md`);
const docs: { path: string; title: string; summary: string; }[] = [];
for (const path of paths) {
const md = genDoc(path);
if (query && query.length > 0) {
// TODO: カタカナをひらがなにして比較するなどしたい
if (!md.includes(query)) continue;
}
const parsed = markdown.parse(md, {});
if (parsed.length === 0) return;
const buf = [...parsed];
const headingTokens = [];
// もっとも上にある見出しを抽出する
while (buf[0].type !== 'heading_open') {
buf.shift();
}
buf.shift();
while (buf[0].type as string !== 'heading_close') {
const token = buf.shift();
if (token) {
headingTokens.push(token);
}
}
const firstParagrapfTokens = [];
while (buf[0].type !== 'paragraph_open') {
buf.shift();
}
buf.shift();
while (buf[0].type as string !== 'paragraph_close') {
const token = buf.shift();
if (token) {
firstParagrapfTokens.push(token);
}
}
docs.push({
path: path.match(new RegExp(`docs\/${lang}\/(.+?)\.md$`))![1],
title: markdown.renderer.render(headingTokens, {}, {}),
summary: markdown.renderer.render(firstParagrapfTokens, {}, {}),
});
}
ctx.body = docs;
});
const getFeed = async (acct: string) => {
const { username, host } = parseAcct(acct);
const user = await Users.findOne({