From 2b9181cd29eed24de82808f98bd97617260af866 Mon Sep 17 00:00:00 2001 From: Dominik George <dominik.george@teckids.org> Date: Tue, 12 Mar 2024 13:12:03 +0100 Subject: [PATCH] Add basic support for Open Graph https://ogp.me/ --- config.toml | 4 ++++ templates/base.html | 26 +++++++++++++++++++++++--- templates/blog/overview.html | 12 ------------ templates/blog/post.html | 12 ------------ templates/index.html | 2 ++ templates/page.html | 12 ------------ 6 files changed, 29 insertions(+), 39 deletions(-) diff --git a/config.toml b/config.toml index cae54bf9..693e2d92 100644 --- a/config.toml +++ b/config.toml @@ -41,6 +41,10 @@ include_content = true index_format = "elasticlunr_json" +#[extra.og.image] +#url = +#alt = + [extra.footer] address = "Kennedyallee 18<br/>53175 Bonn" bank = "<b>IBAN:</b> DE31 3705 0198 1933 0485 46<br/><b>BIC:</b> COLSDE33XXX<br/>Sparkasse KoelnBonn" diff --git a/templates/base.html b/templates/base.html index fe3718cd..193a2e61 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,3 +1,8 @@ +{% if page -%} +{% set thing = page -%} +{% else -%} +{% set thing = section -%} +{% endif -%} <!DOCTYPE html> <html lang="{{ lang }}"> <head> @@ -5,15 +10,30 @@ <meta name="viewport" content="width=device-width, initial-scale=1" /> {% block meta %} - {% if config.description %}<meta name="description" content="{{ config.description }}" />{% endif %} - <link rel="alternate" type="application/atom+xml" href="{{ get_url(path="atom.xml", trailing_slash=false) }}" /> + <meta name="description" content="{{ thing.description | default(value=config.description) }}" /> + <link rel="alternate" type="application/atom+xml" href="{{ get_url(path="atom.xml", trailing_slash=false) }}" /> + {% endblock %} + + {% block og %} + <meta property="og:site_name" content="{{ config.title }}" /> + <meta property="og:title" content="{% block og_title %}{{ thing.title | default(value=config.title) }}{% endblock og_title %}" /> + <meta property="og:description" content="{{ thing.description | default(value=config.description) }}" /> + <meta property="og:type" content="{% block og_type %}{{ thing.extra.og.type | default(value='article') }}{% endblock og_type %}" /> + <meta property="og:url" content="{% block og_url %}{{ thing.permalink | safe }}{% endblock og_url %}" /> + {% if thing.extra.depiction %} + <meta property="og:image" content="{{ get_url(path="@/" ~ thing.relative_path, trailing_slash=true) }}{{ thing.extra.depiction.image | safe }}" /> + <meta property="og:image:alt" content="{{ thing.extra.depiction.alt }}" /> + {% elif config.extra.og.image %} + <meta property="og:image" content="{{ get_url(path=config.extra.og.image.url) }}" /> + <meta property="og:image:alt" content="{{ config.extra.og.image.alt }}" /> + {% endif %} {% endblock %} <link rel="stylesheet" href="{{ get_url(path="fonts/roboto/index.css") }}" /> <link rel="stylesheet" href="{{ get_url(path="fonts/font-awesome/css/all.css") }}" /> <link rel="stylesheet" href="{{ get_url(path="style.css") }}" /> - <title>{% block title %}{{ config.title }}{% endblock %}</title> + <title>{% block title %}{{ thing.title }}{% endblock %}</title> </head> <body class="has-navbar-fixed-top"> diff --git a/templates/blog/overview.html b/templates/blog/overview.html index a859d5f9..f28434e6 100644 --- a/templates/blog/overview.html +++ b/templates/blog/overview.html @@ -1,17 +1,5 @@ {% extends "base.html" %} -{% block meta %} - {% if section.description %} - <meta name="description" content="{{ page.description }}" /> - {% elif config.description %} - <meta name="description" content="{{ config.description }}" /> - {% endif %} -{% endblock %} - -{% block title %} - {{ section.title }} -{% endblock %} - {% block main %} <div class="my-4"> <div class="section"> diff --git a/templates/blog/post.html b/templates/blog/post.html index 68242d69..6131ecd6 100644 --- a/templates/blog/post.html +++ b/templates/blog/post.html @@ -1,17 +1,5 @@ {% extends "base.html" %} -{% block meta %} - {% if page.description %} - <meta name="description" content="{{ page.description }}" /> - {% elif config.description %} - <meta name="description" content="{{ config.description }}" /> - {% endif %} -{% endblock %} - -{% block title %} - {{ page.title }} -{% endblock %} - {% block main %} <h1>{{ page.title }}</h1> <div class="my-4"> diff --git a/templates/index.html b/templates/index.html index 636e355d..07e3d367 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,7 @@ {% extends "base.html" %} +{% block og_type %}website{% endblock %} + {% block main %} {% include "frontpage/blocks/claim.html" %} {% include "frontpage/blocks/projects.html" %} diff --git a/templates/page.html b/templates/page.html index 36983fcd..c30179b5 100644 --- a/templates/page.html +++ b/templates/page.html @@ -1,17 +1,5 @@ {% extends "base.html" %} -{% block meta %} - {% if page.description %} - <meta name="description" content="{{ page.description }}" /> - {% elif config.description %} - <meta name="description" content="{{ config.description }}" /> - {% endif %} -{% endblock %} - -{% block title %} - {{ page.title }} -{% endblock %} - {% block main %} {% include "pages/heading.html" %} <div class="my-4"> -- GitLab