refactor: 清理未使用的源码片段

This commit is contained in:
2026-08-02 11:32:39 +08:00
parent bcec8512f4
commit 04df078fcf
6 changed files with 9 additions and 45 deletions
+9 -15
View File
@@ -276,7 +276,6 @@ const isMobile = computed(() => screenWidth.value <= 900);
// 学习材料 Markdown 预览
const showPreview = ref(false);
const materialPreview = ref("");
const previewLoading = ref(false);
const escapeHtml = (s: string) => s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
const escapeAttr = (s: string) => s.replace(/"/g, "&quot;").replace(/&/g, "&amp;");
@@ -312,20 +311,15 @@ async function previewMaterial() {
showPreview.value = true;
const raw = materialUrl.value || "";
if (!raw.trim()) { materialPreview.value = ""; return; }
previewLoading.value = true;
try {
const titles: Record<string, string> = {};
const bareUrls = new Set<string>();
raw.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
bareUrls.add(url.replace(/[.。,;!??)】」』\]]+$/, ""));
return url;
});
const results = await Promise.all([...bareUrls].map(async (u) => ({ u, t: await getUrlTitle(u) })));
results.forEach(({ u, t }) => { titles[u] = t; });
materialPreview.value = renderMarkdown(raw, titles);
} finally {
previewLoading.value = false;
}
const titles: Record<string, string> = {};
const bareUrls = new Set<string>();
raw.replace(/https?:\/\/[^\s)\u3001\uFF09\u300D\u300B<>]+/g, (url) => {
bareUrls.add(url.replace(/[.。,;!??)】」』\]]+$/, ""));
return url;
});
const results = await Promise.all([...bareUrls].map(async (u) => ({ u, t: await getUrlTitle(u) })));
results.forEach(({ u, t }) => { titles[u] = t; });
materialPreview.value = renderMarkdown(raw, titles);
}
</script>