@@ -30,6 +30,8 @@ pub struct BlogConf {
30
30
giscus : Option < Giscus > ,
31
31
google_analytics : Option < GoogleAnalytics > ,
32
32
syntax_highlight : Option < bool > ,
33
+ facebook : Option < String > , // Facebook sharing link
34
+ twitter_share : Option < String > , // Twitter sharing link
33
35
}
34
36
35
37
#[ derive( Debug , Deserialize , Serialize ) ]
@@ -126,6 +128,25 @@ impl Blog {
126
128
pub fn get_current_year ( & self ) -> i32 {
127
129
Utc :: now ( ) . year ( )
128
130
}
131
+
132
+ // Generate sharing links for Facebook and Twitter
133
+ pub fn generate_facebook_twitter_links ( & self , post : & Post ) -> ( Option < String > , Option < String > ) {
134
+ let post_url = format ! ( "{}{}" , self . conf. get_root( ) , post. get_url( ) ) ;
135
+ let facebook_link = self . conf . facebook . as_ref ( ) . map ( |_| {
136
+ format ! (
137
+ "https://www.facebook.com/sharer/sharer.php?u={}" ,
138
+ post_url
139
+ )
140
+ } ) ;
141
+ let twitter_link = self . conf . twitter_share . as_ref ( ) . map ( |_| {
142
+ format ! (
143
+ "https://twitter.com/intent/tweet?url={}&text={}" ,
144
+ post_url,
145
+ post. get_metadata( ) . get_title( )
146
+ )
147
+ } ) ;
148
+ ( facebook_link, twitter_link)
149
+ }
129
150
}
130
151
131
152
impl BlogConf {
@@ -201,6 +222,14 @@ impl BlogConf {
201
222
pub fn get_syntax_highlight ( & self ) -> Option < bool > {
202
223
self . syntax_highlight
203
224
}
225
+
226
+ pub fn get_facebook ( & self ) -> Option < & str > {
227
+ self . facebook . as_deref ( )
228
+ }
229
+
230
+ pub fn get_twitter_share ( & self ) -> Option < & str > {
231
+ self . twitter_share . as_deref ( )
232
+ }
204
233
}
205
234
206
235
impl Post {
0 commit comments