メタ情報をレンダリングするように
This commit is contained in:
@ -7,14 +7,32 @@ import * as Koa from 'koa';
|
||||
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 docs from './docs';
|
||||
import User from '../../models/user';
|
||||
import parseAcct from '../../acct/parse';
|
||||
import { fa } from '../../build/fa';
|
||||
import config from '../../config';
|
||||
import Note, { pack as packNote } from '../../models/note';
|
||||
import getNoteSummary from '../../renderers/get-note-summary';
|
||||
const consts = require('../../const.json');
|
||||
|
||||
const client = `${__dirname}/../../client/`;
|
||||
|
||||
// Init app
|
||||
const app = new Koa();
|
||||
|
||||
// Init renderer
|
||||
app.use(views(__dirname + '/views', {
|
||||
extension: 'pug',
|
||||
options: {
|
||||
config,
|
||||
themeColor: consts.themeColor,
|
||||
facss: fa.dom.css()
|
||||
}
|
||||
}));
|
||||
|
||||
// Serve favicon
|
||||
app.use(favicon(`${client}/assets/favicon.ico`));
|
||||
|
||||
@ -67,6 +85,38 @@ router.use('/docs', docs.routes());
|
||||
// URL preview endpoint
|
||||
router.get('/url', require('./url-preview'));
|
||||
|
||||
//#region for crawlers
|
||||
// User
|
||||
router.get('/@:user', async ctx => {
|
||||
const { username, host } = parseAcct(ctx.params.user);
|
||||
const user = await User.findOne({
|
||||
usernameLower: username.toLowerCase(),
|
||||
host
|
||||
});
|
||||
|
||||
if (user != null) {
|
||||
await ctx.render('user', { user });
|
||||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
|
||||
// Note
|
||||
router.get('/notes/:note', async ctx => {
|
||||
const note = await Note.findOne({ _id: ctx.params.note });
|
||||
|
||||
if (note != null) {
|
||||
const _note = await packNote(note);
|
||||
await ctx.render('note', {
|
||||
note: _note,
|
||||
summary: getNoteSummary(_note)
|
||||
});
|
||||
} else {
|
||||
ctx.status = 404;
|
||||
}
|
||||
});
|
||||
//#endregion
|
||||
|
||||
// Render base html for all requests
|
||||
router.get('*', async ctx => {
|
||||
await send(ctx, `app/base.html`, {
|
||||
|
20
src/server/web/views/note.pug
Normal file
20
src/server/web/views/note.pug
Normal file
@ -0,0 +1,20 @@
|
||||
extends ../../../../src/client/app/base
|
||||
|
||||
block vars
|
||||
- const user = note.user;
|
||||
- const title = user.name ? `${user.name} (@${user.username})` : `@${user.username}`;
|
||||
- const url = `${config.url}/notes/${note.id}`;
|
||||
- const img = user.avatarId ? `${config.drive_url}/${user.avatarId}` : null;
|
||||
|
||||
block title
|
||||
= `${title} | Misskey`
|
||||
|
||||
block desc
|
||||
meta(name='description' content= summary)
|
||||
|
||||
block meta
|
||||
meta(name='twitter:card' content='summary')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= summary)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= img)
|
19
src/server/web/views/user.pug
Normal file
19
src/server/web/views/user.pug
Normal file
@ -0,0 +1,19 @@
|
||||
extends ../../../../src/client/app/base
|
||||
|
||||
block vars
|
||||
- const title = user.name ? `${user.name} (@${user.username})` : `@${user.username}`;
|
||||
- const url = config.url + '/@' + (user.host ? `${user.username}@${user.host}` : user.username);
|
||||
- const img = user.avatarId ? `${config.drive_url}/${user.avatarId}` : null;
|
||||
|
||||
block title
|
||||
= `${title} | Misskey`
|
||||
|
||||
block desc
|
||||
meta(name='description' content= user.description)
|
||||
|
||||
block meta
|
||||
meta(name='twitter:card' content='summary')
|
||||
meta(property='og:title' content= title)
|
||||
meta(property='og:description' content= user.description)
|
||||
meta(property='og:url' content= url)
|
||||
meta(property='og:image' content= img)
|
Reference in New Issue
Block a user