Skip to content
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

Can I replace spaces with dashes for URL generation? #95

Open
assopri opened this issue Apr 8, 2022 · 4 comments
Open

Can I replace spaces with dashes for URL generation? #95

assopri opened this issue Apr 8, 2022 · 4 comments

Comments

@assopri
Copy link

assopri commented Apr 8, 2022

Using your solution to generate website with Obsidian Zola. Can I somehow override the default URL generation mechanics of obsidian-export (to change spaces to dashes)?

@benbohmer
Copy link

This would be useful for many use cases, not only Zola!

@zoni
Copy link
Owner

zoni commented Nov 5, 2022

It's currently pretty hard-coded:

obsidian-export/src/lib.rs

Lines 674 to 688 in 6af4c91

let target_file = target_file.unwrap();
// We use root_file() rather than current_file() here to make sure links are always
// relative to the outer-most note, which is the note which this content is inserted into
// in case of embedded notes.
let rel_link = diff_paths(
target_file,
&context
.root_file()
.parent()
.expect("obsidian content files should always have a parent"),
)
.expect("should be able to build relative path when target file is found in vault");
let rel_link = rel_link.to_string_lossy();
let mut link = utf8_percent_encode(&rel_link, PERCENTENCODE_CHARS).to_string();

I'm not against making this more configurable/overrideable, but it would be nice to know what you're trying to achieve and why you would want a different behavior.

The intent of obsidian-export is to give you a normalized CommonMark input to feed to later processors (such as static site generators like Zola). It's obsidian-export's job to make sure that input has valid links/paths on the local filesystem that those tools can resolve correctly (which it currently does).

It's not intended to construct final URLs directly, as that's really the job of Hugo, Zola, etc. to do (because it's also their concern to change .md to .html, or to link to a directory instead of a file in case of "pretty URLs")

@zoni
Copy link
Owner

zoni commented Nov 5, 2022

Related issue: #73

@smaroukis
Copy link

smaroukis commented Oct 17, 2023

I also had an issue where I wanted to leave the spaces encoded as literal spaces, for a responsive image partial for a hugo site, which uses the image in markdown as

{{< imgh src="filename with spaces.png" alt="alt-text" >}}

(since the image filename itself is not renamed to be percent encoded by obsidian-export the partial does not find the asset)

Of course the partial could be changed to first percent encode the resource, but I'm just getting started with hugo...

Partial I'm using: https://mijndertstuij.nl/posts/hugo-responsive-images/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants