mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-16 09:58:13 +08:00
✨ fix(parser): 添加 insert.mention 解析
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
* @file plugins Mys interface post.ts
|
* @file plugins Mys interface post.ts
|
||||||
* @description Mys 插件帖子接口
|
* @description Mys 插件帖子接口
|
||||||
* @author BTMuli<bt-muli@outlook.com>
|
* @author BTMuli<bt-muli@outlook.com>
|
||||||
* @since Alpha v0.1.1
|
* @since Alpha v0.1.2
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { type MysResponse } from "./base";
|
import { type MysResponse } from "./base";
|
||||||
@@ -242,7 +242,7 @@ export interface PostContent {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 帖子结构化内容
|
* @description 帖子结构化内容
|
||||||
* @since Alpha v0.1.1
|
* @since Alpha v0.1.2
|
||||||
* @interface PostStructuredContent
|
* @interface PostStructuredContent
|
||||||
* @property {string|object} insert 插入内容
|
* @property {string|object} insert 插入内容
|
||||||
* @property {string} insert.image 图片 URL
|
* @property {string} insert.image 图片 URL
|
||||||
@@ -257,6 +257,9 @@ export interface PostContent {
|
|||||||
* @property {string} insert.fold.content 折叠文本,反序列化后为 PostStructuredContent[]
|
* @property {string} insert.fold.content 折叠文本,反序列化后为 PostStructuredContent[]
|
||||||
* @property {PostStructuredContentLinkCard} insert.link_card 链接卡片
|
* @property {PostStructuredContentLinkCard} insert.link_card 链接卡片
|
||||||
* @property {string} insert.divider 分割线
|
* @property {string} insert.divider 分割线
|
||||||
|
* @property {object} insert.mention 提及
|
||||||
|
* @property {string} insert.mention.uid 用户 ID
|
||||||
|
* @property {string} insert.mention.nickname 用户昵称
|
||||||
* @property {object} attributes 属性
|
* @property {object} attributes 属性
|
||||||
* @property {number} attributes.height 高度
|
* @property {number} attributes.height 高度
|
||||||
* @property {number} attributes.width 宽度
|
* @property {number} attributes.width 宽度
|
||||||
@@ -268,6 +271,7 @@ export interface PostContent {
|
|||||||
* @returns {PostStructuredContent}
|
* @returns {PostStructuredContent}
|
||||||
*/
|
*/
|
||||||
export interface PostStructuredContent {
|
export interface PostStructuredContent {
|
||||||
|
|
||||||
insert:
|
insert:
|
||||||
| {
|
| {
|
||||||
image?: string
|
image?: string
|
||||||
@@ -284,6 +288,10 @@ export interface PostStructuredContent {
|
|||||||
}
|
}
|
||||||
link_card?: PostStructuredContentLinkCard
|
link_card?: PostStructuredContentLinkCard
|
||||||
divider?: string
|
divider?: string
|
||||||
|
mention?: {
|
||||||
|
uid: string
|
||||||
|
nickname: string
|
||||||
|
}
|
||||||
}
|
}
|
||||||
| string
|
| string
|
||||||
attributes?: {
|
attributes?: {
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ export function PostParser (post: PostData): string {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @description 解析中转
|
* @description 解析中转
|
||||||
* @since Alpha v0.1.1
|
* @since Alpha v0.1.2
|
||||||
* @param {PostStructuredContent} data Mys数据
|
* @param {PostStructuredContent} data Mys数据
|
||||||
* @returns {HTMLDivElement | HTMLSpanElement} 解析后的中转
|
* @returns {HTMLDivElement | HTMLSpanElement} 解析后的中转
|
||||||
*/
|
*/
|
||||||
@@ -118,6 +118,8 @@ function ParserTransfer (data: PostStructuredContent): HTMLDivElement | HTMLSpan
|
|||||||
return LinkCardParser(data);
|
return LinkCardParser(data);
|
||||||
} else if (data.insert.divider) {
|
} else if (data.insert.divider) {
|
||||||
return DividerParser(data);
|
return DividerParser(data);
|
||||||
|
} else if (data.insert.mention) {
|
||||||
|
return MentionParser(data);
|
||||||
} else {
|
} else {
|
||||||
return UnknownParser(data);
|
return UnknownParser(data);
|
||||||
}
|
}
|
||||||
@@ -483,3 +485,31 @@ function LinkCardParser (data: PostStructuredContent): HTMLDivElement {
|
|||||||
div.classList.add("mys-post-link-card");
|
div.classList.add("mys-post-link-card");
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description 解析 Mention
|
||||||
|
* @since Alpha v0.1.2
|
||||||
|
* @param {PostStructuredContent} data Mys数据
|
||||||
|
* @returns {HTMLAnchorElement} 解析后的 Mention
|
||||||
|
*/
|
||||||
|
function MentionParser (data: PostStructuredContent): HTMLAnchorElement {
|
||||||
|
// 检查数据
|
||||||
|
if (typeof data.insert === "string") {
|
||||||
|
throw new Error("data.insert is a string");
|
||||||
|
}
|
||||||
|
if (!data.insert.mention) {
|
||||||
|
throw new Error("data.insert.mention is not defined");
|
||||||
|
}
|
||||||
|
// 创建图标
|
||||||
|
const icon = document.createElement("i");
|
||||||
|
icon.classList.add("mdi", "mdi-account-circle-outline");
|
||||||
|
// 创建链接
|
||||||
|
const link = document.createElement("a");
|
||||||
|
link.classList.add("mys-post-link");
|
||||||
|
link.href = `https://www.miyoushe.com/ys/accountCenter/postList?id=${data.insert.mention.uid}`;
|
||||||
|
link.target = "_blank";
|
||||||
|
link.innerText = data.insert.mention.nickname;
|
||||||
|
// 插入图标
|
||||||
|
link.prepend(icon);
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user