correct url
This commit is contained in:
parent
411ea64fcb
commit
e8f69a34b1
1 changed files with 21 additions and 19 deletions
|
@ -71,31 +71,33 @@ pub fn get_posts(location: &str) -> Vec<Post> {
|
||||||
let filename = fname.to_string_lossy();
|
let filename = fname.to_string_lossy();
|
||||||
let file_without_ext = filename.split_at(filename.len() - 3).0;
|
let file_without_ext = filename.split_at(filename.len() - 3).0;
|
||||||
|
|
||||||
let file_metadata = std::fs::read_to_string(format!("{location}/{filename}"))
|
let file_metadata = std::fs::read_to_string(f.path()).map_or_else(
|
||||||
.map_or_else(
|
|_| FileMetadataBlog {
|
||||||
|_| FileMetadataBlog {
|
title: Some(file_without_ext.into()),
|
||||||
title: Some(file_without_ext.into()),
|
..FileMetadataBlog::default()
|
||||||
..FileMetadataBlog::default()
|
},
|
||||||
},
|
|text| {
|
||||||
|text| {
|
let arena = Arena::new();
|
||||||
let arena = Arena::new();
|
|
||||||
|
|
||||||
let options = get_options();
|
let options = get_options();
|
||||||
let root = parse_document(&arena, &text, &options);
|
let root = parse_document(&arena, &text, &options);
|
||||||
let mut metadata = get(root, MType::Blog).blog.unwrap();
|
let mut metadata = get(root, MType::Blog).blog.unwrap();
|
||||||
|
|
||||||
// Always have a title
|
// Always have a title
|
||||||
metadata.title = metadata
|
metadata.title = metadata
|
||||||
.title
|
.title
|
||||||
.map_or_else(|| Some(file_without_ext.into()), Some);
|
.map_or_else(|| Some(file_without_ext.into()), Some);
|
||||||
|
|
||||||
metadata
|
metadata
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) {
|
if file_metadata.publish == Some(true) && file_metadata.draft != Some(true) {
|
||||||
|
let url =
|
||||||
|
f.path().to_string_lossy().strip_prefix(location).unwrap()[1..].to_owned();
|
||||||
|
|
||||||
Some(Post {
|
Some(Post {
|
||||||
url: file_without_ext.into(),
|
url: url[..url.len() - 3].to_owned(),
|
||||||
title: file_metadata.title.unwrap(),
|
title: file_metadata.title.unwrap(),
|
||||||
date: file_metadata.date.unwrap_or({
|
date: file_metadata.date.unwrap_or({
|
||||||
let m = f.metadata().unwrap();
|
let m = f.metadata().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue