Skip to content

Commit 29e99eb

Browse files
g-oikonomoualshedivat
authored andcommitted
Enable preview images on social media (alshedivat#66)
* Enable preview images on social media This commit adds support for serving Open Graph meta tags inside the HTML head. When enabled, links to the page on social media will display a preview. NB: twitter behaves somewhat differently and may require twitter card meta tags in addition to Open Graph. https://ogp.me/ * Remove trailing whitespaces * Support page-specific open graph social media previews * Document open graph support in the readme * Improve open graph support
1 parent 72377b2 commit 29e99eb

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

README.md

+14
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,20 @@ Just use the liquid tags `{% highlight python %}` and `{% endhighlight %}` to de
9898
</a>
9999
</p>
100100

101+
#### Social media previews
102+
The al-folio theme optionally supports preview images on social media.
103+
To enable this functionality you will need to set `serve_og_meta` to `true` in
104+
your `_config.yml`. Once you have done so, all your site's pages will include
105+
Open Graph data in the HTML head element.
106+
107+
You will then need to configure what image to display in your site's social
108+
media previews. This can be configured on a per-page basis, by setting the
109+
`og_image` page variable. If for an individual page this variable is not set,
110+
then the theme will fall back to a site-wide `og_image` variable, configurable
111+
in your `_config.yml`. In both the page-specific and site-wide cases, the
112+
`og_image` variable needs to hold the URL for the image you wish to display in
113+
social media previews.
114+
101115
## Contributing
102116

103117
Feel free to contribute new features and theme improvements by sending a pull request.

_config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ url: # the base hostname & protocol for your site
1414
baseurl: /al-folio # the subpath of your site, e.g. /blog/
1515
last_updated: # leave blank if you don't want to display last updated
1616

17+
# -----------------------------------------------------------------------------
18+
# Open Graph
19+
# -----------------------------------------------------------------------------
20+
# Display links to the page with a preview object on social media.
21+
# To achieve this, change serve_og_meta to true and then provide the URL of the
22+
# preview image as the value of og_image.
23+
serve_og_meta: false # Include Open Graph meta tags in the HTML head
24+
og_image: # The site-wide (default for all links) Open Graph preview image
1725
# -----------------------------------------------------------------------------
1826
# Social integration
1927
# -----------------------------------------------------------------------------

_includes/head.html

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
<title>{{ site.name }}{% if page.title and page.url != "/" %} | {{ page.title }}{% endif %}</title>
77
<meta name="description" content="{{ site.description }}">
88

9+
{% if site.serve_og_meta %}
10+
<meta property="og:site_name" content="{{ site.description }}" />
11+
<meta property="og:type" content="object" />
12+
<meta property="og:title" content="{{ site.name }}" />
13+
<meta property="og:url" content="{{ page.url | prepend: site.baseurl | prepend: site.url }}" />
14+
<meta property="og:description" content="{{ page.title }}" />
15+
<meta property="og:image"
16+
content="{%- if page.og_image -%}{{ page.og_image }}{%- else -%}{{ site.og_image }}{%- endif -%}" />
17+
{% endif %}
18+
919
<link rel="shortcut icon" href="{{ '/assets/img/favicon.ico' | prepend: site.baseurl | prepend: site.url }}">
1020

1121
<link rel="stylesheet" href="{{ '/assets/css/main.css' | prepend: site.baseurl | prepend: site.url }}">

0 commit comments

Comments
 (0)