Skip to content

Commit 5695eda

Browse files
committed
Match Zolas URLs scheme
This should not break permalinks at all and make it easier to compare the "before and after" of a Zola migration.
1 parent 9f97861 commit 5695eda

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/lib.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,28 @@ impl Generator {
139139
}
140140

141141
fn render_post(&self, blog: &Blog, post: &Post) -> eyre::Result<PathBuf> {
142+
let mut filename = PathBuf::from(&post.filename);
143+
filename.set_extension("html");
144+
145+
// This directory path is a compatiblity thing with a planned migration
146+
// to Zola. Zola insists on rendering pages at ../index.html, but we
147+
// mustn't break existing permalinks. So, ../slug.html/index.html it is.
142148
let path = blog
143149
.path()
144150
.join(format!("{:04}", &post.year))
145151
.join(format!("{:02}", &post.month))
146-
.join(format!("{:02}", &post.day));
152+
.join(format!("{:02}", &post.day))
153+
.join(filename);
147154
fs::create_dir_all(self.out_directory.join(&path))?;
148155

149-
// then, we render the page in that path
150-
let mut filename = PathBuf::from(&post.filename);
151-
filename.set_extension("html");
152-
153156
let data = json!({
154157
"title": format!("{} | {}", post.title, blog.title()),
155158
"section": blog,
156159
"page": post,
157-
"root": blog.path_back_to_root().join("../../../"),
160+
"root": blog.path_back_to_root().join("../../../../"),
158161
});
159162

160-
let path = path.join(filename);
163+
let path = path.join("index.html");
161164
self.render_template(&path, &format!("{}.html", post.layout), data)?;
162165
Ok(path)
163166
}

0 commit comments

Comments
 (0)