feat: add Open Graph protocol support

This commit is contained in:
st1020 2024-05-18 18:20:43 +08:00
parent 04a31a78f8
commit 3d4a168676
2 changed files with 33 additions and 4 deletions

View file

@ -50,6 +50,8 @@ math = false
mermaid = false mermaid = false
# Enable comment support globally. # Enable comment support globally.
comment = false comment = false
# The URL of social image.
social_image = "icons/github.svg"
[extra.style] [extra.style]
# The custom background color. # The custom background color.

View file

@ -11,13 +11,40 @@
<!-- Meta --> <!-- Meta -->
<meta name="theme-color" /> <meta name="theme-color" />
<!-- Author -->
{% if page %} {% if page %}
<meta name="description" content="{{ page.summary | default(value=page.title) | safe }}" /> <!-- Author -->
<meta name="author" content="{{ page.extra.author | default(value=page.title) }}" /> {% set page_title = page.title | default(value=config.title) %}
<!---->
{% set description = page.summary | default(value=page_title) %}
<meta name="description" content="{{ description }}" />
<meta name="author" content="{{ page.extra.author | default(value=page_title) }}" />
<!-- The Open Graph protocol -->
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ page_title }}" />
<meta property="og:site_name" content="{{ config.title }}" />
<meta property="og:description" content="{{ description }}" />
<meta property="og:url" content="{{ page.permalink }}" />
{% set image = page.extra.cover_image | default(value=config.extra.social_image) %}
<!---->
{% if image %}
<meta property="og:image" content="{{ get_url(path=image) }}" />
{% endif %}
<!---->
{% else %} {% else %}
<meta name="description" content="{{ config.description | default(value=`A personal blog`) }}" /> <!-- Author -->
{% set description = config.description | default(value="A personal blog") %}
<!---->
<meta name="description" content="{{ description }}" />
<meta name="author" content="{{ config.author | default(value=config.title) }}" /> <meta name="author" content="{{ config.author | default(value=config.title) }}" />
<!-- The Open Graph protocol -->
<meta property="og:type" content="website" />
<meta property="og:title" content="{{ config.title }}" />
<meta property="og:description" content="{{ description }}" />
<meta property="og:url" content="{{ get_url(path=``) }}" />
{% if config.extra.social_image %}
<meta property="og:image" content="{{ get_url(path=config.extra.social_image) }}" />
{% endif %}
<!---->
{% endif %} {% endif %}
<!-- CSS & JS --> <!-- CSS & JS -->