メタ情報をレンダリングするように
This commit is contained in:
parent
d9cdc1f079
commit
440cf139bb
|
@ -59,9 +59,15 @@ gulp.task('build:ts', () => {
|
||||||
.pipe(gulp.dest('./built/'));
|
.pipe(gulp.dest('./built/'));
|
||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('build:copy', () =>
|
gulp.task('build:copy:views', () =>
|
||||||
|
gulp.src('./src/server/web/views/**/*').pipe(gulp.dest('./built/server/web/views'))
|
||||||
|
);
|
||||||
|
|
||||||
|
gulp.task('build:copy', ['build:copy:views'], () =>
|
||||||
gulp.src([
|
gulp.src([
|
||||||
'./build/Release/crypto_key.node',
|
'./build/Release/crypto_key.node',
|
||||||
|
'./src/const.json',
|
||||||
|
'./src/server/web/views/**/*',
|
||||||
'./src/**/assets/**/*',
|
'./src/**/assets/**/*',
|
||||||
'!./src/client/app/**/assets/**/*'
|
'!./src/client/app/**/assets/**/*'
|
||||||
]).pipe(gulp.dest('./built/'))
|
]).pipe(gulp.dest('./built/'))
|
||||||
|
|
|
@ -58,6 +58,7 @@
|
||||||
"@types/koa-multer": "1.0.0",
|
"@types/koa-multer": "1.0.0",
|
||||||
"@types/koa-router": "7.0.28",
|
"@types/koa-router": "7.0.28",
|
||||||
"@types/koa-send": "4.1.1",
|
"@types/koa-send": "4.1.1",
|
||||||
|
"@types/koa-views": "^2.0.3",
|
||||||
"@types/koa__cors": "2.2.2",
|
"@types/koa__cors": "2.2.2",
|
||||||
"@types/kue": "0.11.8",
|
"@types/kue": "0.11.8",
|
||||||
"@types/license-checker": "15.0.0",
|
"@types/license-checker": "15.0.0",
|
||||||
|
@ -146,6 +147,7 @@
|
||||||
"koa-router": "7.4.0",
|
"koa-router": "7.4.0",
|
||||||
"koa-send": "4.1.3",
|
"koa-send": "4.1.3",
|
||||||
"koa-slow": "2.1.0",
|
"koa-slow": "2.1.0",
|
||||||
|
"koa-views": "^6.1.4",
|
||||||
"kue": "0.11.6",
|
"kue": "0.11.6",
|
||||||
"license-checker": "18.0.0",
|
"license-checker": "18.0.0",
|
||||||
"loader-utils": "1.1.0",
|
"loader-utils": "1.1.0",
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
block vars
|
||||||
|
|
||||||
doctype html
|
doctype html
|
||||||
|
|
||||||
!= '\n<!-- Thank you for using Misskey! @syuilo -->\n'
|
!= '\n<!-- Thank you for using Misskey! @syuilo -->\n'
|
||||||
|
@ -9,9 +11,17 @@ html
|
||||||
meta(name='application-name' content='Misskey')
|
meta(name='application-name' content='Misskey')
|
||||||
meta(name='theme-color' content=themeColor)
|
meta(name='theme-color' content=themeColor)
|
||||||
meta(name='referrer' content='origin')
|
meta(name='referrer' content='origin')
|
||||||
|
meta(property='og:site_name' content='Misskey')
|
||||||
link(rel='manifest' href='/manifest.json')
|
link(rel='manifest' href='/manifest.json')
|
||||||
|
|
||||||
title Misskey
|
title
|
||||||
|
block title
|
||||||
|
| Misskey
|
||||||
|
|
||||||
|
block desc
|
||||||
|
meta(name='description' content='A SNS')
|
||||||
|
|
||||||
|
block meta
|
||||||
|
|
||||||
style
|
style
|
||||||
include ./../../../built/client/assets/init.css
|
include ./../../../built/client/assets/init.css
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
* 投稿を表す文字列を取得します。
|
* 投稿を表す文字列を取得します。
|
||||||
* @param {*} note 投稿
|
* @param {*} note (packされた)投稿
|
||||||
*/
|
*/
|
||||||
const summarize = (note: any): string => {
|
const summarize = (note: any): string => {
|
||||||
if (note.isHidden) {
|
if (note.isHidden) {
|
||||||
|
|
|
@ -7,14 +7,32 @@ import * as Koa from 'koa';
|
||||||
import * as Router from 'koa-router';
|
import * as Router from 'koa-router';
|
||||||
import * as send from 'koa-send';
|
import * as send from 'koa-send';
|
||||||
import * as favicon from 'koa-favicon';
|
import * as favicon from 'koa-favicon';
|
||||||
|
import * as views from 'koa-views';
|
||||||
|
|
||||||
import docs from './docs';
|
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/`;
|
const client = `${__dirname}/../../client/`;
|
||||||
|
|
||||||
// Init app
|
// Init app
|
||||||
const app = new Koa();
|
const app = new Koa();
|
||||||
|
|
||||||
|
// Init renderer
|
||||||
|
app.use(views(__dirname + '/views', {
|
||||||
|
extension: 'pug',
|
||||||
|
options: {
|
||||||
|
config,
|
||||||
|
themeColor: consts.themeColor,
|
||||||
|
facss: fa.dom.css()
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
// Serve favicon
|
// Serve favicon
|
||||||
app.use(favicon(`${client}/assets/favicon.ico`));
|
app.use(favicon(`${client}/assets/favicon.ico`));
|
||||||
|
|
||||||
|
@ -67,6 +85,38 @@ router.use('/docs', docs.routes());
|
||||||
// URL preview endpoint
|
// URL preview endpoint
|
||||||
router.get('/url', require('./url-preview'));
|
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
|
// Render base html for all requests
|
||||||
router.get('*', async ctx => {
|
router.get('*', async ctx => {
|
||||||
await send(ctx, `app/base.html`, {
|
await send(ctx, `app/base.html`, {
|
||||||
|
|
|
@ -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)
|
|
@ -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)
|
Loading…
Reference in New Issue