kaushalmodi / ox-hugo

A carefully crafted Org exporter back-end for Hugo
https://ox-hugo.scripter.co
GNU General Public License v3.0
882 stars 132 forks source link

Allow exporting with broken links if `broken-links: t` #587

Closed kaushalmodi closed 2 years ago

kaushalmodi commented 2 years ago

Status


Discussed in https://github.com/kaushalmodi/ox-hugo/discussions/586

Originally posted by **Codeberg-AsGithubAlternative-buhtz** March 12, 2022 Hello I am getting the message `Unable to resolve link; aborting: "roam:git"` when using `org-hugo-export-wim-to-md`. See the full debug output at the end. In the context of org-roam especially when used for Zettelkasten it is usual to have dead links. A dead link is not an error just an information because it will remind you that there is something to do ("thinking further"). From `ox-publish` I know the variable `(setq org-export-with-broken-links t)`. It seems to me that this is not relevant for `ox-hugo`, correct? I did `M-x customize-group RET ox-hugo` but couldn't see an option like that there. Can ox-hugo export such links? It could just replace them with the string `ERROR`or whatever it wants. But it shouldn't stop the export process. ```emacs-lisp 1 Debugger entered--Lisp error: (org-link-broken "roam:git") 2 signal(org-link-broken ("roam:git")) 3 org-export-resolve-fuzzy-link((link (:type "fuzzy" :path "roam:git" :format bracket :raw-link "roam:git" :appli$ 4 #f(compiled-function (link) #)((link (:type "fuzzy" :path "roam:git" :format bracket :$ 5 #f(compiled-function (--data) #)((link (:type "fuzzy" :path "roam:git" :format bracket$ 6 mapc(#f(compiled-function (--data) #) (#("SSH-Key for Codeberg.org erstellen, um ohne $ 7 #f(compiled-function (--data) #)((paragraph (:begin 155 :end 294 :contents-begin 155 :$ 8 mapc(#f(compiled-function (--data) #) ((paragraph (:begin 155 :end 294 :contents-begin$ 9 #f(compiled-function (--data) #)((section (:begin 155 :end 295 :contents-begin 155 :co$ 10 mapc(#f(compiled-function (--data) #) ((section (:begin 155 :end 295 :contents-begin 1$ 11 #f(compiled-function (--data) #)((headline (:raw-value "Ziel" :begin 148 :end 295 :pre$ 12 mapc(#f(compiled-function (--data) #) ((section (:begin 1 :end 148 :contents-begin 1 :$ 13 #f(compiled-function (--data) #)((org-data nil (section (:begin 1 :end 148 :contents-b$ 14 org-element-map((org-data nil (section (:begin 1 :end 148 :contents-begin 1 :contents-end 148 :post-blank 0 :po$ 15 org-hugo--get-pre-processed-buffer() 16 org-hugo-export-wim-to-md(:all-subtrees) 17 (save-current-buffer (set-buffer (find-file-noselect org-file)) (message (format "[ox-hugo/export-all file %d/%$ 18 (let ((org-file (car --dolist-tail--))) (save-current-buffer (set-buffer (find-file-noselect org-file)) (messag$ 19 (while --dolist-tail-- (let ((org-file (car --dolist-tail--))) (save-current-buffer (set-buffer (find-file-nose$ 20 (let ((--dolist-tail-- org-files)) (while --dolist-tail-- (let ((org-file (car --dolist-tail--))) (save-current$ 21 (progn (message (format (if dont-recurse "[ox-hugo/export-all] Exporting %d files from %S .." "[ox-hugo/export-$ 22 (if (= 0 num-files) (message (format "No Org files found in %s" search-path)) (progn (message (format (if dont-$ 23 (let* ((org-files-root-dir (or org-files-root-dir default-directory)) (dont-recurse (or dont-recurse (and curre$ 24 ox-hugo/export-all("~/tab-cloud/my.org-roam") 25 eval((ox-hugo/export-all "~/tab-cloud/my.org-roam") t) 26 eval-expression((ox-hugo/export-all "~/tab-cloud/my.org-roam") nil nil 127) 27 funcall-interactively(eval-expression (ox-hugo/export-all "~/tab-cloud/my.org-roam") nil nil 127) 28 call-interactively(eval-expression nil nil) 29 command-execute(eval-expression) ```
kaushalmodi commented 2 years ago

