Skip to content

Commit 0d3a371

Browse files
authored
Merge pull request #518 from davep/mf2
Sprinkle some Microformats2 pixie dust on the output
2 parents e5afea1 + feff83c commit 0d3a371

9 files changed

Lines changed: 45 additions & 38 deletions

File tree

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212
([#517](https://github.com/davep/blogmore/pull/517))
1313
- Added a Sitelinks Searchbox action to the homepage's JSON-LD when search
1414
is enabled. ([#517](https://github.com/davep/blogmore/pull/517))
15+
- Added Microformats2 semantic markup (`h-entry`, `h-card`, etc.) to all
16+
templates to improve machine-readability and IndieWeb compatibility.
17+
([#518](https://github.com/davep/blogmore/pull/518))
18+
- Added `rel="me"` attributes to social links in the sidebar.
19+
([#518](https://github.com/davep/blogmore/pull/518))
1520

1621
## v2.26.0
1722

examples/themes/modern-compact/templates/_post_summary.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@
1616
tag_dir (str): URL path segment for tag pages.
1717
#}
1818
{% macro post_summary(post, include_category=true) %}
19-
<article class="post-summary{% if post.draft %} draft-post{% endif %}">
20-
<h2><a href="{{ post.url }}">{{ post.title }}{% if post.draft %} 🚧{% endif %}</a></h2>
19+
<article class="post-summary h-entry{% if post.draft %} draft-post{% endif %}">
20+
<h2 class="p-name"><a class="u-url" href="{{ post.url }}">{{ post.title }}{% if post.draft %} 🚧{% endif %}</a></h2>
2121
<div class="post-meta-line">
2222
{% if post.date %}
23-
<time datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
23+
<time class="dt-published" datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date dt-updated"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
2424
{% endif %}
2525
{% if with_read_time %}
2626
<span class="reading-time">{{ post.reading_time }} min read</span>
2727
{% endif %}
2828
{% if include_category and post.category %}
29-
<a href="/{{ category_dir }}/{{ post.safe_category }}.html" class="category-link">{{ post.category }}</a>
29+
<a href="/{{ category_dir }}/{{ post.safe_category }}.html" class="category-link p-category">{{ post.category }}</a>
3030
{% endif %}
3131
{% if post.tags %}
3232
<span class="tags">
3333
{% for tag, safe_tag in post.sorted_tag_pairs() %}
34-
<a href="/{{ tag_dir }}/{{ safe_tag }}.html" class="tag">{{ tag }}</a>
34+
<a href="/{{ tag_dir }}/{{ safe_tag }}.html" class="tag p-category">{{ tag }}</a>
3535
{% endfor %}
3636
</span>
3737
{% endif %}
3838
</div>
39-
<div class="post-content">
39+
<div class="post-content e-content">
4040
{{ post.html_content|safe }}
4141
</div>
4242
</article>

examples/themes/modern-compact/templates/base.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<span class="sidebar-mobile-title"><a href="/">{{ site_title }}</a></span>
100100
<button class="burger-menu" type="button" aria-label="Toggle navigation" aria-expanded="false"></button>
101101
</div>
102-
<div class="sidebar-content">
102+
<div class="sidebar-content h-card">
103103
<div class="sidebar-header">
104104
{% if site_logo_html %}
105105
<div class="sidebar-logo">
@@ -110,15 +110,15 @@
110110
{% elif site_logo %}
111111
<div class="sidebar-logo">
112112
<a href="/">
113-
<img src="{{ site_logo }}" alt="{{ site_title }}">
113+
<img src="{{ site_logo }}" alt="{{ site_title }}" class="u-photo">
114114
</a>
115115
</div>
116116
{% endif %}
117117

118118
<div class="sidebar-title">
119-
<div class="site-title"><a href="/">{{ site_title }}</a></div>
119+
<div class="site-title p-name"><a class="u-url" href="/">{{ site_title }}</a></div>
120120
{% if site_subtitle %}
121-
<p class="sidebar-subtitle">{{ site_subtitle }}</p>
121+
<p class="sidebar-subtitle p-note">{{ site_subtitle }}</p>
122122
{% endif %}
123123
</div>
124124
</div>
@@ -149,7 +149,7 @@
149149
<div class="sidebar-heading">{{ socials_title | default('Social') }}</div>
150150
<div class="sidebar-socials">
151151
{% for social in socials %}
152-
<a href="{{ social.url }}" title="{{ social.title | default(social.site) }}" aria-label="{{ social.title | default(social.site) }}"{% if social.url|is_external_link %} target="_blank" rel="noopener noreferrer"{% endif %}>
152+
<a href="{{ social.url }}" title="{{ social.title | default(social.site) }}" aria-label="{{ social.title | default(social.site) }}"{% if social.url|is_external_link %} target="_blank" rel="noopener noreferrer me"{% else %} rel="me"{% endif %} class="u-url">
153153
<i class="fa-brands fa-{{ social.site }}"></i>
154154
</a>
155155
{% endfor %}

src/blogmore/templates/_post_summary.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,26 @@
1919
tag_dir (str): URL path segment for tag pages.
2020
#}
2121
{% macro post_summary(post, include_category=true) %}
22-
<article class="post-summary{% if post.draft %} draft-post{% endif %}">
23-
<h2><a href="{{ post.url }}">{{ post.title }}{% if post.draft %} 🚧{% endif %}</a></h2>
22+
<article class="h-entry post-summary{% if post.draft %} draft-post{% endif %}">
23+
<h2 class="p-name"><a class="u-url" href="{{ post.url }}">{{ post.title }}{% if post.draft %} 🚧{% endif %}</a></h2>
2424
{% if post.date %}
25-
<time datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
25+
<time class="dt-published" datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date dt-updated"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
2626
{% endif %}
2727
{% if with_read_time %}
2828
<div class="reading-time">{{ post.reading_time }} min read</div>
2929
{% endif %}
3030
{% if include_category and post.category %}
3131
<div class="category">
32-
<a href="/{{ category_dir }}/{{ post.safe_category }}/{{ pagination_page1_suffix }}" class="category-link">{{ post.category }}</a>
32+
<a href="/{{ category_dir }}/{{ post.safe_category }}/{{ pagination_page1_suffix }}" class="p-category category-link">{{ post.category }}</a>
3333
</div>
3434
{% endif %}
35-
<div class="post-content">
35+
<div class="post-content e-content">
3636
{{ post.html_content|shift_headings(1)|safe }}
3737
</div>
3838
{% if post.tags %}
3939
<div class="tags">
4040
{% for tag, safe_tag in post.sorted_tag_pairs() %}
41-
<a href="/{{ tag_dir }}/{{ safe_tag }}/{{ pagination_page1_suffix }}" class="tag">{{ tag }}</a>
41+
<a href="/{{ tag_dir }}/{{ safe_tag }}/{{ pagination_page1_suffix }}" class="p-category tag">{{ tag }}</a>
4242
{% endfor %}
4343
</div>
4444
{% endif %}

src/blogmore/templates/base.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,24 @@
8080
<span class="sidebar-mobile-title"><a href="/">{{ site_title }}</a></span>
8181
<button class="burger-menu" type="button" aria-label="Toggle navigation" aria-expanded="false"></button>
8282
</div>
83-
<div class="sidebar-content">
83+
<div class="sidebar-content h-card">
8484
<div class="sidebar-header">
8585
{% if site_logo %}
8686
<div class="sidebar-logo">
8787
<a href="/">
8888
{% if site_logo_html %}
8989
{{ site_logo_html | safe }}
9090
{% else %}
91-
<img src="{{ site_logo }}" alt="{{ site_title }}">
91+
<img src="{{ site_logo }}" alt="{{ site_title }}" class="u-photo">
9292
{% endif %}
9393
</a>
9494
</div>
9595
{% endif %}
9696

9797
<div class="sidebar-title">
98-
<div class="site-title"><a href="/">{{ site_title }}</a></div>
98+
<div class="site-title p-name"><a class="u-url" href="/">{{ site_title }}</a></div>
9999
{% if site_subtitle %}
100-
<p class="sidebar-subtitle">{{ site_subtitle }}</p>
100+
<p class="sidebar-subtitle p-note">{{ site_subtitle }}</p>
101101
{% endif %}
102102
</div>
103103
</div>
@@ -128,7 +128,7 @@
128128
<div class="sidebar-heading">{{ socials_title | default('Social') }}</div>
129129
<div class="sidebar-socials">
130130
{% for social in socials %}
131-
<a href="{{ social.url }}" title="{{ social.title | default(social.site) }}" aria-label="{{ social.title | default(social.site) }}"{% if social.url|is_external_link %} target="_blank" rel="noopener noreferrer"{% endif %}>
131+
<a href="{{ social.url }}" title="{{ social.title | default(social.site) }}" aria-label="{{ social.title | default(social.site) }}"{% if social.url|is_external_link %} target="_blank" rel="noopener noreferrer me"{% else %} rel="me"{% endif %} class="u-url">
132132
<i class="fa-brands fa-{{ social.site }}"></i>
133133
</a>
134134
{% endfor %}

src/blogmore/templates/page.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@
1313
{% endblock %}
1414

1515
{% block content %}
16-
<article class="page">
16+
<article class="h-entry page">
1717
<header class="page-header">
18-
<h1>{{ page.title }}</h1>
18+
<h1 class="p-name">{{ page.title }}</h1>
19+
<a class="u-url" href="{{ page.url }}" style="display:none;">Permalink</a>
1920
</header>
2021

21-
<div class="page-content">
22+
<div class="e-content page-content">
2223
{{ page.html_content|safe }}
2324
</div>
2425
</article>

src/blogmore/templates/post.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
{% endblock %}
1919

2020
{% block content %}
21-
<article class="post{% if post.draft %} draft-post{% endif %}">
21+
<article class="h-entry post{% if post.draft %} draft-post{% endif %}">
2222
{% if prev_post or next_post %}
2323
<nav class="post-navigation post-navigation-top">
2424
{% if prev_post %}
@@ -37,28 +37,29 @@
3737
{% endif %}
3838

3939
<header class="post-header">
40-
<h1>{{ post.title }}{% if post.draft %} 🚧{% endif %}</h1>
40+
<h1 class="p-name">{{ post.title }}{% if post.draft %} 🚧{% endif %}</h1>
41+
<a class="u-url" href="{{ post.url }}" style="display:none;">Permalink</a>
4142
{% if post.date %}
42-
<time datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
43+
<time class="dt-published" datetime="{{ post.date.isoformat() }}">{{ post.date|format_date }}</time>{% if post.modified_date %}<span class="modified-date dt-updated"> (Modified: {{ post.modified_date|format_date_plain }})</span>{% endif %}
4344
{% endif %}
4445
{% if with_read_time %}
4546
<div class="reading-time">{{ post.reading_time }} min read</div>
4647
{% endif %}
4748
{% if post.category %}
4849
<div class="category">
49-
<a href="/{{ category_dir }}/{{ post.safe_category }}/{{ pagination_page1_suffix }}" class="category-link">{{ post.category }}</a>
50+
<a href="/{{ category_dir }}/{{ post.safe_category }}/{{ pagination_page1_suffix }}" class="p-category category-link">{{ post.category }}</a>
5051
</div>
5152
{% endif %}
5253
</header>
5354

54-
<div class="post-content">
55+
<div class="e-content post-content">
5556
{{ post.html_content|safe }}
5657
</div>
5758

5859
{% if post.tags %}
5960
<div class="tags">
6061
{% for tag, safe_tag in post.sorted_tag_pairs() %}
61-
<a href="/{{ tag_dir }}/{{ safe_tag }}/{{ pagination_page1_suffix }}" class="tag">{{ tag }}</a>
62+
<a href="/{{ tag_dir }}/{{ safe_tag }}/{{ pagination_page1_suffix }}" class="tag p-category">{{ tag }}</a>
6263
{% endfor %}
6364
</div>
6465
{% endif %}

tests/test_generator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ def test_generate_with_pages(
467467
# The posts fixture has 7 non-draft posts; the 2 pages in pages_dir
468468
# must not inflate this count to 9.
469469
index_content = (temp_output_dir / "index.html").read_text()
470-
assert index_content.count('<article class="post-summary">') == 7
470+
assert index_content.count("post-summary") == 7
471471

472472
def test_generate_with_sidebar_pages_filter(
473473
self, posts_dir: Path, pages_dir: Path, temp_output_dir: Path

tests/test_renderer.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ def test_post_summary_rendered_on_index(self, sample_post: Post) -> None:
10361036
tag_dir="tags",
10371037
)
10381038

1039-
assert 'class="post-summary"' in html
1039+
assert "post-summary" in html
10401040
assert sample_post.title in html
10411041

10421042
def test_post_summary_shows_category_on_index(self, sample_post: Post) -> None:
@@ -1051,7 +1051,7 @@ def test_post_summary_shows_category_on_index(self, sample_post: Post) -> None:
10511051
tag_dir="tags",
10521052
)
10531053

1054-
assert 'class="category-link"' in html
1054+
assert "category-link" in html
10551055
assert "python" in html
10561056

10571057
def test_post_summary_shows_category_on_tag_page(self, sample_post: Post) -> None:
@@ -1066,7 +1066,7 @@ def test_post_summary_shows_category_on_tag_page(self, sample_post: Post) -> Non
10661066
tag_dir="tags",
10671067
)
10681068

1069-
assert 'class="category-link"' in html
1069+
assert "category-link" in html
10701070

10711071
def test_post_summary_omits_category_on_category_page(
10721072
self, sample_post: Post
@@ -1099,8 +1099,8 @@ def test_post_summary_shows_category_on_date_archive(
10991099
tag_dir="tags",
11001100
)
11011101

1102-
assert 'class="post-summary"' in html
1103-
assert 'class="category-link"' in html
1102+
assert "post-summary" in html
1103+
assert "category-link" in html
11041104

11051105
def test_post_summary_shows_reading_time_when_enabled(
11061106
self, sample_post: Post
@@ -1191,7 +1191,7 @@ def test_shift_headings_in_summary(self) -> None:
11911191
)
11921192

11931193
# Post title in index is h2
1194-
assert "<h2>" in html
1194+
assert "<h2" in html
11951195
# Subheading in content should be shifted to h3
11961196
assert "<h3>Subheading</h3>" in html
11971197

0 commit comments

Comments
 (0)