お知らせのMarkdownサポート + ogpタグ生成
This commit is contained in:
parent
ecc8b8562e
commit
5cff3cccca
5 changed files with 661 additions and 29 deletions
|
@ -5,18 +5,23 @@ import crypto from 'crypto';
|
|||
import koaSend from 'koa-send';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import ms from 'ms';
|
||||
import striptags from 'striptags';
|
||||
import MarkdownIt from 'markdown-it';
|
||||
|
||||
import { config } from '../config';
|
||||
import { upsertUser, getUser, updateUser, updateUsersToolsToken } from './functions/users';
|
||||
import { api } from './services/misskey';
|
||||
import { die } from './die';
|
||||
import { misskeyAppInfo } from './const';
|
||||
import { Announcements } from './models';
|
||||
|
||||
export const router = new Router<DefaultState, Context>();
|
||||
|
||||
const sessionHostCache: Record<string, string> = {};
|
||||
const tokenSecretCache: Record<string, string> = {};
|
||||
|
||||
const md = new MarkdownIt();
|
||||
|
||||
router.get('/login', async ctx => {
|
||||
let host = ctx.query.host as string | undefined;
|
||||
if (!host) {
|
||||
|
@ -135,6 +140,15 @@ router.get('/api(.*)', async (ctx, next) => {
|
|||
next();
|
||||
});
|
||||
|
||||
router.get('/announcements/:id', async (ctx) => {
|
||||
const a = await Announcements.findOne(ctx.params.id);
|
||||
const stripped = striptags(md.render(a?.body ?? '').replace(/\n/g, ' '));
|
||||
await ctx.render('frontend', a ? {
|
||||
t: a.title,
|
||||
d: stripped.length > 80 ? stripped.substring(0, 80) + '…' : stripped,
|
||||
} : null);
|
||||
});
|
||||
|
||||
router.get('(.*)', async (ctx) => {
|
||||
await ctx.render('frontend');
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue