I wanted to add images in my blog posts. I now have path problems depending because the path to this image is not the same, depending on which page the post is displayed.
Example of the output:
jbake-sample
| about.html
| archive.html
| favicon.ico
| feed.xml
| index.html
| sitemap.xml
| tree.txt
|
+---blog
| \---2013
| first-post.html
| fourth-post.html
| jbake-logo.png
| second-post.html
| third-post.html
|
+---css
| ...
|
+---fonts
| ...
|
\---js
...
See it online: http://jmini.github.io/jbake-sample/
My problem is that the content of "fourth-post.adoc" (which uses this image) is printed at different places:
And the path to this image is not the same depending on the where the article is printed.
The path to the jbake-logo.png image is: ${rootpath}/blog/2013/jbake-logo.png
But the rootpath variable is template stuff and not something you can use in the post source.
My guess is that Asciidoctor could handle it (because there is this notion of variables) but it doesn’t make sense for HTML or Markdown sources.
I my opinion, it is the responsibility of JBake to fix the images path before including the post to the definitive page.
Please tell me if I missed something, otherwise I think I can fix it with a goovy method I will call before the post content is printed to the output file.
If anyone is interested, here is how my Proof of Concept code looks like to fix the image path. The idea is to fix the src attribute of all img tags before adding the content to the output file.
I will put this code in a Jar, add it on the JBake classpath (I am using the JBake maven plugin) and I will call it from the groovy template (in the gsp files).
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
public final class HtmlUtility {
public static String fixHtml(String htmlContent, String imgPrefixPath) {
Document doc = Jsoup.parseBodyFragment(htmlContent);
doc.outputSettings().charset("ASCII");
Elements elements = doc.getElementsByTag("img");
for (Element e : elements) {
String src = e.attr("src");
if (src != null) {
String newSrc = imgPrefixPath + src;
e.attr("src", newSrc);
}
}
return doc.body().html();
}
}
--
You received this message because you are subscribed to the Google Groups "JBake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Jon,
I am definitively interested…
The other types of path I can imagine are link to other pages/articles. Any other know issue in this domain?
My current solution relies on JSoup. Is this OK for you? Or do you prefer using another approach?
For the moment I did not took the time have a look at the code base. I need to setup an IDE for JBake.
I appreciate any pointer you can provide (What are the involved classes? Where should I add my code? ...).
I am happy to inform you that the version 1.0.1 of my Utility Class contains the fix that handle the "href" attribute of the <a> tag.
This demonstration site now works as expected:
http://jmini.github.io/jbake-sample
(Notice the image and the links on the first page).
Feedback is appreciated.
Next step for me: propose this implementation as a patch for JBake (as discussed in the previous messages).
--
Jon,
Was this merged in? If so, is it in the documentation how this would work?
Thanks,
Wade
--
You received this message because you are subscribed to the Google Groups "JBake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+unsubscribe@googlegroups.com.
Hi Wade,No a PR was never raised for this as far as I'm aware.Jon
On 3 May 2017 at 11:15, <m...@wadechandler.com> wrote:
On Tuesday, March 1, 2016 at 8:39:22 AM UTC-5, Jonathan Bullock wrote:
> Excellent, looking forward to merging in the patch :)
>
>
Jon,
Was this merged in? If so, is it in the documentation how this would work?
Thanks,
Wade
--
You received this message because you are subscribed to the Google Groups "JBake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+...@googlegroups.com.
2. Workaround - inside *.md we should have a conditional parsing like
if( #system.pages_are_for_index)
.....lines for index with all posts
else if( #system.pages_are_for_index)
..... lines for post
else if .... other tags fr other pages
How can we add lines to blogs that are parsed conditionally (we should have some way to path lines and some system variables to use)
Thank you
Dorin
--
You received this message because you are subscribed to the Google Groups "JBake Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+unsubscribe@googlegroups.com.
1. With workaround 1 Jbake generated code is already working here
https://storage.googleapis.com/apiabuc/jbake_test_100/output/index.html
I moved the specific pages like "about" into another directories because I have to manually or programmatic move and delete file at regenerating the site (output directory is not deleted by jbake -b, my engine generation of files and images toward jbake ...)
2. Any template language should offer a way to escape some special terms to you, to jbake. Conditional compiling of templates should be implemented in some of the template languages.
If some do not support, we have to migrate to other that can support escape forms. This is one use of compiling directoves, for this workarund, but in the future there may be other mandatory programming that we should do in templates and send info to JBake
Let me repeat here and check if it is good
if( #jbake.compile.pages_for_index)
.....lines for index with all posts (link type one to images = images/pic.jpg)
else if( #jbake.compile.details_pages)
..... lines for post (link type two to images = ../images/pic.jpg)
else if .... other tags for other pages, other links ...
Thank you
Dorin
You received this message because you are subscribed to a topic in the Google Groups "JBake Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jbake-user/64MiZRTl_3I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jbake-user+unsubscribe@googlegroups.com.
Hi Wade,1. I like this idea, it would enable Markdown and raw HTML content files to be independent of JBake like AsciiDoc files can be. Could you raise an issue for this on GitHub?
2. I may have mis-understood what you mean but this is possible right now via jbake.properties you can define any global meta-data in here and it's exposed to each of the template engines, it can also be injected/exported into Asciidoctor so the values are usable in AsciiDoc content as if they have been defined as attributes in the document.
3. I'm assuming you mean the whole content file would be made up of template engine syntax. This was explored in a pull request but never fully implemented. But I'm unsure how this would be beneficial, when the content file is processed by the relevant template engine what data model/context would be exposed for use during the conversion process from template syntax to HTML?
Perhaps we can explore an example scenario/file to flesh out how this would work?
4. This would solve a number of issues. Just to confirm we're on the same page I'm envisaging the template engine runs first and processes any template syntax then the content is passed to the relevant markup engine for processing. My initial thought was to use Groovy here as it provides much more than other template engines.
5. Manik (thanks for this by the way) has implemented a post processor that alters img src values to be relative as he's mentioned. It's a starting point and hopefully it can be expanded upon by the plugin/extension system eventually. This is scheduled to be included in 2.6.0 too.
Nothing is online beside the code presented in this utility class: HtmlUtility#fixHtml(..) method line 22
And the usage example in this repository: https://github.com/jmini/jbake-sample
Notice the modifications made to the templates (feed.gsp or index.gsp in commit b7aeb18)
---
I had a first look at the JBake code:
MarkupEngine line 130 [1] is in my opinion not the correct position to fix the HTML. The problem is not when the sources (markdown, asciidoctor or HTML) are read and converted to HTML, but when the content is written into its final destination.
With a “flat only” structure, you will have no problem at all. The problem starts to appear if you produce something like:
/feed.xml
/index.html
/blog/post1.html
/blog/img.png
With the sources:
src/main/jbake/content/blog/post1.md
src/main/jbake/templates/feed.gsp
src/main/jbake/templates/index.gsp
src/main/jbake/templates/post.gsp
When the content of "post1.md" is written to "/blog/post1.html", the paths to link, images and so on are correct. When the same content is written to "/index.html" or to "/feed.html", then the paths are broken.
My solution
is to fix it in the groovy template. This is probably too late. I think that not every templating engine allows to call an arbitrary Method of a utility class on the classpath as it is possible with Groovy.
When JBake provide a list like "published_posts" in the model of a template, then each ${post.body} should be correct for this template (given the fact that at this point the output location is clear).
My guess is that all extractors implementing ModelExtractor<DocumentList> are concerned by this transformation. I just need to figure out how I modify how I modify the "body" attribute of each of the documents extracted by the query. I also need to be sure that this will not induce any side effect (I do not want to modify the document itself but just the copy of the body, given one specific extraction context). I also need to write tests for that.
I would be happy to know what you think.
[1] https://github.com/jbake-org/jbake/blob/master/src/main/java/org/jbake/parser/MarkupEngine.java#L130
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to jbake-user+unsubscribe@googlegroups.com.