Skip to content

Commit c56a7d3

Browse files
committed
内部链接使用 https
1 parent 84136ff commit c56a7d3

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/components/InnerLinkPreview.astro

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,9 @@
161161
bindEvents() {
162162
document.addEventListener('mouseover', (e: MouseEvent) => {
163163
// 检查链接是否在 main 标签内
164-
const link = (e.target as HTMLElement)?.closest('article a.inner-link') as HTMLAnchorElement | null
164+
const link = (e.target as HTMLElement)?.closest(
165+
'article a.inner-link'
166+
) as HTMLAnchorElement | null
165167
if (!link) return
166168

167169
// 忽略预览窗口内的链接
@@ -227,7 +229,7 @@
227229
if (!href) return
228230

229231
this.clearTimers()
230-
this.currentHref = href
232+
this.currentHref = href.replace('http://', 'https://');
231233

232234
if (this.gotoButton) {
233235
this.gotoButton.onclick = () => (window.location.href = href)
@@ -243,7 +245,7 @@
243245
const isExternalLink = !href.startsWith(window.location.origin) && !href.startsWith('/')
244246
if (isExternalLink) return
245247

246-
let contentHtml = await this.getPreviewContent(href)
248+
const contentHtml = await this.getPreviewContent(href)
247249
if (!contentHtml) return
248250

249251
if (this.currentTarget === link && this.content) {
@@ -425,14 +427,16 @@
425427

426428
setupThemeObserver() {
427429
// 监听系统主题变化
428-
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', async (e: MediaQueryListEvent) => {
429-
if (document.documentElement.dataset.theme === 'system') {
430-
await this.initializeMermaid()
431-
if (this.content) {
432-
await this.renderMermaidDiagrams(this.content)
430+
window
431+
.matchMedia('(prefers-color-scheme: dark)')
432+
.addEventListener('change', async (e: MediaQueryListEvent) => {
433+
if (document.documentElement.dataset.theme === 'system') {
434+
await this.initializeMermaid()
435+
if (this.content) {
436+
await this.renderMermaidDiagrams(this.content)
437+
}
433438
}
434-
}
435-
})
439+
})
436440

437441
// 监听主题切换
438442
const observer = new MutationObserver(async (mutations: MutationRecord[]) => {

0 commit comments

Comments
 (0)