The issue stems from the fact that the broken link errors are not masked using the broken_links:t option when pre-processing the buffer. See https://github.com/kaushalmodi/ox-hugo/issues/447#issuecomment-862397524

kaushalmodi commented 2 years ago

Update: This workaround is not needed any more; fixed in https://github.com/kaushalmodi/ox-hugo/pull/596.


@Codeberg-AsGithubAlternative-buhtz

This is not a proper fix. Please undo the following workaround once this issue is fixed.

For now, I think that if you set this internal variable to nil, this issue can be bypassed. Put this in your emacs config:

(with-eval-after-load 'ox-hugo
  (setq org-hugo--preprocess-buffer nil))
buhtz commented 2 years ago

That is the reproducing org-file

:PROPERTIES:
:ID:       0ee70e23-8aec-44a6-abd1-8ed1935b58e8
:END:
#+title: SSH-key for Codeberg.org
+date: [2022-02-05 Sa 22:02]
#+filetags: Wiki
* Ziel
SSH-Key for Codeberg.org erstellen, um ohne Passwort [[roam:git]] nutzen zu können.
Hinweis: Jede Maschine sollte einen eigenen Key haben.

From the first view it looks like that the workaround with org-hug--preprocess-buffer works. Instead of you I did exactly this, which IMHO is use-package's equivalent of with-eval-after-load.

(use-package ox-hugo
  :config
  (setq org-hugo-base-dir "~/tab-cloud/my.org-html")
  (setq org-hugo--preprocess-buffer nil)
)

Everything is exported (over 100 files) and the last message is "Done!".

o you see that error when you export using ox-md or ox-html

I did not understand that comment. I do not know ox-md or ox-html and does not know if this is a function, variable, package, etc I am sorry but it is still not easy for me to dive through the emacs-universe. ;)

kaushalmodi commented 2 years ago

I do not know ox-md or ox-html

They are Org built-in exporters. But that's alright, given that that workaround worked, this issue is definitely in ox-hugo.

kaushalmodi commented 2 years ago

Unrelated:

I think you are missing a # in the beginning of the line here on the date line:

:PROPERTIES:
:ID:       0ee70e23-8aec-44a6-abd1-8ed1935b58e8
:END:
#+title: SSH-key for Codeberg.org
+date: [2022-02-05 Sa 22:02]
buhtz commented 2 years ago

Unrelated: I think you are missing a # in the beginning of the line here on the date line:

IMHO I do not. Some orgroam folks told me that this is editors decision if someone use #+ or +. I saw both variants in a lot of tutorials and videos I wondered about that in the beginning. But I am not sure about this. And I can not find my original question again.

kaushalmodi commented 2 years ago

I have personally never used or seen keywords begin with a plain +.

See the Org manual: https://orgmode.org/manual/In_002dbuffer-Settings.html

I saw both variants in a lot of tutorials and videos I wondered about that in the beginning.

If you see this again, I think you should report that issue. I am actually surprised if the keywords starting with just "+" are even getting parsed for you.

kaushalmodi commented 2 years ago

@Codeberg-AsGithubAlternative-buhtz If you don't do subtree-based export (which I believe would be the case if you have only org-roam files), this issue is fixed for you indirectly by the nature of fixing https://github.com/kaushalmodi/ox-hugo/issues/589.

I'll leave this issue open until it truly gets fixed.

kaushalmodi commented 2 years ago

You can remove this workaround now.