-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCiteThisNote.misskeyplugin
More file actions
110 lines (99 loc) · 4.22 KB
/
Copy pathCiteThisNote.misskeyplugin
File metadata and controls
110 lines (99 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/// @ 1.2.1
### {
name: "CiteThisNote"
version: "3.0.0"
author: "@KawaneRio@misskey.io"
description: "Misskeyでの投稿を參考文獻として引用したいときなど用に、BibLaTeX形式でノートのメタデータを出力します。CiteThisNote is a free Misskey Plugin that allows you to obtain all the necessary information you need to reference or \"Cite\" a note in a neat `BibLaTex` citation format."
permissions: []
config: {}
}
//////////////////////////////// 主關 Main Function
let CiteThisNoteAction = @(notes){
var noteCreatedAt = `{notes.createdAt}` // ノートが生成された日時
var noteCreatedAtUnix = Date:parse(noteCreatedAt) //ノート生成日時をUnix通秒にする
var noteCreatedAtYear = Date:year(noteCreatedAtUnix) //ノート生成年を計算する
var currentYear = Date:year()
var currentMonth = Date:month()
var currentDay = Date:day()
var siteName = Mk:api("meta",{}).name
//しせるにゃんの助言を基にノートのURLを生成
//ありがとうしせるにゃんにゃん♥️ https://misskey.io/notes/9lhy3ug03g
//追記:改變は山田結城氏の助言を參考にした https://misskey.io/notes/9lkt7p500p
//再追記:にゃんかAPIに負荷をかけるのはよくないらしいので、
//APIを使はずにMk:url()を改變した、しせるにゃんの殊をここにて使用する
// https://misskey.io/notes/9lkv102djq
var curentURL = Mk:url().split('/').slice(0,3).join('/')
// var metaURI = Mk:api("meta",{}).uri
var noteURL = `{curentURL}/notes/{notes.id}`
// var noteURL = `{Mk:url()}`
// @username@example.com の example.com部分。
//ここは紗々さんから教へてもらふた https://misskey.io/notes/9lhsh1umas
var SERVER_NAME = Mk:url().split('/')[2]
//地元鯖が初期値として入ってる仕組み
var noteUserHost = `{SERVER_NAME}`
var noteURI = ""
//notes.user.hostがnull以外だと{notes.user.host}を入れる
//このif文はしせるにゃんの助言 https://misskey.io/notes/9lgj0l6d02 を基にした
if (notes.user.host != null) {
noteUserHost = `{notes.user.host}`
noteURI = `{notes.uri}`
}
//ここから文件の處理
var noteFileNameArray = []
var noteFileCommentArray = []
var noteFileURLArray = []
var noteFileMD5Array = []
//もしnotes.filesが空の場合 ここは無視される氣がする
//もしnotes.filesが空っぽじゃなかったら
//notes.filesの要素回數分だけこの殊塊を周す
//1周每にnoteFile*Arrayの中へ[file].*の要素をpushする
//ここは特に紗々@salano_ym氏の助言を參考にした
// https://misskey.io/notes/9ljwy62lqa
each let file, notes.files {
noteFileNameArray.push(file.name)
noteFileCommentArray.push(file.comment)
noteFileURLArray.push(file.url)
noteFileMD5Array.push(file.md5)
}
var noteFileNameArrayJoined = noteFileNameArray.join(", ")
var noteFileCommentArrayJoined = noteFileCommentArray.join("},{")
var noteFileURLArrayJoined = noteFileURLArray.join(", ")
var noteFileMD5ArrayJoined = noteFileMD5Array.join(", ")
// ```の越化字列 threeBackTick Escape Sequence
// notes.text内に```があったら取り除く
// もし notes.text が null じゃなかったら、replaceをしてほしい
var threeBackticks = "```"
var noteTextNoCodeBlock = ""
if (notes.text != null) {
noteTextNoCodeBlock = notes.text.replace(threeBackticks, "")
}
//////////////// 対録 Dialog
Mk:dialog("BibLaTeX Citation",
`
\`\`\`
@online\{{notes.user.username}_{noteCreatedAtUnix},
title = \{\{{notes.user.name}@{notes.user.username}\}の投稿\},
url = \{{noteURL}\},
abstract = \{\{{noteTextNoCodeBlock}\}\},
titleaddon = \{{siteName}\},
type = \{microblogging\},
author = \{@{notes.user.username}@{noteUserHost}\},
urldate = \{{Date:year()}-{Date:month()}-{Date:day()}\},
date = \{{notes.createdAt}\},
keywords = \{{notes.tags}\},
note = \{
filename = \{{noteFileNameArrayJoined}\},
filecomment = \{\{{noteFileCommentArrayJoined}\}\},
fileurl = \{{noteFileURLArrayJoined}\},
filemd5 = \{{noteFileMD5ArrayJoined}\},
uri = \{{noteURI}\},
currenturldate = \{{Date:now()}\}
\}
\}
\`\`\`
`
)
}
//////////////////////////////// 主關數ここまで
// ノートに Plugin の品書きを接ぎ足す
Plugin:register_note_action("このノートを引用する", CiteThisNoteAction)