1
0
mirror of https://github.com/andrigamerita/simpkey synced 2025-06-05 22:09:26 +02:00

mfm support

This commit is contained in:
Xeltica
2020-07-24 23:08:43 +09:00
parent f02516b372
commit 6f6cf5bb8f
5 changed files with 40 additions and 29 deletions

View File

@ -1,11 +1,20 @@
import config from './config';
import views from 'koa-views'; import views from 'koa-views';
import { parse, toHtml } from 'mfmf';
import { parsePlain } from 'mfmf/dist/script/mfm/parse';
import config from './config';
import { User } from './models/User'; import { User } from './models/User';
import { Note } from './models/Note'; import { Note } from './models/Note';
export const render = views(__dirname + '/views', { export const render = views(__dirname + '/views', {
extension: 'pug', options: { extension: 'pug', options: {
...config, ...config,
mfmToHtml: (text: string, plain = false) => {
return toHtml(plain ? parsePlain(text) : parse(text), [], {
url: '',
});
},
getAcct: (user: User) => user.host ? `@${user.username}@${user.host}` : `@${user.username}`, getAcct: (user: User) => user.host ? `@${user.username}@${user.host}` : `@${user.username}`,
getUserName: (user: User) => user.name || user.username, getUserName: (user: User) => user.name || user.username,
getVisibility: (note: Note) => { getVisibility: (note: Note) => {

View File

@ -7,6 +7,10 @@ html
meta(name="viewport", content="width=device-width, initial-scale=1.0") meta(name="viewport", content="width=device-width, initial-scale=1.0")
block meta block meta
title= title title= title
style.
body {
font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
}
body body
header header
h1: a(href="/") Simpkey h1: a(href="/") Simpkey
@ -21,5 +25,5 @@ html
| ・ | ・
a(href="/terms") 利用規約 a(href="/terms") 利用規約
p (C)2020 Xeltica - p (C)2020 Xeltica -
a(href="/about") version !{version} a(href="/about") version #{version}
block footer block footer

View File

@ -23,10 +23,10 @@ mixin sub-note(note)
p p
if note.cw if note.cw
details details
summary !{note.cw} (!{note.text.length}文字) summary #{note.cw} (#{note.text.length}文字)
!= note.text != mfmToHtml(note.text)
else else
!= note.text != mfmToHtml(note.text)
aside aside
span.visibility= getVisibility(note) span.visibility= getVisibility(note)
a.date(href="/notes/" + note.id)= new Date(note.createdAt).toLocaleString() a.date(href="/notes/" + note.id)= new Date(note.createdAt).toLocaleString()
@ -35,7 +35,7 @@ mixin note(note)
if note.reply if note.reply
+sub-note(note.reply)(style="opacity: 0.5") +sub-note(note.reply)(style="opacity: 0.5")
if note.renote && !note.text if note.renote && !note.text
p: b 🔁 !{getUserName(note.user)} がRenote p: b 🔁 #{getUserName(note.user)} がRenote
+note(note.renote) +note(note.renote)
else else
.note&attributes(attributes) .note&attributes(attributes)
@ -46,10 +46,10 @@ mixin note(note)
| ↩ | ↩
if note.cw if note.cw
details details
summary !{note.cw} (!{note.text.length}文字) summary #{note.cw} (#{note.text.length}文字)
!= note.text != mfmToHtml(note.text)
else else
!= note.text != mfmToHtml(note.text)
if note.renote if note.renote
p RN: p RN:
+sub-note(note.renote) +sub-note(note.renote)
@ -61,11 +61,11 @@ mixin note(note)
span(class=(key === note.myReaction ? 'my reaction' : 'reaction'))=`${key} ${val}` span(class=(key === note.myReaction ? 'my reaction' : 'reaction'))=`${key} ${val}`
footer footer
|[ |[
a(href="/reply/" + note.id) リプライ !{note.repliesCount} a(href="/reply/" + note.id) リプライ #{note.repliesCount}
|] |]
if canRenote && canRenote(note) if canRenote && canRenote(note)
|[ |[
a(href="/renote/" + note.id) リノート !{note.renoteCount} a(href="/renote/" + note.id) リノート #{note.renoteCount}
|] |]
if canReact && canReact(note) if canReact && canReact(note)
if !note.myReaction if !note.myReaction
@ -138,28 +138,26 @@ mixin user-header(user, detail = false)
span.bot [CAT] span.bot [CAT]
if detail if detail
if user.description if user.description
.description= user.description .description !{mfmToHtml(user.description)}
if user.birthday if user.birthday
.birthday 🎂 !{user.birthday} .birthday 🎂 #{user.birthday}
if user.location if user.location
.birthday 📍!{user.location} .birthday 📍#{user.location}
if user.sex if user.sex
.sex 性別: !{user.sex} .sex 性別: #{user.sex}
if user.sex
.sex 性別: !{user.sex}
dl dl
each field in user.fields each field in user.fields
dt= field.name dt= mfmToHtml(field.name)
dd= field.value dd= mfmToHtml(field.value)
.count .count
a.notes(href="/" + getAcct(user)) !{user.notesCount} ノート a.notes(href="/" + getAcct(user)) #{user.notesCount} ノート
| |
//- a.following(href="/" + getAcct(user) + "/following") //- a.following(href="/" + getAcct(user) + "/following")
| !{user.followingCount} フォロー | #{user.followingCount} フォロー
| |
//- a.followers(href="/" + getAcct(user) + "/followers") //- a.followers(href="/" + getAcct(user) + "/followers")
| !{user.followersCount} フォロワー | #{user.followersCount} フォロワー
mixin timeline(notes) mixin timeline(notes)
each note in notes each note in notes

View File

@ -2,7 +2,7 @@ extends _base
block content block content
p Simpkey は、JavaScript のいらない Misskey クライアントです。 p Simpkey は、JavaScript のいらない Misskey クライアントです。
h2 バージョン !{version} h2 バージョン #{version}
ul ul
each val in changelog each val in changelog
li= val li= val

View File

@ -11,23 +11,23 @@ block content
hr hr
case val.type case val.type
when 'follow' when 'follow'
p !{getUserName(val.user)} さんにフォローされました p #{getUserName(val.user)} さんにフォローされました
when 'mention' when 'mention'
when 'reply' when 'reply'
when 'renote' when 'renote'
when 'quote' when 'quote'
+note(val.note) +note(val.note)
when 'reaction' when 'reaction'
p !{getUserName(val.user)} さんが !{val.reaction} とリアクションしました p #{getUserName(val.user)} さんが #{val.reaction} とリアクションしました
+sub-note(val.note) +sub-note(val.note)
when 'pollVote' when 'pollVote'
p !{getUserName(val.user)} さんが投票しました p #{getUserName(val.user)} さんが投票しました
+sub-note(val.note) +sub-note(val.note)
when 'receiveFollowRequest' when 'receiveFollowRequest'
p !{getUserName(val.user)} さんからフォローリクエストされました p #{getUserName(val.user)} さんからフォローリクエストされました
when 'followRequestAccepted' when 'followRequestAccepted'
p !{getUserName(val.user)} さんへのフォローが承認されました p #{getUserName(val.user)} さんへのフォローが承認されました
when 'groupInvited' when 'groupInvited'
when 'app' when 'app'
default default
p !{val.type} 通知(未実装) p #{val.type} 通知(未実装)