* why prepend "file://" to abs paths in html output?
@ 2017-07-08 0:38 Matt Price
2017-07-08 10:33 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Matt Price @ 2017-07-08 0:38 UTC (permalink / raw)
To: Org Mode
[-- Attachment #1: Type: text/plain, Size: 944 bytes --]
in org-html-link local links of the form
"/some/path/to/file"
are rewritten as
"file:///some/path/to/file".
This makes it difficult to write root-relative URL's in the way that one
might expect to be able to (so that export produces links like
<img src="/static/images/unicorn.jpg"/>
Is this really the most desirable behaviour? In html export, at least, I
would think most users would want to allow links of the kind I described.
But this seems like a conscious design decision; cf. these lines from
org-html-link:
;; If file path is absolute, prepend it with protocol
;; component - "file://".
(cond
((file-name-absolute-p raw-path)
(setq raw-path (org-export-file-uri raw-path)))
((and home use-abs-url)
(setq raw-path (concat (file-name-as-directory home) raw-path))))
I'm wondering whether a user oculd at least set a defcustom to control this
behaviour.
Thanks,
Matt
[-- Attachment #2: Type: text/html, Size: 1369 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 0:38 why prepend "file://" to abs paths in html output? Matt Price
@ 2017-07-08 10:33 ` Nicolas Goaziou
2017-07-08 12:37 ` Kaushal Modi
0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-08 10:33 UTC (permalink / raw)
To: Matt Price; +Cc: Org Mode
Hello,
Matt Price <moptop99@gmail.com> writes:
> in org-html-link local links of the form
>
> "/some/path/to/file"
>
> are rewritten as
>
> "file:///some/path/to/file".
>
> This makes it difficult to write root-relative URL's in the way that one
> might expect to be able to (so that export produces links like
>
> <img src="/static/images/unicorn.jpg"/>
>
> Is this really the most desirable behaviour? In html export, at least, I
> would think most users would want to allow links of the kind I described.
> But this seems like a conscious design decision; cf. these lines from
> org-html-link:
>
> ;; If file path is absolute, prepend it with protocol
> ;; component - "file://".
> (cond
> ((file-name-absolute-p raw-path)
> (setq raw-path (org-export-file-uri raw-path)))
> ((and home use-abs-url)
> (setq raw-path (concat (file-name-as-directory home) raw-path))))
>
> I'm wondering whether a user oculd at least set a defcustom to control this
> behaviour.
Let me ask this the other way: is there any situation where "file://"
prefix is desirable?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 10:33 ` Nicolas Goaziou
@ 2017-07-08 12:37 ` Kaushal Modi
2017-07-08 14:08 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-07-08 12:37 UTC (permalink / raw)
To: Nicolas Goaziou, Matt Price; +Cc: Org Mode
[-- Attachment #1: Type: text/plain, Size: 323 bytes --]
On Sat, Jul 8, 2017, 6:35 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
> Let me ask this the other way: is there any situation where "file://"
> prefix is desirable?
>
I don't see why "file://" would be useful in html exports (or pdf, md,
etc). It is probably needed only in org to org exports.
> --
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 825 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 12:37 ` Kaushal Modi
@ 2017-07-08 14:08 ` Nicolas Goaziou
2017-07-08 14:19 ` Carsten Dominik
0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-08 14:08 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Org Mode
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> I don't see why "file://" would be useful in html exports
OK. Il remove the file:// scheme specifications then.
> (or pdf, md, etc).
Well, those are not related to network based protocols. Does it really
make a difference in those cases?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 14:08 ` Nicolas Goaziou
@ 2017-07-08 14:19 ` Carsten Dominik
2017-07-08 19:13 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Carsten Dominik @ 2017-07-08 14:19 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Org Mode, Kaushal Modi
[-- Attachment #1: Type: text/plain, Size: 709 bytes --]
I think it can be useful to write file: in the org-mode file, to make a
clear distinction from internal links. But once it is clear that something
is a link to a file, I guess you are right that it might not be needed in
HTML. We will see what breaks.....
Carsten
On Sat, Jul 8, 2017 at 4:08 PM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> Hello,
>
> Kaushal Modi <kaushal.modi@gmail.com> writes:
>
> > I don't see why "file://" would be useful in html exports
>
> OK. Il remove the file:// scheme specifications then.
>
> > (or pdf, md, etc).
>
> Well, those are not related to network based protocols. Does it really
> make a difference in those cases?
>
> Regards,
>
> --
> Nicolas Goaziou
>
>
[-- Attachment #2: Type: text/html, Size: 1242 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 14:19 ` Carsten Dominik
@ 2017-07-08 19:13 ` Nicolas Goaziou
2017-07-08 23:37 ` Tim Cross
0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-08 19:13 UTC (permalink / raw)
To: Carsten Dominik; +Cc: Org Mode, Kaushal Modi
Hello,
Carsten Dominik <dominik@uva.nl> writes:
> I think it can be useful to write file: in the org-mode file, to make a
> clear distinction from internal links. But once it is clear that something
> is a link to a file, I guess you are right that it might not be needed in
> HTML. We will see what breaks.....
Thinking about it, we should probably not remove the "file://" prefix.
I cannot think of any situation where [[/absolute/path/to/file]] would
match something like "<img src="/absolute/path/to/file"/>", because "/"
never matches web root directory.
IOW, to re-use the OP's example, [[/static/images/unicorn.jpg]] is never
a valid Org link, in the sense that it points to a non-existing file.
Since the OP is writing a link only valid during HTML export, he might
as well write raw HTML.
Note that that "file:///static/images/unicorn.jpg" is not useful either,
but at least it is logical.
The only situation where we might do something is during publishing,
when we know what web root directory – i.e., base directory – is. In
that case, we could replace absolute file names starting with web root
dir as root-relative URL.
WDYT?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 19:13 ` Nicolas Goaziou
@ 2017-07-08 23:37 ` Tim Cross
2017-07-09 10:45 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Tim Cross @ 2017-07-08 23:37 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Carsten Dominik, Org Mode, Kaushal Modi
Ni Nicolas,
I think I agree.
If I export org files as HTML for use on my local system, I probably
want 'real' links and file:/// is probably the right thing as I don't
want to have to also install the files in a local web server. However,
when I want to export files to HTML and have them served by a web
server, file:/// is not the right thing.
Perhaps we need a way to easily set a context for web exports. If the
context is set, then use it, otherwise, use file:/// (actually, I
thought this was already there, but it has been a while since I did html
exports where links were necessary).
Tim
Nicolas Goaziou writes:
> Hello,
>
> Carsten Dominik <dominik@uva.nl> writes:
>
>> I think it can be useful to write file: in the org-mode file, to make a
>> clear distinction from internal links. But once it is clear that something
>> is a link to a file, I guess you are right that it might not be needed in
>> HTML. We will see what breaks.....
>
> Thinking about it, we should probably not remove the "file://" prefix.
>
> I cannot think of any situation where [[/absolute/path/to/file]] would
> match something like "<img src="/absolute/path/to/file"/>", because "/"
> never matches web root directory.
>
> IOW, to re-use the OP's example, [[/static/images/unicorn.jpg]] is never
> a valid Org link, in the sense that it points to a non-existing file.
> Since the OP is writing a link only valid during HTML export, he might
> as well write raw HTML.
>
> Note that that "file:///static/images/unicorn.jpg" is not useful either,
> but at least it is logical.
>
> The only situation where we might do something is during publishing,
> when we know what web root directory – i.e., base directory – is. In
> that case, we could replace absolute file names starting with web root
> dir as root-relative URL.
>
> WDYT?
>
> Regards,
--
Tim Cross
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-08 23:37 ` Tim Cross
@ 2017-07-09 10:45 ` Nicolas Goaziou
2017-07-10 12:53 ` Kaushal Modi
` (2 more replies)
0 siblings, 3 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-09 10:45 UTC (permalink / raw)
To: Tim Cross; +Cc: Carsten Dominik, Org Mode, Kaushal Modi
Hello,
Tim Cross <theophilusx@gmail.com> writes:
> Perhaps we need a way to easily set a context for web exports. If the
> context is set, then use it, otherwise, use file:/// (actually, I
> thought this was already there, but it has been a while since I did html
> exports where links were necessary).
The following patch implements `org-html-root', which allows to export
file links as root-relative URL. I'm not sure the docstring is clear
enough, tho.
Also, HTML publishing process always bind the above to publishing
directory, without user intervention.
So, basically, upon exporting the following document to HTML:
#+html_link_root: /tmp/
[[/tmp/unicorn.jpg]]
the link becomes
<img src="/unicorn.jpg" alt="unicorn.jpg" />
WDYT?
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-09 10:45 ` Nicolas Goaziou
@ 2017-07-10 12:53 ` Kaushal Modi
2017-07-10 13:31 ` Nicolas Goaziou
2017-07-10 13:58 ` Brett Viren
2017-07-10 22:12 ` Tim Cross
2 siblings, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-07-10 12:53 UTC (permalink / raw)
To: Nicolas Goaziou, Tim Cross; +Cc: Carsten Dominik, emacs-org list
[-- Attachment #1: Type: text/plain, Size: 3676 bytes --]
Hello,
On Sun, Jul 9, 2017, 6:45 AM Nicolas Goaziou <mail@nicolasgoaziou.fr> wrote:
>
> The following patch implements `org-html-root', which allows to export
> file links as root-relative URL.
Can you please attach the patch?
I'm
not sure the docstring is clear
> enough, tho.
>
Also, HTML publishing process always bind the above to publishing
> directory, without user intervention.
>
Matt and I are working on an exporter backend for Hugo, ox-hugo. We are
exporting Org to a flavor of Markdown compatible with Hugo. The HTML
exporter has some contribution in this exporter.
If a link is "/foo/bar" in the Markdown file, Hugo assumes "foo" to be
present in the "static/" dir in the site root. So the Markdown link auto
expands to "example.org/static/foo/bar".
But if the link was "/foo/bar" in the Org file to begin, with it would
become "file:///foo/bar" in Markdown (as it is a derivation of ox-md).
Though, we got around that by overriding the org-md-link function in
ox-hugo.
The complication arose when we needed to support "#+ATTR_HTML: :class
something" above figure links. We then needed to let the html link exporter
take up the link translation job instead of having ox-hugo do that directly
(it is OK to have HTML snippets in Markdown). And thus this request.
So, basically, upon exporting the following document to HTML:
>
> #+html_link_root: /tmp/
> [[/tmp/unicorn.jpg]]
>
> the link becomes
>
> <img src="/unicorn.jpg" alt="unicorn.jpg" />
>
Based on the example, that patch might work!
=====
Reply to an earlier email:
On Sat, Jul 8, 2017 at 3:14 PM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> Hello,
>
> Carsten Dominik <dominik@uva.nl> writes:
>
> > I think it can be useful to write file: in the org-mode file, to make a
> > clear distinction from internal links. But once it is clear that
> something
> > is a link to a file, I guess you are right that it might not be needed
> in
> > HTML. We will see what breaks.....
>
> Thinking about it, we should probably not remove the "file://" prefix.
>
It depends.. if people are using Org files exported as HTML to open
referenced files in their browser (though that would work only if they open
those HTML pages only on that machine). But at least in one browser
(Firefox), I noticed that the browser auto-added the "file://" prefix if
user tried to access "/static/images/unicorn.jpg" directly from the address
bar.
I cannot think of any situation where [[/absolute/path/to/file]] would
> match something like "<img src="/absolute/path/to/file"/>", because "/"
> never matches web root directory.
>
As mentioned above, one example is Hugo, which auto-interprets the presence
of absolute links in the Markdown files (whether they are of Markdown or
HTML style).
Note that that "file:///static/images/unicorn.jpg" is not useful either,
> but at least it is logical.
>
I can see the benefit if a browser does not support auto-detection of
local links. But if the patch works, all should be good :)
The only situation where we might do something is during publishing,
> when we know what web root directory – i.e., base directory – is. In
> that case, we could replace absolute file names starting with web root
> dir as root-relative URL.
>
In our case, we are delegating that step to Hugo. So Org does the job of
content translation from Org to Markdown (plus inline HTML code for
figures, etc) "as it is", and Hugo does the job of HTML, RSS, etc.
generation, content management (what goes in what directory), link
resolution, etc.
> --
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 6331 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-10 12:53 ` Kaushal Modi
@ 2017-07-10 13:31 ` Nicolas Goaziou
0 siblings, 0 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-10 13:31 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Carsten Dominik, Tim Cross, emacs-org list
[-- Attachment #1: Type: text/plain, Size: 141 bytes --]
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> Can you please attach the patch?
Oops. Here it is.
Regards,
--
Nicolas Goaziou
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-ox-html-Implement-root-directory-for-absolute-links.patch --]
[-- Type: text/x-diff, Size: 3521 bytes --]
From 6eed5dcd4e585dd32e52571189cf395b1a532310 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Date: Sun, 9 Jul 2017 12:40:49 +0200
Subject: [PATCH] ox-html: Implement root directory for absolute links
* lisp/ox-html.el (org-html-link-root): New variable.
(org-html-link): Use new variable.
(org-html-publish-to-html): Set root to base directory.
---
lisp/ox-html.el | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 2ceaf0722..edaec4df7 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -118,6 +118,7 @@
(:keywords "KEYWORDS" nil nil space)
(:html-html5-fancy nil "html5-fancy" org-html-html5-fancy)
(:html-link-use-abs-url nil "html-link-use-abs-url" org-html-link-use-abs-url)
+ (:html-link-root "HTML_LINK_ROOT" nil org-html-link-root)
(:html-link-home "HTML_LINK_HOME" nil org-html-link-home)
(:html-link-up "HTML_LINK_UP" nil org-html-link-up)
(:html-mathjax "HTML_MATHJAX" nil "" space)
@@ -1403,6 +1404,18 @@ example."
:package-version '(Org . "8.1")
:type 'boolean)
+(defcustom org-html-link-root nil
+ "Directory considered as web root.
+When non-nil, all links to absolute file names belonging to this
+directory become root-relative URL. Otherwise, such links keep
+the \"file:\" scheme."
+ :group 'org-export-html
+ :version "26.1"
+ :package-version '(Org . "9.1")
+ :type '(choice (const :tag "No root directory" nil)
+ (directory :tag "Local web root"))
+ :safe #'string-or-null-p)
+
(defcustom org-html-home/up-format
"<div id=\"org-div-home-and-up\">
<a accesskey=\"h\" href=\"%s\"> UP </a>
@@ -2993,12 +3006,19 @@ INFO is a plist holding contextual information. See
(setq raw-path
(funcall link-org-files-as-html-maybe raw-path info))
;; If file path is absolute, prepend it with protocol
- ;; component - "file://".
+ ;; component - "file://" or make it a root-relative URL.
(cond
((file-name-absolute-p raw-path)
- (setq raw-path (org-export-file-uri raw-path)))
+ (let ((root (plist-get info :html-link-root)))
+ (setq raw-path
+ (if (and root (file-in-directory-p raw-path root))
+ (concat "/"
+ (file-relative-name
+ (expand-file-name raw-path)
+ root))
+ (org-export-file-uri raw-path)))))
((and home use-abs-url)
- (setq raw-path (concat (file-name-as-directory home) raw-path))))
+ (setq raw-path (expand-file-name raw-path home))))
;; Add search option, if any. A search option can be
;; relative to a custom-id, a headline title, a name or
;; a target.
@@ -3762,18 +3782,22 @@ Return output file's name."
;;;###autoload
(defun org-html-publish-to-html (plist filename pub-dir)
- "Publish an org file to HTML.
+ "Publish an Org file to HTML.
FILENAME is the filename of the Org file to be published. PLIST
is the property list for the given project. PUB-DIR is the
publishing directory.
Return output file name."
- (org-publish-org-to 'html filename
- (concat "." (or (plist-get plist :html-extension)
- org-html-extension
- "html"))
- plist pub-dir))
+ (org-publish-org-to
+ 'html
+ filename
+ (concat "." (or (plist-get plist :html-extension)
+ org-html-extension
+ "html"))
+ (org-combine-plists `(:html-link-root ,(plist-get plist :base-directory))
+ plist)
+ pub-dir))
(provide 'ox-html)
--
2.13.2
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-09 10:45 ` Nicolas Goaziou
2017-07-10 12:53 ` Kaushal Modi
@ 2017-07-10 13:58 ` Brett Viren
2017-07-10 19:54 ` Kaushal Modi
2017-07-13 12:46 ` Nicolas Goaziou
2017-07-10 22:12 ` Tim Cross
2 siblings, 2 replies; 20+ messages in thread
From: Brett Viren @ 2017-07-10 13:58 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Carsten Dominik, Tim Cross, Org Mode, Kaushal Modi
[-- Attachment #1: Type: text/plain, Size: 1643 bytes --]
Hi Nicolas,
Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> So, basically, upon exporting the following document to HTML:
>
> #+html_link_root: /tmp/
> [[/tmp/unicorn.jpg]]
>
> the link becomes
>
> <img src="/unicorn.jpg" alt="unicorn.jpg" />
Is this saying "subtract the value of 'html_link_root' from the Org link
to make its URL"?
If so, I think this would not be general enough to help some cases. For
example, with Nikola+orgmode and with Nikola's "pretty URLs" option the
relative location between either the Org source or its generated HTML
and an image that they both link will differ.
Some details:
Nikola source wants this layout:
/path/to/my/nikola/posts/my-blog-post.org
/path/to/my/nikola/images/unicorn.jpg
The Org source generates to HTML which will be found at this URL path:
/mysiteroot/posts/my-blog-post/index.html
So, right now, either the Org link to the image must be written to be
invalid (for Org):
[[../../images/unicorn.jpg]]
Or, some mechanism needs to turn the valid Org link:
[[../images/unicorn.jpg]]
into either:
<img src="/mysiteroot/images/unicorn.jpg" ...>
or:
<img src="../../images/unicorn.jpg" ...>
I guess I could use html_link_root set to "/path/to/my/nikola" but then
my Org source loses portability.
I think better would be able to explicitly state the desired URL path
for the HTML <img> like:
#+html_url_path: /mysiteroot/images/unicorn.jpg
[[../images/unicorn.jpg]]
-Brett.
PS: imo, in this example, I think the real solution is to make Nikola
allow for keeping org+img source together and to output org+img+html all
together in one web directory.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 800 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-10 13:58 ` Brett Viren
@ 2017-07-10 19:54 ` Kaushal Modi
2017-07-10 21:44 ` Kaushal Modi
2017-07-13 12:39 ` Nicolas Goaziou
2017-07-13 12:46 ` Nicolas Goaziou
1 sibling, 2 replies; 20+ messages in thread
From: Kaushal Modi @ 2017-07-10 19:54 UTC (permalink / raw)
To: Brett Viren, Nicolas Goaziou; +Cc: Carsten Dominik, Tim Cross, Org Mode
[-- Attachment #1: Type: text/plain, Size: 2944 bytes --]
Hi Nicolas,
I tried out the patch, and my comments are in the MWE below.
On Mon, Jul 10, 2017 at 9:59 AM Brett Viren <bv@bnl.gov> wrote:
> Is this saying "subtract the value of 'html_link_root' from the Org link
> to make its URL"?
>
> If so, I think this would not be general enough to help some cases. For
> example, with Nikola+orgmode and with Nikola's "pretty URLs" option the
> relative location between either the Org source or its generated HTML
> and an image that they both link will differ.
>
Good point. I overlooked that.
I have this MWE that explains the "would like to have" vs "what this patch
gives us":
=====
#+TITLE: ox-html root dir
#+OPTIONS: toc:nil
#+STARTUP: inlineimages
#+HTML_LINK_ROOT: /tmp/site/static/
An =image.png= exists as =/tmp/site/static/images/image.png=.
* This is how the image links should have worked with the link root already
specified
[[/images/image.png]]
- The =HTML_LINK_ROOT= should to appended to the front of the above link if
that
concatenated path is a valid one.
- Would also like =C-x C-o=, inline image display, etc. to work.
- So a thought.. should the link root specification be made exporter
agnostic?
* This works after adding support for =HTML_LINK_ROOT= ..
.. but
- The link path becomes too long.
- Need to hard-code the full path to the site/blog root directory before
each of
such links.
[[file:/tmp/site/static/images/image.png]]
=====
> Some details:
>
> Nikola source wants this layout:
>
> /path/to/my/nikola/posts/my-blog-post.org
> /path/to/my/nikola/images/unicorn.jpg
>
> The Org source generates to HTML which will be found at this URL path:
>
> /mysiteroot/posts/my-blog-post/index.html
>
The organization for Hugo posts is something similar. So hopefully we can
have a solution that works for such blogging platforms in general.
In comparsion, the hugo paths would be:
/path/to/my/hugo/content/posts/my-blog-post.org
/path/to/my/hugo/static/images/unicorn.jpg
So, right now, either the Org link to the image must be written to be
> invalid (for Org):
>
> [[../../images/unicorn.jpg]]
>
Yeah, this is a problem and can probably be fixed if a support for
something like "#+LINK_ROOT" can be made in Org and not specific to an
exporter backend.
Or, some mechanism needs to turn the valid Org link:
>
> [[../images/unicorn.jpg]]
>
> into either:
>
> <img src="/mysiteroot/images/unicorn.jpg" ...>
>
> or:
>
> <img src="../../images/unicorn.jpg" ...>
>
> I guess I could use html_link_root set to "/path/to/my/nikola" but then
> my Org source loses portability.
>
> I think better would be able to explicitly state the desired URL path
> for the HTML <img> like:
>
> #+html_url_path: /mysiteroot/images/unicorn.jpg
> [[../images/unicorn.jpg]]
>
As I mention in my MWE, I am actually looking for a solution so that we do
not need to specify the "mysiteroot" for each link.. may be just one as a
"#+LINK_ROOT".
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 4558 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-10 19:54 ` Kaushal Modi
@ 2017-07-10 21:44 ` Kaushal Modi
2017-07-13 12:39 ` Nicolas Goaziou
1 sibling, 0 replies; 20+ messages in thread
From: Kaushal Modi @ 2017-07-10 21:44 UTC (permalink / raw)
To: Brett Viren, Nicolas Goaziou; +Cc: Carsten Dominik, Tim Cross, Org Mode
[-- Attachment #1: Type: text/plain, Size: 2376 bytes --]
Hello,
On Mon, Jul 10, 2017 at 3:54 PM Kaushal Modi <kaushal.modi@gmail.com> wrote:
> Hi Nicolas,
>
> I tried out the patch, and my comments are in the MWE below.
>
> I have this MWE that explains the "would like to have" vs "what this patch
> gives us":
>
> =====
> #+TITLE: ox-html root dir
> #+OPTIONS: toc:nil
> #+STARTUP: inlineimages
> #+HTML_LINK_ROOT: /tmp/site/static/
>
> An =image.png= exists as =/tmp/site/static/images/image.png=.
>
> * This is how the image links should have worked with the link root
> already specified
> [[/images/image.png]]
> - The =HTML_LINK_ROOT= should to appended to the front of the above link
> if that
> concatenated path is a valid one.
> - Would also like =C-x C-o=, inline image display, etc. to work.
> - So a thought.. should the link root specification be made exporter
> agnostic?
>
To expand on my MWE:
I have this patch on top of Nicolas's patch:
=====
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index 9e710e3e0a..410bb42eec 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -3011,11 +3011,12 @@ INFO is a plist holding contextual information. See
((file-name-absolute-p raw-path)
(let ((root (plist-get info :html-link-root)))
(setq raw-path
- (if (and root (file-in-directory-p raw-path root))
- (concat "/"
- (file-relative-name
- (expand-file-name raw-path)
- root))
+ (if (and root
+ (file-exists-p
+ (concat (file-name-as-directory root)
+ (replace-regexp-in-string
+ "\\`/" "" raw-path))))
+ raw-path
(org-export-file-uri raw-path)))))
((and home use-abs-url)
(setq raw-path (expand-file-name raw-path home))))
=====
This adds the root and link instead of having the root be a subset of link
(hope that makes sense).
With that, here is the updated MEW:
=====
#+TITLE: ox-html root dir
#+OPTIONS: toc:nil
#+STARTUP: inlineimages
#+HTML_LINK_ROOT: /tmp/site/static/
An =image.png= exists at =/tmp/site/static/images/image.png=.
* TODO [1/2] This is how the image links should have worked with the link
root already specified
[[/images/image.png]]
- [X] The =HTML_LINK_ROOT= should to appended to the front of the above
link if
that concatenated path is a valid one.
- [ ] Would also like =C-x C-o=, inline image display, etc. to work.
- So a thought.. should the link root specification be made exporter
agnostic?
=====
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 4388 bytes --]
^ permalink raw reply related [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-09 10:45 ` Nicolas Goaziou
2017-07-10 12:53 ` Kaushal Modi
2017-07-10 13:58 ` Brett Viren
@ 2017-07-10 22:12 ` Tim Cross
2 siblings, 0 replies; 20+ messages in thread
From: Tim Cross @ 2017-07-10 22:12 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Carsten Dominik, Org Mode, Kaushal Modi
Having seen the other posts on this, I think I'll need to spend more
time thinking about this and the various use cases. There is something
I'm having trouble putting my finger on which doesn't feel quite right,
but I feel I need to look more deeply into the whole idea of how to
export links generally. Originally, I was thinking just about HTML
export and just file:// vs site context specific links.
Based on what you have provided, this certainly does seem to address the
specific use case I was thinking of, but others have pointed out
additional considerations, so I'm now not sure if the suggested approach
won't improve one case while making others more difficult/restricted.
Tim
Nicolas Goaziou writes:
> Hello,
>
> Tim Cross <theophilusx@gmail.com> writes:
>
>> Perhaps we need a way to easily set a context for web exports. If the
>> context is set, then use it, otherwise, use file:/// (actually, I
>> thought this was already there, but it has been a while since I did html
>> exports where links were necessary).
>
> The following patch implements `org-html-root', which allows to export
> file links as root-relative URL. I'm not sure the docstring is clear
> enough, tho.
>
> Also, HTML publishing process always bind the above to publishing
> directory, without user intervention.
>
> So, basically, upon exporting the following document to HTML:
>
> #+html_link_root: /tmp/
> [[/tmp/unicorn.jpg]]
>
> the link becomes
>
> <img src="/unicorn.jpg" alt="unicorn.jpg" />
>
>
> WDYT?
>
> Regards,
--
Tim Cross
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-10 19:54 ` Kaushal Modi
2017-07-10 21:44 ` Kaushal Modi
@ 2017-07-13 12:39 ` Nicolas Goaziou
2017-07-13 12:50 ` Kaushal Modi
1 sibling, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-13 12:39 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Brett Viren, Carsten Dominik, Org Mode, Tim Cross
Hello,
Kaushal Modi <kaushal.modi@gmail.com> writes:
> #+HTML_LINK_ROOT: /tmp/site/static/
>
> An =image.png= exists as =/tmp/site/static/images/image.png=.
>
> * This is how the image links should have worked with the link root already
> specified
> [[/images/image.png]]
There is only one possible interpretation of this: look for the file at
"/images/image.png", which probably doesn't exist.
> - The =HTML_LINK_ROOT= should to appended to the front of the above link if
> that
> concatenated path is a valid one.
> - Would also like =C-x C-o=, inline image display, etc. to work.
> - So a thought.. should the link root specification be made exporter
> agnostic?
> * This works after adding support for =HTML_LINK_ROOT= ..
> .. but
> - The link path becomes too long.
> - Need to hard-code the full path to the site/blog root directory before
> each of
> such links.
> [[file:/tmp/site/static/images/image.png]]
ISTM you are looking after link abbreviations.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-10 13:58 ` Brett Viren
2017-07-10 19:54 ` Kaushal Modi
@ 2017-07-13 12:46 ` Nicolas Goaziou
1 sibling, 0 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-13 12:46 UTC (permalink / raw)
To: Brett Viren; +Cc: Tim Cross, Carsten Dominik, Org Mode, Kaushal Modi
Hello,
Brett Viren <bv@bnl.gov> writes:
> Nikola source wants this layout:
>
> /path/to/my/nikola/posts/my-blog-post.org
> /path/to/my/nikola/images/unicorn.jpg
>
> The Org source generates to HTML which will be found at this URL path:
>
> /mysiteroot/posts/my-blog-post/index.html
>
> So, right now, either the Org link to the image must be written to be
> invalid (for Org):
>
> [[../../images/unicorn.jpg]]
Your examples do not apply here, as we are talking about absolute file
names.
Relative links are exported as relative URL, which is good in most
cases. The remaining cases can be dealt with filters or some such or by
back-end themselves.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-13 12:39 ` Nicolas Goaziou
@ 2017-07-13 12:50 ` Kaushal Modi
2017-07-13 12:55 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-07-13 12:50 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Brett Viren, Carsten Dominik, Org Mode, Tim Cross
[-- Attachment #1: Type: text/plain, Size: 609 bytes --]
On Thu, Jul 13, 2017 at 8:39 AM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
>
> There is only one possible interpretation of this: look for the file at
> "/images/image.png", which probably doesn't exist.
>
I agree. It's definitely less confusing to an unknowing user with that
strict definition.
ISTM you are looking after link abbreviations.
>
Hmm. Thanks for that hint. Would it be OK to define backend-specific link
abbreviations?
I'd like to eventually merge ox-hugo[1] into Org. So would like to stay in
line with the conventions.
[1]: https://github.com/kaushalmodi/ox-hugo
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 1268 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-13 12:50 ` Kaushal Modi
@ 2017-07-13 12:55 ` Nicolas Goaziou
2017-07-13 13:01 ` Kaushal Modi
0 siblings, 1 reply; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-13 12:55 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Brett Viren, Carsten Dominik, Org Mode, Tim Cross
Kaushal Modi <kaushal.modi@gmail.com> writes:
> Hmm. Thanks for that hint. Would it be OK to define backend-specific link
> abbreviations?
I don't think so.
Back-end are able to manipulate links the way they want without Org core
interfering. IOW, this black magick should operate whitin "ox-hugo.el"
itself, IMO.
BTW, I still don't understand why an export back-end (unlike an user)
would need to use link abbreviations.
Regards,
--
Nicolas Goaziou
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-13 12:55 ` Nicolas Goaziou
@ 2017-07-13 13:01 ` Kaushal Modi
2017-07-13 13:14 ` Nicolas Goaziou
0 siblings, 1 reply; 20+ messages in thread
From: Kaushal Modi @ 2017-07-13 13:01 UTC (permalink / raw)
To: Nicolas Goaziou; +Cc: Brett Viren, Carsten Dominik, Org Mode, Tim Cross
[-- Attachment #1: Type: text/plain, Size: 1093 bytes --]
On Thu, Jul 13, 2017 at 8:55 AM Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:
> Kaushal Modi <kaushal.modi@gmail.com> writes:
>
> > Hmm. Thanks for that hint. Would it be OK to define backend-specific link
> > abbreviations?
>
> I don't think so.
>
> Back-end are able to manipulate links the way they want without Org core
> interfering. IOW, this black magick should operate whitin "ox-hugo.el"
> itself, IMO.
>
I meant "Would it be OK to have ox-hugo.el define a link abbreviation like
`hugo-static:' for the user?" That way, each user of ox-hugo.el does not
have to do that in their configs.
> BTW, I still don't understand why an export back-end (unlike an user)
> would need to use link abbreviations.
For static site generators like Hugo, Nikola, etc. it is conventional to
dump all "static" attachments like images, code files, etc in a fixed
"static/" (or something like that) in the blog structure.
So it is very common to have all static links begin with
"/path/to/blog/root/static/" for a blog. (That's exactly the
#+HTML_LINK_ROOT I mentioned earlier.)
--
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 1810 bytes --]
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: why prepend "file://" to abs paths in html output?
2017-07-13 13:01 ` Kaushal Modi
@ 2017-07-13 13:14 ` Nicolas Goaziou
0 siblings, 0 replies; 20+ messages in thread
From: Nicolas Goaziou @ 2017-07-13 13:14 UTC (permalink / raw)
To: Kaushal Modi; +Cc: Brett Viren, Carsten Dominik, Org Mode, Tim Cross
Kaushal Modi <kaushal.modi@gmail.com> writes:
> I meant "Would it be OK to have ox-hugo.el define a link abbreviation like
> `hugo-static:' for the user?" That way, each user of ox-hugo.el does not
> have to do that in their configs.
Anything goes, but I'm quite certain there's a better way.
> For static site generators like Hugo, Nikola, etc. it is conventional to
> dump all "static" attachments like images, code files, etc in a fixed
> "static/" (or something like that) in the blog structure.
Then you could implement a function that detects static attachments
(e.g., per extension, or using a user-provided function), intercepts
links to such files, and rewrites them to the fixed "static/" directory.
Regards,
^ permalink raw reply [flat|nested] 20+ messages in thread
end of thread, other threads:[~2017-07-13 13:15 UTC | newest]
Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-08 0:38 why prepend "file://" to abs paths in html output? Matt Price
2017-07-08 10:33 ` Nicolas Goaziou
2017-07-08 12:37 ` Kaushal Modi
2017-07-08 14:08 ` Nicolas Goaziou
2017-07-08 14:19 ` Carsten Dominik
2017-07-08 19:13 ` Nicolas Goaziou
2017-07-08 23:37 ` Tim Cross
2017-07-09 10:45 ` Nicolas Goaziou
2017-07-10 12:53 ` Kaushal Modi
2017-07-10 13:31 ` Nicolas Goaziou
2017-07-10 13:58 ` Brett Viren
2017-07-10 19:54 ` Kaushal Modi
2017-07-10 21:44 ` Kaushal Modi
2017-07-13 12:39 ` Nicolas Goaziou
2017-07-13 12:50 ` Kaushal Modi
2017-07-13 12:55 ` Nicolas Goaziou
2017-07-13 13:01 ` Kaushal Modi
2017-07-13 13:14 ` Nicolas Goaziou
2017-07-13 12:46 ` Nicolas Goaziou
2017-07-10 22:12 ` Tim Cross
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).