主题
VitePress 链接前加图标
发表于
更新于
字数
阅读量
文内链接前加一个图标,展示当前链接的地址属于哪个网站。效果展示:
实现
利用伪元素及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/uil:link-alt.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 {
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://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: 3px;
margin-right: 3px;
background-image: url(https://api.iconify.design/logos/mdn.svg);
}
&[href^='https://cn.vite.dev']::before,
&[href^='https://vite.dev']::before {
background-image: url("https://cn.vite.dev/logo.svg");
}
&[href^='https://webpack.js']::before {
background-image: url(https://api.iconify.design/material-icon-theme/webpack.svg);
}
&[href^='https://vuejs.org']::before,
&[href^='https://cn.vuejs.org']::before {
background-image: url(https://api.iconify.design/material-icon-theme/vue.svg);
}
&[href^='https://twikoo.js.org']::before {
width: 16px;
height: 16px;
margin-left: 3px;
margin-right: 3px;
background-image: url("https://twikoo.js.org/twikoo-logo-mini.png");
}
&[href^='https://element-plus.org']::before,
&[href^='https://element.eleme.']::before {
width: 14px;
height: 16px;
margin-left: 2px;
margin-right: 4px;
background-image: url(https://api.iconify.design/logos/element.svg);
}
&[href^='https://nodejs.org']::before {
width: 34px;
height: 20px;
background-image: url(https://api.iconify.design/logos/nodejs.svg);
}
&[href^='https://npmjs.com']::before {
background-image: url(https://api.iconify.design/material-icon-theme/npm.svg);
}
&[href^='https://react.dev']::before {
background-image: url(https://api.iconify.design/material-icon-theme/react.svg);
}
&[href^='https://typescriptlang.org']::before {
width: 18px;
height: 18px;
margin-left: 1px;
margin-right: 3px;
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*='.siliconflow.cn']::before {
width: 16px;
height: 16px;
margin-left: 3px;
margin-right: 3px;
background-image: url(https://static01.siliconflow.cn/f/static/cn/logo.svg);
}
&[href^='https://code.visualstudio.com']::before {
width: 16px;
height: 16px;
margin-left: 3px;
margin-right: 3px;
background-image: url(https://api.iconify.design/logos:visual-studio-code.svg);
}
}
// 暗黑模式
.dark .vp-doc a {
&[href^='https://github.com']::before {
background-image: url(https://api.iconify.design/mdi/github.svg?color=%23d3d3d3);
}
}
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
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
然后将 css 注入主题配置
.vitepress/theme/index.ts
ts
// 导入链接样式
import './style/link.scss'
1
2
2