0
0
Fork 0

お知らせのMarkdownサポート + ogpタグ生成

This commit is contained in:
Xeltica 2022-03-01 00:35:23 +09:00
parent ecc8b8562e
commit 5cff3cccca
5 changed files with 661 additions and 29 deletions

View file

@ -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');
});

View file

@ -4,8 +4,8 @@ html
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1.0")
block meta
- const title = 'Misskey Tools'
- const desc = '✨Misskey での1日のート数、フォロー数、フォロワー数をカウントし、深夜0時にお知らせする便利サービスです。';
- const title = t ? `${t} | Misskey Tools`: 'Misskey Tools';
- const desc = d || '✨Misskey での1日のート数、フォロー数、フォロワー数をカウントし、深夜0時にお知らせする便利サービスです。';
title= title
meta(name='description' content=desc)
meta(property='og:title' content=title)