MacDownApp / macdown

Open source Markdown editor for macOS.
https://macdown.uranusjr.com/
9.45k stars 1.09k forks source link

Add option to replace Jekyll media path to local repo path #416

Open galaxy001 opened 9 years ago

galaxy001 commented 9 years ago

Some Jekyll site have to set media path to absolute path like /assets/images/test.jpg, and cannot be rendered on local machine.

If user can provide Jekyll repo path like ~/git/test.github.io, it will be helpful to format those media with URL begin as / to ~/git/test.github.io/assets/images/test.jpg.

uranusjr commented 9 years ago

How should this be provided then? With a global preference? Would an entry inside the Jekyll front matter work? Something like:

media_root: ~/git/test.github.io
galaxy001 commented 9 years ago

Global preference is a easy way.

A smarter way should be check whether the opened file is in a git repo with git rev-parse --show-toplevel, and set that dir as media_root.

And, ~ is not working in HTML, we should use real path in HTML.

uranusjr commented 9 years ago

I don’t really want to tie things to a specific tool, so the git trick is out. Setting a global preference is easy, but might not make a lot of sense if you want to manage multiple sites.

Maybe something like EditorConfig is better (just thinking out loud). #396 seems like a more general version of this problem.

galaxy001 commented 9 years ago

In #396, since you are going to search every path along something like /User/Galaxy/Documents/git/myblog/_posts/2016-01-01.md for .macdown, it should also be acceptable to check whether the first /root/prefixed/media.png can be found as ./root/prefixed/media.png.

Such as, /root/prefixed/media.png can be found as /User/Galaxy/Documents/git/myblog/./root/prefixed/media.png.

Then, if media_root is not set, we can maintain a in-memory hash to remember all file within /User/Galaxy/Documents/git/myblog/_posts/ should have their media_root set to /User/Galaxy/Documents/git/myblog/.

Of course some counting on different root-prefixed-medias will make it more smart.

lacl-upec commented 8 years ago

A global preference and some symlinks can easily do the trick. From now on, I made links in / (yes really ugly workaround) but a "root directory" global option is the only thing I need.

zimmeee commented 8 years ago

Forgive me, as I'm new to both Macdown and Jekyll. I'm not sure if this issue is solved, or not.

This is what my markdown looks like: ![Withings Aura Sleep System]({{ site.baseurl }}/media/withings-aura.jpg) *The Withings Aura Smart Sleep system*

When I run Jekyll build, the URL is properly resolved and the images are displayed in the compiled post. In MacDown preview, the images cannot be found, presumably, because I don't know how to tell MacDown the value of site.baseurl. Is this possible to do?

FranklinYu commented 8 years ago

@zimmeee If the per-file configuration mentioned in #396 is finally implemented, then maybe we can allow user to specify site.baseurl there. I agree with @uranusjr on this topic (per-file/per-project settings over global settings).

FranklinYu commented 8 years ago

@galaxy001 I think you mean this:

When MacDown open a file

/User/Galaxy/Documents/git/myblog/_posts/2016-01-01.md

with an image path /root/prefixed/media.png, if MacDown cannot find the image at /root/prefixed/media.png, it search all its parent folders in the path, i.e.

For each of the paths, try appending the image path to it, yielding

for the first path where an image is found,

  1. use that image, and
  2. cache the path for other images in the same Markdown document.

Please correct me if I missed anything.

galaxy001 commented 8 years ago

@franklinyu Yes. I hope this can be added soon.

Further more, if necessary, the searching result for each folder can be cached into MacDown user data, and the cached path should be tried first for all files inside same folder.

zimmeee commented 8 years ago

This would be an awesome improvement to the workflow of anybody using Macdown to author Jekyll blogs!

uranusjr commented 8 years ago

@franklinyu This looks like a good solution. Honestly I have no idea how to implement it into the WebView API, but this should be the way to go.

FranklinYu commented 8 years ago

@galaxy001 By

Further more, if necessary, the searching result for each folder can be cached into MacDown user data, and the cached path should be tried first for all files inside same folder.

Do you mean that (continuing my example before) MacDown save something like this as a per-user preference:

(I replaced /User/Galaxy/Documents/git with $REPO_DIR because the former is a bit too long.)

galaxy001 commented 8 years ago

Yes, sort of.

A more representative example is:

I mean, this is a per directory record.

Moreover, I am not sure whether it is possible to be more smart as below:

Which is a per git repo record.

However, the smart way might fail if someone use git submodule:

FranklinYu commented 8 years ago

@galaxy001 The "more smart" way depends on Git, while @uranusjr explicitly stated that

I don’t really want to tie things to a specific tool, so the git trick is out.

And I agree with this. Introducing a (complicated) external dependency for just a single use case (static site generator) sounds more like an overkill.

galaxy001 commented 8 years ago

@franklinyu @uranusjr So, will you consider the per directory record way ?

Static site generator support will be useful if we want to keep a notebook sync to web blog.

An example is:

FranklinYu commented 8 years ago

@galaxy001 Yes, that is a pretty feasible idea. However, I'm sorry that I cannot guarantee a timeline for this feature.