Skip to content

Commit d2287c0

Browse files
feat: add post meta descriptions for seo
1 parent b47b16c commit d2287c0

6 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/post.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ pub struct Post {
4949
#[serde(skip_serializing)]
5050
pub commits: Option<Vec<String>>,
5151
pub tags: Option<Vec<String>>,
52+
pub description: Option<String>,
5253
pub real_commits: Option<Vec<Commit>>,
5354
pub related_posts: Option<Vec<SummaryPost>>,
5455
}

src/rss.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ mod tests {
9292
content: "<p>Body text</p>".to_string(),
9393
commits: None,
9494
tags: None,
95+
description: None,
9596
real_commits: None,
9697
related_posts: None,
9798
}

src/services/post.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ impl PostService {
4848
let tags_str: Option<String> = row.get("tags")?;
4949
let tags = tags_str.and_then(|s| serde_json::from_str(&s).ok());
5050

51+
let description: Option<String> = row.get("description")?;
52+
5153
Ok(Post {
5254
id,
5355
content_type,
@@ -60,6 +62,7 @@ impl PostService {
6062
content,
6163
commits,
6264
tags,
65+
description,
6366
real_commits: None,
6467
related_posts: None,
6568
})

src/services/test_helpers.rs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ CREATE TABLE posts (
2424
date TEXT NOT NULL,
2525
content TEXT NOT NULL DEFAULT '',
2626
commits TEXT,
27-
tags TEXT
27+
tags TEXT,
28+
description TEXT
2829
);
2930
CREATE TABLE commits (
3031
id TEXT PRIMARY KEY,
@@ -76,6 +77,7 @@ pub fn seed(conn: &Connection) {
7677
&str,
7778
Option<&str>,
7879
Option<&str>,
80+
Option<&str>,
7981
)] = &[
8082
(
8183
"post-01",
@@ -88,6 +90,7 @@ pub fn seed(conn: &Connection) {
8890
"link post content",
8991
Some(r#"["commit-1"]"#),
9092
Some(r#"["rust","web"]"#),
93+
Some("A post about Rust and the web."),
9194
),
9295
(
9396
"post-02",
@@ -100,6 +103,7 @@ pub fn seed(conn: &Connection) {
100103
"quoted text here",
101104
Some(r#"["commit-2","commit-1"]"#),
102105
Some(r#"["rust"]"#),
106+
None,
103107
),
104108
(
105109
"post-03",
@@ -112,6 +116,7 @@ pub fn seed(conn: &Connection) {
112116
"golang article about performance",
113117
None,
114118
Some(r#"["go"]"#),
119+
Some("An article about Go and performance."),
115120
),
116121
(
117122
"post-04",
@@ -124,6 +129,7 @@ pub fn seed(conn: &Connection) {
124129
"regular post",
125130
None,
126131
None,
132+
None,
127133
),
128134
(
129135
"post-05",
@@ -136,6 +142,7 @@ pub fn seed(conn: &Connection) {
136142
"regular post",
137143
None,
138144
None,
145+
None,
139146
),
140147
(
141148
"post-06",
@@ -148,6 +155,7 @@ pub fn seed(conn: &Connection) {
148155
"regular post",
149156
None,
150157
None,
158+
None,
151159
),
152160
(
153161
"post-07",
@@ -160,6 +168,7 @@ pub fn seed(conn: &Connection) {
160168
"regular post",
161169
None,
162170
None,
171+
None,
163172
),
164173
(
165174
"post-08",
@@ -172,6 +181,7 @@ pub fn seed(conn: &Connection) {
172181
"regular post",
173182
None,
174183
None,
184+
None,
175185
),
176186
(
177187
"post-09",
@@ -184,6 +194,7 @@ pub fn seed(conn: &Connection) {
184194
"regular post",
185195
None,
186196
None,
197+
None,
187198
),
188199
(
189200
"post-10",
@@ -196,6 +207,7 @@ pub fn seed(conn: &Connection) {
196207
"regular post",
197208
None,
198209
None,
210+
None,
199211
),
200212
(
201213
"post-11",
@@ -208,6 +220,7 @@ pub fn seed(conn: &Connection) {
208220
"regular post",
209221
None,
210222
None,
223+
None,
211224
),
212225
(
213226
"post-12",
@@ -220,6 +233,7 @@ pub fn seed(conn: &Connection) {
220233
"regular post",
221234
None,
222235
None,
236+
None,
223237
),
224238
(
225239
"about",
@@ -232,14 +246,15 @@ pub fn seed(conn: &Connection) {
232246
"about page content",
233247
None,
234248
None,
249+
None,
235250
),
236251
];
237252

238-
for (id, ct, title, link, via, qa, date, content, commits, tags) in posts {
253+
for (id, ct, title, link, via, qa, date, content, commits, tags, description) in posts {
239254
conn.execute(
240-
"INSERT INTO posts(id,content_type,title,link,via,quote_author,date,content,commits,tags)
241-
VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10)",
242-
rusqlite::params![id, ct, title, link, via, qa, date, content, commits, tags],
255+
"INSERT INTO posts(id,content_type,title,link,via,quote_author,date,content,commits,tags,description)
256+
VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11)",
257+
rusqlite::params![id, ct, title, link, via, qa, date, content, commits, tags, description],
243258
)
244259
.unwrap();
245260

templates/base.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
<link rel="stylesheet" href="/static/css/style.css?{{ build_id }}" />
2121
<link rel="icon" href="/static/imgs/favicon.ico?{{ build_id }}" />
2222
<meta name="view-transition" content="same-origin" />
23+
{% block meta %}
24+
<meta
25+
name="description"
26+
content="Jonathan Milligan's blog — writing on software, technology, and ideas."
27+
/>
28+
{% endblock %}
2329
<link
2430
rel="alternate"
2531
type="application/atom+xml"

templates/post.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
{% extends "base.html" %} {% import "macros.html" as macros %}
2+
{% block meta %}{% if post.description %}<meta
3+
name="description"
4+
content="{{ post.description }}"
5+
/>{% else %}<meta
6+
name="description"
7+
content="Jonathan Milligan's blog — writing on software, technology, and ideas."
8+
/>{% endif %}{% endblock %}
29
{% block content %}
310
<main>
411
{{ macros::render_post(post=post, show_commits=true, show_related=true) }}

0 commit comments

Comments
 (0)