Skip to content

Commit 01d84ed

Browse files
committed
Add social-share metadata and an Atom feed to the blog
The Jekyll layout's head had only title, description, and theme-color: sharing any blog post on X, LinkedIn, or Discord rendered a bare link with no card, and the blog had no feed for aggregators or readers. - og:/twitter: tags in the shared layout, using the post's cover image when present and the site social card otherwise, with og:type article on dated posts and website elsewhere. - A hand-rolled Atom feed at /blogs/feed.xml built from a Liquid template, advertised via a rel=alternate link. A template instead of jekyll-feed avoids a Gemfile.lock regeneration, which cannot be done on machines without local bundler access. - site.url is now set, which absolute_url and the feed's permanent entry IDs both require. The feed opts out of the site-wide layout default with layout: null; without it the config's defaults would wrap the XML in the HTML shell.
1 parent 9b6d4f9 commit 01d84ed

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

blogs/_config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ description: Insights, updates, and deep dives into the world of document databa
44
# app/services/externalLinks.ts; update both when one changes.
55
discord_url: https://discord.gg/vH7bYu524D
66
baseurl: /blogs
7-
url: ""
7+
# Absolute host for og:url, og:image, and the Atom feed's permanent IDs.
8+
url: "https://documentdb.io"
89
permalink: pretty
910
markdown: kramdown
1011
kramdown:

blogs/_layouts/default.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,33 @@
66
<title>{% if page.title %}{{ page.title }} · {% endif %}DocumentDB</title>
77
<meta name="description" content="{{ page.description | default: site.description | escape }}">
88
<meta name="theme-color" content="#09090b">
9+
10+
{% assign social_title = page.title | default: site.title %}
11+
{% assign social_description = page.description | default: site.description %}
12+
{% if page.cover_image %}
13+
{% if page.cover_image contains '://' %}
14+
{% assign social_image = page.cover_image %}
15+
{% else %}
16+
{% assign social_image = page.cover_image | absolute_url %}
17+
{% endif %}
18+
{% else %}
19+
{% assign social_image = site.url | append: '/images/social-card.png' %}
20+
{% endif %}
21+
<meta property="og:site_name" content="DocumentDB">
22+
<meta property="og:type" content="{% if page.date %}article{% else %}website{% endif %}">
23+
<meta property="og:title" content="{{ social_title | escape }}">
24+
<meta property="og:description" content="{{ social_description | escape }}">
25+
<meta property="og:url" content="{{ page.url | absolute_url }}">
26+
<meta property="og:image" content="{{ social_image }}">
27+
{% if page.date %}
28+
<meta property="article:published_time" content="{{ page.date | date_to_xmlschema }}">
29+
{% endif %}
30+
<meta name="twitter:card" content="summary_large_image">
31+
<meta name="twitter:title" content="{{ social_title | escape }}">
32+
<meta name="twitter:description" content="{{ social_description | escape }}">
33+
<meta name="twitter:image" content="{{ social_image }}">
34+
35+
<link rel="alternate" type="application/atom+xml" title="DocumentDB Blog" href="{{ '/feed.xml' | relative_url }}">
936
<link rel="stylesheet" href="{{ '/assets/blog.css' | relative_url }}">
1037
</head>
1138
<body>

blogs/feed.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
# layout: null opts out of the site-wide `layout: default` front-matter
3+
# default, which would otherwise wrap this XML in the HTML shell.
4+
layout: null
5+
permalink: /feed.xml
6+
---
7+
<?xml version="1.0" encoding="utf-8"?>
8+
<feed xmlns="http://www.w3.org/2005/Atom">
9+
<title>{{ site.title | xml_escape }}</title>
10+
<subtitle>{{ site.description | xml_escape }}</subtitle>
11+
<id>{{ '/' | absolute_url }}</id>
12+
<link href="{{ '/' | absolute_url }}"/>
13+
<link href="{{ '/feed.xml' | absolute_url }}" rel="self"/>
14+
<updated>{% if site.posts.size > 0 %}{{ site.posts.first.date | date_to_xmlschema }}{% else %}{{ site.time | date_to_xmlschema }}{% endif %}</updated>
15+
<author><name>DocumentDB</name></author>
16+
{% for post in site.posts %}
17+
<entry>
18+
<title>{{ post.title | xml_escape }}</title>
19+
<id>{{ post.url | absolute_url }}</id>
20+
<link href="{{ post.url | absolute_url }}"/>
21+
<updated>{{ post.date | date_to_xmlschema }}</updated>
22+
{% if post.author %}<author><name>{{ post.author | xml_escape }}</name></author>{% endif %}
23+
{% if post.description %}<summary>{{ post.description | xml_escape }}</summary>{% endif %}
24+
<content type="html">{{ post.content | xml_escape }}</content>
25+
{% for tag in post.tags %}<category term="{{ tag | xml_escape }}"/>{% endfor %}
26+
</entry>
27+
{% endfor %}
28+
</feed>

0 commit comments

Comments
 (0)