Include a self-link for the blog.
This commit is contained in:
parent
3ac7826d2c
commit
11bfb6836f
@ -31,8 +31,14 @@ pub(crate) fn convert_blog_post_page_to_render_context<D: AsRef<Path>, F: AsRef<
|
|||||||
"blog_post.js",
|
"blog_post.js",
|
||||||
)?];
|
)?];
|
||||||
let global_settings = GlobalSettings::new(page.title.clone(), css_files, js_files);
|
let global_settings = GlobalSettings::new(page.title.clone(), css_files, js_files);
|
||||||
|
let link_to_blog_post = get_web_path(
|
||||||
|
config,
|
||||||
|
output_directory,
|
||||||
|
output_file,
|
||||||
|
output_file.strip_prefix(output_directory)?,
|
||||||
|
)?;
|
||||||
|
|
||||||
let ret = RenderBlogPostPage::new(global_settings, page.title.clone());
|
let ret = RenderBlogPostPage::new(global_settings, page.title.clone(), Some(link_to_blog_post));
|
||||||
Ok(ret)
|
Ok(ret)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,13 +52,15 @@ fn get_web_path<D: AsRef<Path>, F: AsRef<Path>, P: AsRef<Path>>(
|
|||||||
if config.use_relative_paths() {
|
if config.use_relative_paths() {
|
||||||
let output_directory = output_directory.as_ref();
|
let output_directory = output_directory.as_ref();
|
||||||
let containing_file = containing_file.as_ref();
|
let containing_file = containing_file.as_ref();
|
||||||
|
let containing_file_relative_to_output_directory =
|
||||||
|
containing_file.strip_prefix(output_directory)?;
|
||||||
// Subtracting 1 from the depth to "remove" the file name.
|
// Subtracting 1 from the depth to "remove" the file name.
|
||||||
let depth_from_web_root = containing_file
|
let depth_from_web_root = containing_file_relative_to_output_directory
|
||||||
.strip_prefix(output_directory)?
|
|
||||||
.components()
|
.components()
|
||||||
.count()
|
.count()
|
||||||
- 1;
|
- 1;
|
||||||
let prefix = "../".repeat(depth_from_web_root);
|
let prefix = "../".repeat(depth_from_web_root);
|
||||||
|
// TODO: It should be possible to strip some of the "../" components based on whether the path_from_web_root goes down the same path as the containing file.
|
||||||
let final_path = PathBuf::from(prefix).join(path_from_web_root);
|
let final_path = PathBuf::from(prefix).join(path_from_web_root);
|
||||||
let final_string = final_path
|
let final_string = final_path
|
||||||
.as_path()
|
.as_path()
|
||||||
@ -73,3 +81,29 @@ fn get_web_path<D: AsRef<Path>, F: AsRef<Path>, P: AsRef<Path>>(
|
|||||||
Ok(final_string)
|
Ok(final_string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn count_shared_steps<A: AsRef<Path>, B: AsRef<Path>>(left: A, right: B) -> usize {
|
||||||
|
let left = left.as_ref();
|
||||||
|
let right = right.as_ref();
|
||||||
|
left.components()
|
||||||
|
.zip(right.components())
|
||||||
|
.position(|(l, r)| l != r)
|
||||||
|
.unwrap_or_else(|| left.components().count())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_count_shared_steps() {
|
||||||
|
assert_eq!(count_shared_steps("", ""), 0);
|
||||||
|
assert_eq!(count_shared_steps("foo.txt", "foo.txt"), 1);
|
||||||
|
assert_eq!(count_shared_steps("cat/foo.txt", "dog/foo.txt"), 0);
|
||||||
|
assert_eq!(
|
||||||
|
count_shared_steps("foo/bar/baz/lorem.txt", "foo/bar/ipsum/dolar.txt"),
|
||||||
|
2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -31,16 +31,20 @@ pub(crate) struct RenderBlogPostPage {
|
|||||||
|
|
||||||
/// The title that will be shown visibly on the page.
|
/// The title that will be shown visibly on the page.
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
|
|
||||||
|
self_link: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderBlogPostPage {
|
impl RenderBlogPostPage {
|
||||||
pub(crate) fn new(
|
pub(crate) fn new(
|
||||||
global_settings: GlobalSettings,
|
global_settings: GlobalSettings,
|
||||||
title: Option<String>,
|
title: Option<String>,
|
||||||
|
self_link: Option<String>,
|
||||||
) -> RenderBlogPostPage {
|
) -> RenderBlogPostPage {
|
||||||
RenderBlogPostPage {
|
RenderBlogPostPage {
|
||||||
global_settings,
|
global_settings,
|
||||||
title,
|
title,
|
||||||
|
self_link,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user