Skip to content

Commit 3d4a168

Browse files
committed
feat: add Open Graph protocol support
1 parent 04a31a7 commit 3d4a168

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

config.toml

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ math = false
5050
mermaid = false
5151
# Enable comment support globally.
5252
comment = false
53+
# The URL of social image.
54+
social_image = "icons/github.svg"
5355

5456
[extra.style]
5557
# The custom background color.

templates/partials/head.html

+31-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,40 @@
1111
<!-- Meta -->
1212
<meta name="theme-color" />
1313

14-
<!-- Author -->
1514
{% if page %}
16-
<meta name="description" content="{{ page.summary | default(value=page.title) | safe }}" />
17-
<meta name="author" content="{{ page.extra.author | default(value=page.title) }}" />
15+
<!-- Author -->
16+
{% set page_title = page.title | default(value=config.title) %}
17+
<!---->
18+
{% set description = page.summary | default(value=page_title) %}
19+
<meta name="description" content="{{ description }}" />
20+
<meta name="author" content="{{ page.extra.author | default(value=page_title) }}" />
21+
<!-- The Open Graph protocol -->
22+
<meta property="og:type" content="website" />
23+
<meta property="og:title" content="{{ page_title }}" />
24+
<meta property="og:site_name" content="{{ config.title }}" />
25+
<meta property="og:description" content="{{ description }}" />
26+
<meta property="og:url" content="{{ page.permalink }}" />
27+
{% set image = page.extra.cover_image | default(value=config.extra.social_image) %}
28+
<!---->
29+
{% if image %}
30+
<meta property="og:image" content="{{ get_url(path=image) }}" />
31+
{% endif %}
32+
<!---->
1833
{% else %}
19-
<meta name="description" content="{{ config.description | default(value=`A personal blog`) }}" />
34+
<!-- Author -->
35+
{% set description = config.description | default(value="A personal blog") %}
36+
<!---->
37+
<meta name="description" content="{{ description }}" />
2038
<meta name="author" content="{{ config.author | default(value=config.title) }}" />
39+
<!-- The Open Graph protocol -->
40+
<meta property="og:type" content="website" />
41+
<meta property="og:title" content="{{ config.title }}" />
42+
<meta property="og:description" content="{{ description }}" />
43+
<meta property="og:url" content="{{ get_url(path=``) }}" />
44+
{% if config.extra.social_image %}
45+
<meta property="og:image" content="{{ get_url(path=config.extra.social_image) }}" />
46+
{% endif %}
47+
<!---->
2148
{% endif %}
2249

2350
<!-- CSS & JS -->

0 commit comments

Comments
 (0)