Skip to content

Commit e3368f7

Browse files
authored
添加对文本片段(Text Fragment)链接的跳转支持 (#235)
* 添加对文本片段(Text Fragment)链接的跳转支持 * 通过文本片段将首页features卡片链接到更准确的地方
1 parent d423fb3 commit e3368f7

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

.vitepress/theme/index.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ import Layout from './layout.vue'
88
import '@theojs/lumen/theme'
99
import '@theojs/lumen/doc-blocks-border'
1010

11+
/**
12+
* Add noopener to links with text fragments
13+
*/
14+
function initNoopenerLinks() {
15+
if (typeof window === 'undefined')
16+
return
17+
18+
const processLinks = () => {
19+
document.querySelectorAll('a').forEach((link) => {
20+
const href = link.getAttribute('href')
21+
// Add noopener to links with text fragments
22+
if (href && href.includes(':~:text=')) {
23+
const rel = link.getAttribute('rel') || ''
24+
if (!rel.includes('noopener')) {
25+
const newRel = rel ? `${rel} noopener` : 'noopener'
26+
link.setAttribute('rel', newRel.trim())
27+
}
28+
const target = link.getAttribute('target') || ''
29+
if (!target) {
30+
link.setAttribute('target', '_blank')
31+
}
32+
}
33+
})
34+
}
35+
36+
// Process links on load
37+
if (document.readyState === 'loading') {
38+
document.addEventListener('DOMContentLoaded', processLinks)
39+
}
40+
else {
41+
processLinks()
42+
}
43+
44+
// Process dynamically added links
45+
const observer = new MutationObserver(processLinks)
46+
observer.observe(document.body, {
47+
childList: true,
48+
subtree: true,
49+
})
50+
}
51+
1152
export default {
1253
extends: DefaultTheme,
1354
Layout,
@@ -17,6 +58,8 @@ export default {
1758
baiduAnalytics({ baiduId: '0afa8cd5bd78fd0c960f8af5dc6af333' })
1859
if (typeof window !== 'undefined') {
1960
trackPageview('0afa8cd5bd78fd0c960f8af5dc6af333', window.location.href)
61+
// Initialize noopener for text fragment links
62+
initNoopenerLinks()
2063
}
2164

2265
app.component('Home', HomeUnderline)

en/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ features:
3131
details: Supports Win / MacOS / Linux / FreeBSD / Android<br>Compatible with X86 / ARM / MIPS architectures
3232
link: /en/guide/download
3333
- title: Secure
34-
details: AES-GCM or WireGuard encryption<br>Prevents man-in-the-middle attacks
35-
link: /
34+
details: Multiple encryption algorithms including AES-GCM or WireGuard encryption<br>Prevents man-in-the-middle attacks
35+
link: /en/guide/network/configurations#:~:text=encryption%20algorithm&text=ET_ENCRYPTION_ALGORITHM
3636
- title: Efficient NAT Traversal
3737
details: Supports UDP, IPv6 traversal<br>Can penetrate NAT4-NAT4 networks
38-
link: /
38+
link: /en/guide/aboutp2p
3939
- title: Subnet Proxy
4040
details: Nodes can share subnets for other nodes to access.
4141
link: /en/guide/network/point-to-networking
4242
- title: Intelligent Routing
4343
details: Latency priority, automatic route selection<br>Provides the best network experience
44-
link: /en/guide/network/configurations
44+
link: /en/guide/network/configurations#:~:text=latency%20priority%20mode&text=ET_LATENCY_FIRST
4545
- title: High Performance
46-
details: Zero-copy throughout the entire link<br>Supports TCP / UDP / WSS / WG and other protocols
46+
details: Zero-copy throughout the entire link<br>Supports TCP / UDP / WS / WSS / WG / QUIC / FakeTCP and other protocols
4747
link: /en/guide/perf
4848
- title: UDP Loss Resistance
4949
details: KCP / QUIC proxy<br>Optimizes latency and bandwidth in high packet loss environments

index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,19 @@ features:
3131
details: 支持 Win / MacOS / Linux / FreeBSD / Android<br>兼容 X86 / ARM / MIPS 架构
3232
link: /guide/download
3333
- title: 安全
34-
details: AES-GCM 或 WireGuard 加密<br>防止中间人攻击
35-
link: /
34+
details: 支持 AES-GCM 等多种加密算法 或 WireGuard 加密<br>防止中间人攻击
35+
link: /guide/network/configurations#:~:text=加密算法&text=ET_ENCRYPTION_ALGORITHM
3636
- title: 高效 NAT 穿透
3737
details: 支持 UDP、IPv6 穿透<br>可打通 NAT4-NAT4 网络
38-
link: /
38+
link: /guide/aboutp2p
3939
- title: 子网代理
4040
details: 节点可共享子网供其他节点访问。
4141
link: /guide/network/point-to-networking
4242
- title: 智能路由
4343
details: 延迟优先,自动选路<br>提供最佳网络体验
44-
link: /guide/network/configurations
44+
link: /guide/network/configurations#:~:text=延迟优先模式&text=ET_LATENCY_FIRST
4545
- title: 高性能
46-
details: 全链路零拷贝<br>支持 TCP / UDP / WSS / WG 等协议
46+
details: 全链路零拷贝<br>支持 TCP / UDP / WS / WSS / WG / QUIC / FakeTCP 等协议
4747
link: /guide/perf
4848
- title: 抗 UDP 丢包
4949
details: KCP / QUIC 代理<br>优化高丢包环境下的延迟和带宽

0 commit comments

Comments
 (0)