fix(parser): 完善了一下

This commit is contained in:
BTMuli
2023-03-31 00:27:32 +08:00
parent c2af95920f
commit f09a474d07
2 changed files with 24 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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);