mirror of
https://github.com/BTMuli/TeyvatGuide.git
synced 2025-12-14 09:38:13 +08:00
fix(parser): 完善了一下
This commit is contained in:
@@ -6,6 +6,19 @@
|
||||
*/
|
||||
import { PostStructuredContent } from "../interface/post";
|
||||
|
||||
/**
|
||||
* @description 检测链接是否是米游社帖子
|
||||
* @since Alpha v0.1.1
|
||||
* @param {string} url 链接
|
||||
* @returns {boolean} 是否是米游社帖子
|
||||
*/
|
||||
export function IsMysPost(url: string): boolean {
|
||||
return (
|
||||
url.startsWith("https://bbs.mihoyo.com/ys/article/") ||
|
||||
url.startsWith("https://www.miyoushe.com/ys/article/")
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 解析Mys数据
|
||||
* @since Alpha v0.1.1
|
||||
@@ -106,7 +119,7 @@ function LinkTextParser(data: PostStructuredContent): HTMLSpanElement {
|
||||
const link = document.createElement("a");
|
||||
const link_url = data.attributes.link;
|
||||
link.classList.add("mys-post-link");
|
||||
if (link_url.startsWith("https://www.miyoushe.com/ys/article/")) {
|
||||
if (IsMysPost(link_url)) {
|
||||
link.href = "/post_detail/" + link_url.split("/").pop();
|
||||
link.target = "_self";
|
||||
} else {
|
||||
@@ -374,7 +387,7 @@ function LinkCardParser(data: PostStructuredContent): HTMLDivElement {
|
||||
button.classList.add("mys-post-link-card-btn");
|
||||
button.innerHTML = data.insert.link_card.button_text || "详情" + " >";
|
||||
const link_url = data.insert.link_card.origin_url;
|
||||
if (link_url.startsWith("https://www.miyoushe.com/ys/article/")) {
|
||||
if (IsMysPost(link_url)) {
|
||||
button.href = "/post_detail/" + link_url.split("/").pop();
|
||||
button.target = "_self";
|
||||
} else {
|
||||
|
||||
@@ -30,9 +30,15 @@ onMounted(async () => {
|
||||
}
|
||||
// 获取数据
|
||||
loadingTitle.value = "正在获取数据...";
|
||||
const postData = await MysOper.Post.get(post_id);
|
||||
loadingTitle.value = "正在渲染数据...";
|
||||
postHtml.value = MysOper.Post.parser(postData.post.structured_content);
|
||||
try {
|
||||
const postData = await MysOper.Post.get(post_id);
|
||||
loadingTitle.value = "正在渲染数据...";
|
||||
postHtml.value = MysOper.Post.parser(postData.post.structured_content);
|
||||
} catch (error) {
|
||||
loadingEmpty.value = true;
|
||||
loadingTitle.value = "帖子不存在或解析失败";
|
||||
return;
|
||||
}
|
||||
setInterval(() => {
|
||||
loading.value = false;
|
||||
}, 200);
|
||||
|
||||
Reference in New Issue
Block a user