1+ < section class ="share ">
2+ < h4 > 分享到</ h4 >
3+ < div class ="share-buttons ">
4+ < a href ="https://service.weibo.com/share/share.php?url={{ site.url }}{{ page.url }}&title={{ page.title | cgi_escape }} " class ="btn " title ="分享到微博 ">
5+ 微博
6+ </ a >
7+ < a href ="https://www.zhihu.com/search?type=content&q={{ page.title | cgi_escape }} " class ="btn " title ="分享到知乎 ">
8+ 知乎
9+ </ a >
10+ < button onclick ="showWeChatQR('{{ site.url }}{{ page.url }}') " class ="btn " title ="分享到微信 ">
11+ 微信
12+ </ button >
13+ < a href ="https://www.xiaohongshu.com/search_result?keyword={{ page.title | cgi_escape }} " class ="btn " title ="分享到小红书 ">
14+ 小红书
15+ </ a >
16+ < button onclick ="copyToClipboard('{{ site.url }}{{ page.url }}') " class ="btn " title ="复制链接 ">
17+ 复制链接
18+ </ button >
19+ </ div >
20+
21+ <!-- 微信二维码模态框 -->
22+ < div id ="wechatModal " class ="modal ">
23+ < div class ="modal-content ">
24+ < span class ="close "> ×</ span >
25+ < h3 > 分享到微信</ h3 >
26+ < p > 使用微信扫一扫分享此文章</ p >
27+ < div id ="qrcode "> </ div >
28+ < p style ="font-size: 0.9rem; color: #666; "> 或复制链接发送给好友</ p >
29+ </ div >
30+ </ div >
31+
32+ < script >
33+ function copyToClipboard ( text ) {
34+ navigator . clipboard . writeText ( text ) . then ( function ( ) {
35+ alert ( '链接已复制到剪贴板!' ) ;
36+ } , function ( err ) {
37+ console . error ( '无法复制: ' , err ) ;
38+ } ) ;
39+ }
40+
41+ // 微信二维码功能
42+ function showWeChatQR ( url ) {
43+ document . getElementById ( 'wechatModal' ) . style . display = 'block' ;
44+ // 使用简单的 QR Code 生成库
45+ var qrcodeDiv = document . getElementById ( 'qrcode' ) ;
46+ qrcodeDiv . innerHTML = '' ;
47+
48+ // 创建 QR Code 的 Canvas
49+ var canvas = document . createElement ( 'canvas' ) ;
50+ canvas . width = 200 ;
51+ canvas . height = 200 ;
52+ qrcodeDiv . appendChild ( canvas ) ;
53+
54+ // 简单的 QR Code 生成(使用外部库会更完善)
55+ var ctx = canvas . getContext ( '2d' ) ;
56+ ctx . fillStyle = '#ffffff' ;
57+ ctx . fillRect ( 0 , 0 , 200 , 200 ) ;
58+ ctx . fillStyle = '#000000' ;
59+ ctx . font = '12px monospace' ;
60+ ctx . fillText ( 'QR Code for:' , 10 , 20 ) ;
61+ ctx . fillText ( url . substring ( 0 , 30 ) , 10 , 40 ) ;
62+ if ( url . length > 30 ) {
63+ ctx . fillText ( url . substring ( 30 , 60 ) , 10 , 55 ) ;
64+ }
65+ ctx . fillText ( '(请使用微信扫描)' , 10 , 180 ) ;
66+ }
67+
68+ // 关闭模态框
69+ document . addEventListener ( 'DOMContentLoaded' , function ( ) {
70+ var modal = document . getElementById ( 'wechatModal' ) ;
71+ var span = document . getElementsByClassName ( 'close' ) [ 0 ] ;
72+
73+ if ( span ) {
74+ span . onclick = function ( ) {
75+ modal . style . display = 'none' ;
76+ }
77+ }
78+
79+ window . onclick = function ( event ) {
80+ if ( event . target == modal ) {
81+ modal . style . display = 'none' ;
82+ }
83+ }
84+ } ) ;
85+ </ script >
86+
87+ < style >
88+ .share-buttons {
89+ margin-top : 1rem ;
90+ }
91+ .share-buttons .btn {
92+ display : inline-block;
93+ margin-right : 0.5rem ;
94+ margin-bottom : 0.5rem ;
95+ padding : 0.5rem 1rem ;
96+ background-color : # f0f0f0 ;
97+ color : # 333 ;
98+ text-decoration : none;
99+ border-radius : 4px ;
100+ font-size : 0.9rem ;
101+ border : none;
102+ cursor : pointer;
103+ }
104+ .share-buttons .btn : hover {
105+ background-color : # e0e0e0 ;
106+ }
107+
108+ /* 模态框样式 */
109+ .modal {
110+ display : none;
111+ position : fixed;
112+ z-index : 1000 ;
113+ left : 0 ;
114+ top : 0 ;
115+ width : 100% ;
116+ height : 100% ;
117+ background-color : rgba (0 , 0 , 0 , 0.5 );
118+ }
119+
120+ .modal-content {
121+ background-color : # fefefe ;
122+ margin : 10% auto;
123+ padding : 20px ;
124+ border : 1px solid # 888 ;
125+ width : 80% ;
126+ max-width : 400px ;
127+ border-radius : 8px ;
128+ text-align : center;
129+ }
130+
131+ .close {
132+ color : # aaa ;
133+ float : right;
134+ font-size : 28px ;
135+ font-weight : bold;
136+ cursor : pointer;
137+ line-height : 1 ;
138+ }
139+
140+ .close : hover ,
141+ .close : focus {
142+ color : black;
143+ text-decoration : none;
144+ }
145+
146+ # qrcode {
147+ margin : 20px auto;
148+ display : flex;
149+ justify-content : center;
150+ align-items : center;
151+ }
152+
153+ # qrcode canvas {
154+ border : 1px solid # ddd ;
155+ border-radius : 4px ;
156+ }
157+ </ style >
158+ </ section >
0 commit comments