File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,8 @@ global_variables() {
49
49
50
50
# Change this to your username if you want to use twitter for comments
51
51
global_twitter_username=" "
52
+ # Default image for the Twitter cards. Use an absolute URL
53
+ global_twitter_card_image=" "
52
54
# Set this to false for a Twitter button with share count. The cookieless version
53
55
# is just a link.
54
56
global_twitter_cookieless=" true"
@@ -345,8 +347,17 @@ twitter_card() {
345
347
echo "<meta name=' twitter:title' content=' $2 ' />" # Twitter truncates at 70 char
346
348
description=$(grep -v "^<p>$template_tags_line_header" "$1" | sed -e ' s/< [^> ]* > //g' | tr ' \n ' ' ' | sed "s/\"/' /g" | head -c 250)
347
349
echo " < meta name=' twitter:description' content=\" $description \" /> "
348
- image=$( sed -n ' 2,$ d; s/.*<img.*src="\([^"]*\)".*/\1/p' " $1 " ) # First image is fine
350
+
351
+ # For the image we try to locate the first image in the article
352
+ image=$( sed -n ' 2,$ d; s/.*<img.*src="\([^"]*\)".*/\1/p' " $1 " )
353
+
354
+ # If none, then we try a global setting image
355
+ [[ -z $image ]] && [[ -n $global_twitter_card_image ]] && image=$global_twitter_card_image
356
+
357
+ # If none, return
349
358
[[ -z $image ]] && return
359
+
360
+ # Final housekeeping
350
361
[[ $image =~ ^https?:// ]] || image=$global_url /$image # Check that URL is absolute
351
362
echo " < meta name=' twitter:image' content=' $image' /> "
352
363
}
You can’t perform that action at this time.
0 commit comments