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

Compatibility with Jekyll: where to find images (and other files) ? #5

Closed
taophp opened this issue Mar 1, 2016 · 8 comments
Closed

Comments

@taophp
Copy link
Contributor

taophp commented Mar 1, 2016

I just get this problem with images, but I suspect this will occur with all others files.
First, let me show you the directory structures of jekyll. Most of the MD files are stored in the directory _posts and that's main content of the website. Inside those files, relative URL are supposed to be relative to the top of the website. Images are usually stored elsewhere, as the _posts directory will not be published as it is. So let's say that images are stored in the img directory. So, we have this structure:

/
  _posts/
     my-first-short-story.md
     my-second-short-story.md
  img/
    beautiful.png
    ugly.png

So, in my-first-short-story.md, I have a image linked in markdown this way:
![Ugly...](img/ugly.png)
No problem for Jekyll. But Crowbook is not able to find the file when converting my-first-short-story.md.
I suspect this to affect any relative URL.

A solution may be to add an option to set the root to start with when using relative url, something like the base href directive in HTML.

@crowdagger
Copy link
Owner

Just so I get this right: if you want a link in my-first-short-story.md to my-second-short-story.md, is it

[Next story](_posts/my-second-short-story.md)

or

[Next story](my-second-short-story.md) 

? (or: do I need to add separate options for images and links or can it be the same one? ^^)

crowdagger added a commit that referenced this issue Mar 2, 2016
By default, links are computed relatively to the Markdown file that
uses them. Setting `base_path` allows to override this behaviour: in
this case, links will be relative to this path.

`base_path` sets the paths both for images and links, but it is
possible to set them independently, respectively with base_path.images
and base_path.links. Note that if base_path is set, these two options
won't be looked at.

Should fix issue #5.
@crowdagger
Copy link
Owner

I added the option to set it independently or as a a whole, so that should take care of it ^^ Probably won't work well for current HTML renderer, though (in case of image embedding, the whole self-contained page might start to show its limits anyway).

@crowdagger
Copy link
Owner

Also, these options currently don't work when used with the --set arguments instead of a book configuration file. Will probably fix that tomorrow.

@taophp
Copy link
Contributor Author

taophp commented Mar 2, 2016

To answer to your question #5 (comment), for links between post with Jekyll, it depends heavily on the way Jekyll is configured. Jekyll allows users to fine tune the URL they want to get from /example.org/categorie/2016/03/02/my-second-short-story.html to /example.org/my-second-short-story/ or many other variations. So a Jekyll user will never make a link from one md file to another like in your examples: he links to the existing or expected html output file. So, in the md file, you will have something like:

[Next story](/categorie/2016/03/02/my-second-short-story.html) 

or

[Next story](/my-second-short-story/) 

or (if the base href is expected)

[Next story](categorie/2016/03/02/my-second-short-story.html) 

or

[Next story](my-second-short-story/) 

In any case, a Jekyll user will link directly to a file stored in _posts as Jekyll uses _ as a prefix for files and directories that are not expected to be publish, but furnish data for some treatments.

Back to the original problem: considering images or links, the base href html directive works the same way. If set, it became the start for any relative url, instead of the current file. So I suggest that you mimic this for solving the problem due to the fact that, with Jekyll, the source directories structure is not the same as the target directories structure, and make Crowbook failed to find images from md files. I did not thought about links at the time, and I think this may require another a more complicated solution (but I don't know if I need it presently, so I may not bother with that). I have not tested the way currently handle url in links, relative or absolute. I suspect that it makes internal links from one chapter to another in the book ([Chapter 2](chapter2.md) become <a href="#chapter2">). In my case, (short story format), internal links point in the same md file ([Chapter2](#chap2)), so no change is required to the default Markdown behaviour in this case. But a problem may occur when pointing to another document of the website. I mean a link like /my-second-short-story.html has no sense inside a PDF file, you need the complete http://example.org/my-second-short-story.html. You see that the problem is very different from embedding images. You need an absolute base href to prefix all links. In the Jekyll configuration file, you may found some options that can help to solve the problem, but you can't seriously rely on them.
So the best seems to add 2 base href like options: one for embedding objects, a other for absolute linking on the web... Really, for me, I know as I will use the first (as I needed it yesterday evening). For the second, currently, I don't think I need it, but it might be useful to other users.

Cheers !

@taophp
Copy link
Contributor Author

taophp commented Mar 2, 2016

I should have read your commit comment in d0f006f before answering your question... I'll test it today, maybe this evening, but, I agree, this should solve this issue.

@crowdagger
Copy link
Owner

(I don't get when mentions in commits automatically close issues or not... Well, I guess it should be closed now since the --set option should now work with book_path. Not entirely sure everything is fixed, though ^^)

@taophp
Copy link
Contributor Author

taophp commented Mar 2, 2016

I was not aware of the ability to close issues directly with commit... seems a Github feature to me, and a not-so-good idea.

@taophp
Copy link
Contributor Author

taophp commented Mar 2, 2016

It seems to work well for me. Many thanks. 👍

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

2 participants