Khalid Rafi <[email protected]> writes:
>
> This is in the context of blogging. I omitted my base URL which is
> https://blog.khalidrafi.tech/ and only added the later parts of the
> URL. Thus, it's a relative link. So, I need that particular output in
> the resulting Markdown.

Yes, apologies. That was probably obvious to everybody else, but I made
the mistake of replying before finishing my first coffee. :)

As a personal info manager, Org thinks "/" is the root of your own
system. As the docs say, when publishing, it's best to use relative file
paths replicating the directory structure. But this is not always ideal
when writing.

One solution would be to use the full
https://blog.khalidrafi.tech/en/install-emacs-on-android URL, of course.

I once had the same problem for HTML export. Here's the solution I used,
adapted for Markdown: adding an export filter to turn any resulting
"file:///" links into "/" ones when publishing. Replace
"/path-to/base-dir/" with your own base directory (where you keep the
Org files for publishing to the website).


  (defun my/filter-root-links (output backend info)
    "Fix any root-relative references in links."
    ;; When backend is Markdown and we're in the base-dir for Org publishing
    (when (and (eq backend 'md)
                 (string-match "/path-to/base-dir/" (buffer-file-name)))
      (replace-regexp-in-string "file:///" "/" output)))  

  (add-to-list 'org-export-filter-link-functions
                 'my/filter-root-links)


This is not quite ideal either, because following those "/" links from your
Org file will not take you to your publishing base directory. For that,
it might be better to use file links to the full path of your base
directory and adapt the regexp in the above example to replace that.

Defining a new link type could be another solution to save typing and
have working links both in Org and in Markdown/HTML. Say, a `webroot'
link that you could use like: [[webroot:en/install-emacs-on-android]]
and that would add the slash to the exported link.

And perhaps someone knows of another, obvious solution I'm missing?

Regards,
Christian


Reply via email to