-
Notifications
You must be signed in to change notification settings - Fork 996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support colocating subfolders #1582
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,13 +74,6 @@ fn starts_with_schema(s: &str) -> bool { | |
PATTERN.is_match(s) | ||
} | ||
|
||
/// Colocated asset links refers to the files in the same directory, | ||
/// there it should be a filename only | ||
fn is_colocated_asset_link(link: &str) -> bool { | ||
!link.contains('/') // http://, ftp://, ../ etc | ||
&& !starts_with_schema(link) | ||
} | ||
|
||
Comment on lines
-77
to
-83
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could adjust this to match files in colocated subfolders as well. But I'm proposing to get rid of this completely instead. Why change relative links to absolute links? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I cannot remember |
||
/// Returns whether a link starts with an HTTP(s) scheme. | ||
fn is_external_link(link: &str) -> bool { | ||
link.starts_with("http:") || link.starts_with("https:") | ||
|
@@ -111,8 +104,6 @@ fn fix_link( | |
return Err(format!("Relative link {} not found.", link).into()); | ||
} | ||
} | ||
} else if is_colocated_asset_link(link) { | ||
format!("{}{}", context.current_page_permalink, link) | ||
} else { | ||
if is_external_link(link) { | ||
external_links.push(link.to_owned()); | ||
|
@@ -222,14 +213,6 @@ pub fn markdown_to_html(content: &str, context: &RenderContext) -> Result<Render | |
code_block = None; | ||
Event::Html("</code></pre>\n".into()) | ||
} | ||
Event::Start(Tag::Image(link_type, src, title)) => { | ||
if is_colocated_asset_link(&src) { | ||
let link = format!("{}{}", context.current_page_permalink, &*src); | ||
return Event::Start(Tag::Image(link_type, link.into(), title)); | ||
} | ||
|
||
Event::Start(Tag::Image(link_type, src, title)) | ||
} | ||
Event::Start(Tag::Link(link_type, link, title)) if link.is_empty() => { | ||
error = Some(Error::msg("There is a link that is missing a URL")); | ||
Event::Start(Tag::Link(link_type, "#".into(), title)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes are centered around this advice. Above, I replaced
read_dir
byWalkDir
to collect assets recursively. And everywhere where the collected assets are accessed I replaced.file_name()
with.strip_prefix(&page.file.path.parent().unwrap())
. Note that I wanted to use.strip_prefix(&page.file.parent)
originally but there is a special case for pages, whereparent
is actuallygrand_parent
, that breaks this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean when you have an asset folder? That's expected then since otherwise the parent would refer to the page itself
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's what I meant.