主题
VitePress 链接前加图标
发表于
更新于
字数
阅读量
文内链接前加一个图标,展示当前链接的地址属于哪个网站。效果展示:
VitePress 官方文档
VitePress 建站资源汇总
Github - weizwz
实现
利用伪元素及iconify在线图标,纯css即可实现
docs/.vitepress/theme/style/link.scss
scss
/* 链接 */
.vp-doc a:not([href^='https://img.shields.io/']) {
&[target='_blank'],
&[href^='./'],
&[href^='../'] {
&::before {
content: "";
background-image: url(https://api.iconify.design/heroicons-solid:link.svg?color=%23409eff);
width: 20px;
height: 20px;
display: inline-block;
vertical-align: middle;
position: relative;
background-size: cover;
top: -2px;
margin-right: 2px;
}
}
&[href^='./']::before,
&[href^='../']::before,
&[href^='https://note.weizwz.com']::before,
&[href^='https://www.note.weizwz.com']::before {
background-image: url("https://p.weizwz.com/logo_a4353391cbf0889b.webp");
}
&[href^='https://vitepress.dev']::before {
background-image: url("https://vitepress.dev/vitepress-logo-mini.svg");
}
&[href^='https://hexo.io']::before {
width: 16px;
height: 18px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:hexo.svg);
}
&[href^='https://git-scm.com']::before {
width: 18px;
height: 18px;
margin-left: 1px;
margin-right: 3px;
background-image: url(https://api.iconify.design/logos:git.svg);
}
&[href^='https://github.com']::before {
background-image: url(https://api.iconify.design/mdi:github.svg);
}
&[href^='https://gitee.com']::before {
width: 18px;
height: 18px;
margin-left: 1px;
margin-right: 3px;
background-image: url(https://api.iconify.design/simple-icons:gitee.svg?color=%23C71E23);
}
&[href^='https://developer.mozilla.org']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos/mdn.svg);
}
&[href^='https://cn.vite.dev']::before,
&[href^='https://vite.dev']::before {
width: 18px;
height: 18px;
margin-left: 1px;
margin-right: 3px;
background-image: url(https://api.iconify.design/logos:vitejs.svg);
}
&[href^='https://webpack.js']::before {
background-image: url(https://api.iconify.design/devicon:webpack.svg);
}
&[href^='https://vuejs.org']::before,
&[href^='https://cn.vuejs.org']::before {
width: 18px;
height: 16px;
margin: 2px 3px 0 1px;
background-image: url(https://api.iconify.design/logos/vue.svg);
}
&[href^='https://twikoo.js.org']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url("https://twikoo.js.org/twikoo-logo-mini.png");
}
&[href^='https://element-plus.org']::before,
&[href^='https://element.eleme.cn']::before {
width: 16px;
height: 18px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:element.svg);
}
&[href^='https://nodejs.org']::before {
width: 16px;
height: 18px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:nodejs-icon.svg);
}
&[href^='https://npmjs.com']::before,
&[href^='https://www.npmjs.com']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:npm-icon.svg);
}
&[href^='https://pnpm.io']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:pnpm.svg);
}
&[href^='https://react.dev']::before {
width: 20px;
height: 18px;
background-image: url(https://api.iconify.design/logos:react.svg);
}
&[href^='https://typescriptlang.org']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:typescript-icon.svg);
}
&[href^='https://uniapp.dcloud.net.cn']::before {
background-image: url(https://api.iconify.design/mynaui/letter-u-square-solid.svg?color=%232D8E3B);
}
&[href*='https://siliconflow.cn']::before,
&[href*='https://cloud.siliconflow.cn']::before,
&[href*='https://docs.siliconflow.cn']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://static01.siliconflow.cn/f/static/cn/logo.svg);
}
&[href*='https://www.deepseek.com']::before,
&[href*='https://platform.deepseek.com']::before,
&[href*='https://chat.deepseek.com']::before,
&[href*='https://api-docs.deepseek.com']::before {
width: 18px;
height: 14px;
margin-left: 1px;
margin-right: 3px;
background-image: url(https://cdn.deepseek.com/logo.png?x-image-process=image%2Fresize%2Cw_1920);
}
&[href^='https://code.visualstudio.com']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:visual-studio-code.svg);
}
&[href^='https://marketplace.visualstudio.com']::before,
&[href^='https://learn.microsoft.com']::before,
&[href^='https://www.microsoft.com']::before,
&[href^='https://support.microsoft.com']::before,
&[href^='https://microsoftedge.microsoft.com']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:microsoft-icon.svg);
}
&[href^='https://support.google.com']::before,
&[href^='https://www.google.com']::before {
width: 16px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:google-icon.svg);
}
&[href^='https://chromewebstore.google.com']::before,
&[href^='https://chrome.google.com']::before,
&[href^='https://www.google.com/chrome']::before {
width: 18px;
height: 18px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos:chrome.svg);
}
&[href^='https://mp.weixin.qq.com']::before,
&[href^='https://open.weixin.qq.com']::before,
&[href^='https://developers.weixin.qq.com']::before {
width: 18px;
height: 18px;
margin-right: 4px;
background-image: url(https://api.iconify.design/simple-icons:wechat.svg?color=%231AAD1A);
}
}
// 暗黑模式
.dark .vp-doc a {
&[target='_blank'],
&[href^='./'],
&[href^='../'] {
&::before {
filter: brightness(.8);
}
}
&[href^='https://github.com']::before {
background-image: url(https://api.iconify.design/mdi/github.svg?color=%23fff);
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
然后将 css 注入主题配置
.vitepress/theme/index.ts
ts
// 导入链接样式
import './style/link.scss'
1
2
2
统一性调试
https://default.link.com
https://note.weizwz.com
https://vitepress.dev
https://hexo.io
https://git-scm.com
https://github.com
https://gitee.com
https://developer.mozilla.org
https://vite.dev
https://webpack.js
https://vuejs.org
https://twikoo.js.org
https://element-plus.org
https://nodejs.org
https://npmjs.com
https://pnpm.io
https://react.dev
https://typescriptlang.org
https://uniapp.dcloud.net.cn
https://siliconflow.cn
https://www.deepseek.com
https://code.visualstudio.com
https://marketplace.visualstudio.com
https://www.google.com
https://chrome.google.com
https://mp.weixin.qq.com