Skip to content

Commit ec3d352

Browse files
committed
Rename template variables
These variable names are more inline with zola's conventions.
1 parent a9e53dd commit ec3d352

File tree

8 files changed

+54
-54
lines changed

8 files changed

+54
-54
lines changed

src/blogs.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ pub struct Blog {
3737
maintained_by: String,
3838
index_html: String,
3939
#[serde(serialize_with = "add_postfix_slash")]
40-
prefix: PathBuf,
40+
path: PathBuf,
4141
posts: Vec<Post>,
4242
}
4343

4444
impl Blog {
45-
fn load(prefix: PathBuf, dir: &Path) -> eyre::Result<Self> {
45+
fn load(path: PathBuf, dir: &Path) -> eyre::Result<Self> {
4646
let manifest_content = std::fs::read_to_string(dir.join(MANIFEST_FILE))?
4747
.strip_prefix("+++\n")
4848
.unwrap()
@@ -94,7 +94,7 @@ impl Blog {
9494
maintained_by: manifest.maintained_by,
9595
index_html: manifest.index_html,
9696
link_text: manifest.link_text,
97-
prefix,
97+
path,
9898
posts,
9999
})
100100
}
@@ -111,8 +111,8 @@ impl Blog {
111111
&self.index_title
112112
}
113113

114-
pub(crate) fn prefix(&self) -> &Path {
115-
&self.prefix
114+
pub(crate) fn path(&self) -> &Path {
115+
&self.path
116116
}
117117

118118
pub(crate) fn posts(&self) -> &[Post] {
@@ -139,10 +139,10 @@ fn load_recursive(base: &Path, current: &Path, blogs: &mut Vec<Blog>) -> eyre::R
139139
let file_name = path.file_name().and_then(|n| n.to_str());
140140
if let (Some(file_name), Some(parent)) = (file_name, path.parent()) {
141141
if file_name == MANIFEST_FILE {
142-
let prefix = parent
142+
let path = parent
143143
.strip_prefix(base)
144144
.map_or_else(|_| PathBuf::new(), Path::to_path_buf);
145-
blogs.push(Blog::load(prefix, parent)?);
145+
blogs.push(Blog::load(path, parent)?);
146146
}
147147
}
148148
}

src/lib.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Generator {
106106
}
107107

108108
fn render_blog(&self, blog: &Blog) -> eyre::Result<()> {
109-
std::fs::create_dir_all(self.out_directory.join(blog.prefix()))?;
109+
std::fs::create_dir_all(self.out_directory.join(blog.path()))?;
110110

111111
let path = self.render_index(blog)?;
112112

@@ -135,24 +135,24 @@ impl Generator {
135135
.map(|other_blog| {
136136
json!({
137137
"link_text": other_blog.link_text(),
138-
"url": other_blog.prefix().join("index.html"),
138+
"url": other_blog.path().join("index.html"),
139139
})
140140
})
141141
.collect();
142142

143143
let data = json!({
144144
"title": blog.index_title(),
145-
"blog": blog,
145+
"section": blog,
146146
"other_blogs": other_blogs,
147147
});
148-
let path = blog.prefix().join("index.html");
148+
let path = blog.path().join("index.html");
149149
self.render_template(&path, "index.html", data)?;
150150
Ok(path)
151151
}
152152

153153
fn render_post(&self, blog: &Blog, post: &Post) -> eyre::Result<PathBuf> {
154154
let path = blog
155-
.prefix()
155+
.path()
156156
.join(format!("{:04}", &post.year))
157157
.join(format!("{:02}", &post.month))
158158
.join(format!("{:02}", &post.day));
@@ -164,8 +164,8 @@ impl Generator {
164164

165165
let data = json!({
166166
"title": format!("{} | {}", post.title, blog.title()),
167-
"blog": blog,
168-
"post": post,
167+
"section": blog,
168+
"page": post,
169169
});
170170

171171
let path = path.join(filename);
@@ -176,12 +176,12 @@ impl Generator {
176176
fn render_feed(&self, blog: &Blog) -> eyre::Result<()> {
177177
let posts: Vec<_> = blog.posts().iter().take(10).collect();
178178
let data = json!({
179-
"blog": blog,
180-
"posts": posts,
179+
"section": blog,
180+
"pages": posts,
181181
"feed_updated": chrono::Utc::now().with_nanosecond(0).unwrap().to_rfc3339(),
182182
});
183183

184-
self.render_template(blog.prefix().join("feed.xml"), "feed.xml", data)?;
184+
self.render_template(blog.path().join("feed.xml"), "feed.xml", data)?;
185185
Ok(())
186186
}
187187

@@ -193,7 +193,7 @@ impl Generator {
193193
.map(|post| ReleasePost {
194194
title: post.title.clone(),
195195
url: blog
196-
.prefix()
196+
.path()
197197
.join(post.url.clone())
198198
.to_string_lossy()
199199
.to_string(),
@@ -204,7 +204,7 @@ impl Generator {
204204
feed_updated: chrono::Utc::now().with_nanosecond(0).unwrap().to_rfc3339(),
205205
};
206206
fs::write(
207-
self.out_directory.join(blog.prefix()).join("releases.json"),
207+
self.out_directory.join(blog.path()).join("releases.json"),
208208
serde_json::to_string(&data)?,
209209
)?;
210210
Ok(())

templates/feed.xml

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
{% import "macros.html" as macros %}
22
<?xml version="1.0" encoding="utf-8"?>
33
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
4-
<generator uri="https://blog.rust-lang.org/{{blog.prefix}}" version="0.1.0">{{blog.title}}</generator>
5-
<link href="https://blog.rust-lang.org/{{blog.prefix}}feed.xml" rel="self" type="application/atom+xml" />
6-
<link href="https://blog.rust-lang.org/{{blog.prefix}}" rel="alternate" type="text/html" />
7-
<id>https://blog.rust-lang.org/{{blog.prefix}}</id>
8-
<title>{{blog.title}}</title>
9-
<subtitle>{{blog.description}}</subtitle>
4+
<generator uri="https://blog.rust-lang.org/{{ section.path }}" version="0.1.0">{{ section.title }}</generator>
5+
<link href="https://blog.rust-lang.org/{{ section.path }}feed.xml" rel="self" type="application/atom+xml" />
6+
<link href="https://blog.rust-lang.org/{{ section.path }}" rel="alternate" type="text/html" />
7+
<id>https://blog.rust-lang.org/{{ section.path }}</id>
8+
<title>{{ section.title }}</title>
9+
<subtitle>{{ section.description }}</subtitle>
1010
<author>
11-
<name>Maintained by {{blog.maintained_by}}.</name>
11+
<name>Maintained by {{ section.maintained_by }}.</name>
1212
<uri>https://github.com/rust-lang/blog.rust-lang.org/</uri>
1313
</author>
1414
<updated>{{feed_updated}}</updated>
1515

16-
{% for post in posts %}
16+
{% for page in pages %}
1717
<entry>
18-
<title>{{ macros::escape_hbs(input=post.title) }}</title>
19-
<link rel="alternate" href="https://blog.rust-lang.org/{{blog.prefix}}{{ macros::escape_hbs(input=post.url) }}" type="text/html" title="{{ macros::escape_hbs(input=post.title) }}" />
20-
<published>{{ macros::escape_hbs(input=post.published) }}</published>
21-
<updated>{{ macros::escape_hbs(input=post.updated) }}</updated>
22-
<id>https://blog.rust-lang.org/{{blog.prefix}}{{ macros::escape_hbs(input=post.url) }}</id>
23-
<content type="html" xml:base="https://blog.rust-lang.org/{{blog.prefix}}{{ macros::escape_hbs(input=post.url) }}">{{ macros::escape_hbs(input=post.contents) }}</content>
18+
<title>{{ macros::escape_hbs(input=page.title) }}</title>
19+
<link rel="alternate" href="https://blog.rust-lang.org/{{ section.path }}{{ macros::escape_hbs(input=page.url) }}" type="text/html" title="{{ macros::escape_hbs(input=page.title) }}" />
20+
<published>{{ macros::escape_hbs(input=page.published) }}</published>
21+
<updated>{{ macros::escape_hbs(input=page.updated) }}</updated>
22+
<id>https://blog.rust-lang.org/{{ section.path }}{{ macros::escape_hbs(input=page.url) }}</id>
23+
<content type="html" xml:base="https://blog.rust-lang.org/{{ section.path }}{{ macros::escape_hbs(input=page.url) }}">{{ macros::escape_hbs(input=page.contents) }}</content>
2424

2525
<author>
26-
<name>{{ macros::escape_hbs(input=post.author) }}</name>
26+
<name>{{ macros::escape_hbs(input=page.author) }}</name>
2727
</author>
2828
</entry>
2929
{%- endfor %}

templates/headers.html

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
{% macro headers(title, blog) -%}
1+
{% macro headers(title, section) -%}
22
<!-- Twitter card -->
33
<meta name="twitter:card" content="summary">
44
<meta name="twitter:site" content="@rustlang">
55
<meta name="twitter:creator" content="@rustlang">
66
<meta name="twitter:title" content="{{ macros::escape_hbs(input=title) }}">
7-
<meta name="twitter:description" content="{{blog.description}}">
7+
<meta name="twitter:description" content="{{ section.description }}">
88
<meta name="twitter:image" content="https://www.rust-lang.org/static/images/rust-social.jpg">
99

1010
<!-- Facebook OpenGraph -->
1111
<meta property="og:title" content="{{ macros::escape_hbs(input=title) }}" />
12-
<meta property="og:description" content="{{blog.description}}">
12+
<meta property="og:description" content="{{ section.description }}">
1313
<meta property="og:image" content="https://www.rust-lang.org/static/images/rust-social-wide.jpg" />
1414
<meta property="og:type" content="website" />
1515
<meta property="og:locale" content="en_US" />
@@ -36,7 +36,7 @@
3636
<meta name="theme-color" content="#ffffff">
3737

3838
<!-- atom -->
39-
<link type="application/atom+xml" rel="alternate" href="https://blog.rust-lang.org/{{blog.prefix}}feed.xml" title="{{blog.title}}" />
39+
<link type="application/atom+xml" rel="alternate" href="https://blog.rust-lang.org/{{ section.path }}feed.xml" title="{{ section.title }}" />
4040

4141
<!-- theme switcher -->
4242
<script src="/scripts/theme-switch.js"></script>

templates/index.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<header class="mt3 mt0-ns mb4-ns">
55
<div class="container flex flex-column flex-row-l justify-between-l">
66
<div class="mw6-l">
7-
<p>{{blog.index_html}}</p>
7+
<p>{{ section.index_html }}</p>
88
</div>
99
</div>
1010
<div class="container flex flex-column flex-row-l justify-between-l">
@@ -23,14 +23,14 @@
2323
<div class="w-100 mw-none ph3 mw8-m mw9-l center f3">
2424

2525
<table class="post-list collapse w-100 f2-l f2-m f3-s">
26-
{%- for post in blog.posts %}
27-
{% if post.show_year %}<tr>
26+
{%- for page in section.posts %}
27+
{% if page.show_year %}<tr>
2828
<td class="bn"></td>
29-
<td class="bn"><h3 class="f0-l f1-m f2-s mt4 mb0">Posts in {{post.year}}</h3></td>
29+
<td class="bn"><h3 class="f0-l f1-m f2-s mt4 mb0">Posts in {{ page.year }}</h3></td>
3030
</tr>{% endif %}
3131
<tr>
32-
<td class="tr o-60 pr4 pr5-l bn">{{ macros::month_name(num=post.month) }}&nbsp;{{post.day}}</td>
33-
<td class="bn"><a href="{{post.url}}">{{ macros::escape_hbs(input=post.title) }}</a></td>
32+
<td class="tr o-60 pr4 pr5-l bn">{{ macros::month_name(num=page.month) }}&nbsp;{{ page.day }}</td>
33+
<td class="bn"><a href="{{ page.url }}">{{ macros::escape_hbs(input=page.title) }}</a></td>
3434
</tr>
3535
{%- endfor %}
3636
</table>

templates/layout.html

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<title>{{ macros::escape_hbs(input=title) }}</title>
1010
<meta name="viewport" content="width=device-width,initial-scale=1.0">
1111
<meta name="description" content="Empowering everyone to build reliable and efficient software.">
12-
{{ headers::headers(title=title, blog=blog) | indent(prefix=" ", blank=true) }}
12+
{{ headers::headers(title=title, section=section) | indent(prefix=" ", blank=true) }}
1313
</head>
1414
<body>
15-
{{ nav::nav(blog=blog) | indent(prefix=" ", blank=true) }}
15+
{{ nav::nav(section=section) | indent(prefix=" ", blank=true) }}
1616
{%- block page %}{% endblock page %}
1717
{{ footer::footer() | indent(prefix=" ", blank=true) }}
1818
</body>

templates/nav.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
{% macro nav(blog) -%}
1+
{% macro nav(section) -%}
22
<nav class="flex flex-row justify-center justify-end-l items-center flex-wrap ph2 pl3-ns pr4-ns">
33
<div class="brand flex-auto w-100 w-auto-l self-start tc tl-l">
4-
<a href="/{{blog.prefix}}">
4+
<a href="/{{ section.path }}">
55
<img class="v-mid ml0-l rust-logo" alt="Rust Logo" src="/images/rust-logo-blk.svg">
6-
<span class="dib ml1 ml0-l">{{blog.title}}</span>
6+
<span class="dib ml1 ml0-l">{{ section.title }}</span>
77
</a>
88
</div>
99

templates/post.html

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
{% import "macros.html" as macros %}
22
{% extends "layout.html" %}
33
{% block page %}
4-
<section id="{{ macros::escape_hbs(input=post.title) }}" class="white">
4+
<section id="{{ macros::escape_hbs(input=page.title) }}" class="white">
55
<div class="w-100 mw-none ph3 mw8-m mw8-l center f3">
66
<header>
7-
<h2>{{ macros::escape_hbs(input=post.title) }}</h2>
7+
<h2>{{ macros::escape_hbs(input=page.title) }}</h2>
88
<div class="highlight mt2 mb3"></div>
99
</header>
1010

11-
<div class="publish-date-author">{{ macros::month_name(num=post.month) }} {{post.day}}, {{post.year}} &middot; {{ macros::escape_hbs(input=post.author) }}
12-
{% if post.has_team %} on behalf of <a href="{{post.team_url}}">{{post.team}}</a> {% endif %}
11+
<div class="publish-date-author">{{ macros::month_name(num=page.month) }} {{ page.day }}, {{ page.year }} &middot; {{ macros::escape_hbs(input=page.author) }}
12+
{% if page.has_team %} on behalf of <a href="{{ page.team_url }}">{{ page.team }}</a> {% endif %}
1313
</div>
1414

1515
<div class="post">
16-
{{ post.contents }}
16+
{{ page.contents }}
1717
</div>
1818
</div>
1919
</section>

0 commit comments

Comments
 (0)