kaushalmodi / ox-hugo

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

file with toc can not export with make md #439

Closed vinurs closed 2 years ago

vinurs commented 3 years ago

in the org file i have a section like this

* Tablecontents :TOC:
- [[#header1][header1]]
  - [[#header2][header2]]
- [[#footnotes][Footnotes]]

i use the org-toc update this section, when make md, it shows

Debugger entered--Lisp error: (org-link-broken "header1l")
  signal(org-link-broken ("header1"))
kaushalmodi commented 3 years ago

Can you share the complete Org file with which I can reproduce that error?

My gut feeling says that the "Header 1" section is missing the "header1" CUSTOM_ID.

vinurs commented 3 years ago
# -*- mode: org; -*-
#+hugo_base_dir: ~/sys-cfg/github/vinurs.github.io/
#+hugo_section: ../content/post/pkms
#+startup: show2levels

* Table Of Content :TOC:
- [[#header1][header1]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]

* header1
:PROPERTIES:
:export_title: header1
:export_description: header1
:export_author: vinurs
:export_email: <haiyuan.vinurs@gmail.com>
:export_date: 2021-04-13
:export_hugo_categories:
:export_hugo_tags: tag1 tag2
:export_hugo_draft: true
:export_file_name: 20d57dce-9330-4d45-b62f-3c74074a91dd
:export_hugo_auto_set_lastmod: t
:export_hugo_expirydate: 2999-01-01
:export_hugo_front_matter_key_replace: description>summary
:export_hugo_custom_front_matter: :from orgmode
:END:

hello, this is a test 11
#+hugo: more
babababaa

** history
*** 2021/04/13
+ draft

* Footnotes
* COMMENT Local Variables            :ARCHIVE:
# Local Variables:
# eval: (org-hugo-auto-export-mode -1)
# End:
kaushalmodi commented 3 years ago

[[#header1][header1]]

The link uses the # notation. So the Org exporter will expect some Org heading with CUSTOM_ID property set to header1. I believe you will see the same error using any exporter because the error is not specific to ox-hugo.

kaushalmodi commented 3 years ago

You might already know this, but you don't need a separate package to create that TOC; you can just use the Org #+toc keyword. You can find the documentation at https://ox-hugo.scripter.co/doc/org-toc/ .

vinurs commented 3 years ago

[[#header1][header1]]

The link uses the # notation. So the Org exporter will expect some Org heading with CUSTOM_ID property set to header1. I believe you will see the same error using any exporter because the error is not specific to ox-hugo.

yes, this Table Of Content is auto generated by :TOC:

vinurs commented 3 years ago

for me, there is no need to export the toc, i use the toc section is that i want to see all toc in this file when i write sth in this file

vinurs commented 3 years ago

it's not ox-hugo's problem

kaushalmodi commented 3 years ago

yes, this Table Of Content is auto generated by :TOC:

Correct, but that's using an external org-toc package. I meant to say that you don't need that if you want toc in the export.

Looking at https://github.com/alphapapa/org-make-toc, I think that it generates a TOC that's friendly with Org parsing on GitHub.. the generated TOC is not Org export friendly unless that package also inserts the CUSTOM_ID tag for each heading.

cc: @alphapapa Is my above understanding correct?

kaushalmodi commented 3 years ago

@vinurs

there is no need to export the toc

In that case, you can add noexport tag to that TOC heading.

kaushalmodi commented 3 years ago

@vinurs This works

#+hugo_base_dir: .

* Table Of Content :TOC:
- [[#header1][header1]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]

* header1
:PROPERTIES:
:export_title: header1
:custom_id: header1
:export_description: header1
:export_author: vinurs
:export_email: <haiyuan.vinurs@gmail.com>
:export_date: 2021-04-13
:export_hugo_categories:
:export_hugo_tags: tag1 tag2
:export_hugo_draft: true
:export_file_name: 20d57dce-9330-4d45-b62f-3c74074a91dd
:export_hugo_auto_set_lastmod: t
:export_hugo_expirydate: 2999-01-01
:export_hugo_front_matter_key_replace: description>summary
:export_hugo_custom_front_matter: :from orgmode
:END:

hello, this is a test 11
#+hugo: more
babababaa
** history
:PROPERTIES:
:custom_id: history
:END:
*** 2021/04/13
+ draft
* Footnotes
:PROPERTIES:
:custom_id: footnotes
:END:
vinurs commented 3 years ago

@vinurs This works

#+hugo_base_dir: .

* Table Of Content :TOC:
- [[#header1][header1]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]

* header1
:PROPERTIES:
:export_title: header1
:custom_id: header1
:export_description: header1
:export_author: vinurs
:export_email: <haiyuan.vinurs@gmail.com>
:export_date: 2021-04-13
:export_hugo_categories:
:export_hugo_tags: tag1 tag2
:export_hugo_draft: true
:export_file_name: 20d57dce-9330-4d45-b62f-3c74074a91dd
:export_hugo_auto_set_lastmod: t
:export_hugo_expirydate: 2999-01-01
:export_hugo_front_matter_key_replace: description>summary
:export_hugo_custom_front_matter: :from orgmode
:END:

hello, this is a test 11
#+hugo: more
babababaa
** history
:PROPERTIES:
:custom_id: history
:END:
*** 2021/04/13
+ draft
* Footnotes
:PROPERTIES:
:custom_id: footnotes
:END:

wow, thanks very much ^_^

kaushalmodi commented 3 years ago

@vinurs Just to close the loop, also see https://github.com/alphapapa/org-make-toc#known-issues.

vinurs commented 3 years ago

add noexport like this?

* Table Of Content :TOC: :noexport:
- [[#header2][header2]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]

it seems it has no effect

kaushalmodi commented 3 years ago

That's wrong way of appending tags to a heading. The right way is this:

* Table Of Content :TOC:noexport:
- [[#header2][header2]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]

But, you are right. I just realized that that will not solve this problem, because the org link sanity check happens in the entire Org document at the beginning of export.

The only solution is to fix the links by adding the CUSTOM_ID properties.

vinurs commented 3 years ago

yes, so the more troublesome thing is that when i modify the header, i must modify two places(header and custom id) at the same time

vinurs commented 3 years ago

it's strange, i set the :noexport: tag, and i didn't set any custom_id, i run org-hugo-export-to-md the org file can export to md file, why run make md can not

vinurs commented 3 years ago

the toc-org has a QUOTE tag that generate the following toc,

* Table Of Content :TOC:QUOTE:noexport:
#+BEGIN_QUOTE
- [[#header3][header3]]
  - [[#history][history]]
- [[#footnotes][Footnotes]]
#+END_QUOTE
kaushalmodi commented 3 years ago

why run make md can not

Because the ox-hugo exporter ensures that all Org links in the buffer are valid, so that internal linking works in ox-hugo exports.

kaushalmodi commented 3 years ago

when i modify the header, i must modify two places(header and custom id) at the same time

If you do this frequently, you should come up with a small interactive elisp function like change-current-org-header that does these: