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

Internal linking to section indexes #564

Closed adbrown101 closed 2 years ago

adbrown101 commented 2 years ago

Actual Behavior

The exported internal links to the top of another section are broken or not unique.

[Articles Section]({{< relref "_index" >}})
[Articles Section](articles/.org)

Expected Behavior

Links to _index preceded by the section.

[Articles Section]({{< relref "/articles/_index.md" >}})
[Articles Section](/articles/)

How to Reproduce the Issue

See org file

Example Org File

#+HUGO_BASE_DIR: ../
#+TITLE: Test site
* Articles
:PROPERTIES:
:EXPORT_HUGO_SECTION: articles
:CUSTOM_ID: article-section
:END:
** Articles
:PROPERTIES:
:EXPORT_FILE_NAME: _index
:CUSTOM_ID: article-index
:END:
Some introduction text to introduce my index of articles.
* Blog
:PROPERTIES:
:EXPORT_HUGO_SECTION: blog
:CUSTOM_ID: blog-section
:END:
** Blog
:PROPERTIES:
:EXPORT_FILE_NAME: _index
:CUSTOM_ID: blog-index
:END:
Some introduction text to introduce the index of my blog posts. For longer articles please see the
 [[#article-index][Articles Section]] or is it the [[#article-section][Articles Section]].

Generated Markdown File or Error

+++
title = "Blog"
draft = false
+++

Some introduction text to introduce the index of my blog posts. For longer articles please see the
 [Articles Section]({{< relref "_index" >}}) or is it the [Articles Section](articles/.org).

Ox-Hugo Debug Information

Debug Info # Debug information for `ox-hugo` ## Emacs Version GNU Emacs 27.2 (build 1, x86_64-unknown-linux-gnu, X toolkit) of 2021-03-26 ## Org Version Org mode version 9.6 (9.6-??-e7ea951ac @ /home/alan/.emacs.d/.local/straight/build-27.2/org/) ## Hugo Version hugo v0.92.1+extended linux/amd64 BuildDate=unknown ### Org `load-path` shadows **Warning**: Possible mixed installation of Org /home/alan/.emacs.d/.local/straight/build-27.2/org/ox hides /usr/share/emacs/27.2/lisp/org/ox /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-texinfo hides /usr/share/emacs/27.2/lisp/org/ox-texinfo /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-publish hides /usr/share/emacs/27.2/lisp/org/ox-publish /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-org hides /usr/share/emacs/27.2/lisp/org/ox-org /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-odt hides /usr/share/emacs/27.2/lisp/org/ox-odt /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-md hides /usr/share/emacs/27.2/lisp/org/ox-md /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-man hides /usr/share/emacs/27.2/lisp/org/ox-man /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-latex hides /usr/share/emacs/27.2/lisp/org/ox-latex /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-icalendar hides /usr/share/emacs/27.2/lisp/org/ox-icalendar /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-html hides /usr/share/emacs/27.2/lisp/org/ox-html /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-beamer hides /usr/share/emacs/27.2/lisp/org/ox-beamer /home/alan/.emacs.d/.local/straight/build-27.2/org/ox-ascii hides /usr/share/emacs/27.2/lisp/org/ox-ascii /home/alan/.emacs.d/.local/straight/build-27.2/org/org hides /usr/share/emacs/27.2/lisp/org/org /home/alan/.emacs.d/.local/straight/build-27.2/org/org-version hides /usr/share/emacs/27.2/lisp/org/org-version /home/alan/.emacs.d/.local/straight/build-27.2/org/org-timer hides /usr/share/emacs/27.2/lisp/org/org-timer /home/alan/.emacs.d/.local/straight/build-27.2/org/org-tempo hides /usr/share/emacs/27.2/lisp/org/org-tempo /home/alan/.emacs.d/.local/straight/build-27.2/org/org-table hides /usr/share/emacs/27.2/lisp/org/org-table /home/alan/.emacs.d/.local/straight/build-27.2/org/org-src hides /usr/share/emacs/27.2/lisp/org/org-src /home/alan/.emacs.d/.local/straight/build-27.2/org/org-refile hides /usr/share/emacs/27.2/lisp/org/org-refile /home/alan/.emacs.d/.local/straight/build-27.2/org/org-protocol hides /usr/share/emacs/27.2/lisp/org/org-protocol /home/alan/.emacs.d/.local/straight/build-27.2/org/org-plot hides /usr/share/emacs/27.2/lisp/org/org-plot /home/alan/.emacs.d/.local/straight/build-27.2/org/org-pcomplete hides /usr/share/emacs/27.2/lisp/org/org-pcomplete /home/alan/.emacs.d/.local/straight/build-27.2/org/org-num hides /usr/share/emacs/27.2/lisp/org/org-num /home/alan/.emacs.d/.local/straight/build-27.2/org/org-mouse hides /usr/share/emacs/27.2/lisp/org/org-mouse /home/alan/.emacs.d/.local/straight/build-27.2/org/org-mobile hides /usr/share/emacs/27.2/lisp/org/org-mobile /home/alan/.emacs.d/.local/straight/build-27.2/org/org-macs hides /usr/share/emacs/27.2/lisp/org/org-macs /home/alan/.emacs.d/.local/straight/build-27.2/org/org-macro hides /usr/share/emacs/27.2/lisp/org/org-macro /home/alan/.emacs.d/.local/straight/build-27.2/org/org-loaddefs hides /usr/share/emacs/27.2/lisp/org/org-loaddefs /home/alan/.emacs.d/.local/straight/build-27.2/org/org-list hides /usr/share/emacs/27.2/lisp/org/org-list /home/alan/.emacs.d/.local/straight/build-27.2/org/org-lint hides /usr/share/emacs/27.2/lisp/org/org-lint /home/alan/.emacs.d/.local/straight/build-27.2/org/org-keys hides /usr/share/emacs/27.2/lisp/org/org-keys /home/alan/.emacs.d/.local/straight/build-27.2/org/org-install hides /usr/share/emacs/27.2/lisp/org/org-install /home/alan/.emacs.d/.local/straight/build-27.2/org/org-inlinetask hides /usr/share/emacs/27.2/lisp/org/org-inlinetask /home/alan/.emacs.d/.local/straight/build-27.2/org/org-indent hides /usr/share/emacs/27.2/lisp/org/org-indent /home/alan/.emacs.d/.local/straight/build-27.2/org/org-id hides /usr/share/emacs/27.2/lisp/org/org-id /home/alan/.emacs.d/.local/straight/build-27.2/org/org-habit hides /usr/share/emacs/27.2/lisp/org/org-habit /home/alan/.emacs.d/.local/straight/build-27.2/org/org-goto hides /usr/share/emacs/27.2/lisp/org/org-goto /home/alan/.emacs.d/.local/straight/build-27.2/org/org-footnote hides /usr/share/emacs/27.2/lisp/org/org-footnote /home/alan/.emacs.d/.local/straight/build-27.2/org/org-feed hides /usr/share/emacs/27.2/lisp/org/org-feed /home/alan/.emacs.d/.local/straight/build-27.2/org/org-faces hides /usr/share/emacs/27.2/lisp/org/org-faces /home/alan/.emacs.d/.local/straight/build-27.2/org/org-entities hides /usr/share/emacs/27.2/lisp/org/org-entities /home/alan/.emacs.d/.local/straight/build-27.2/org/org-element hides /usr/share/emacs/27.2/lisp/org/org-element /home/alan/.emacs.d/.local/straight/build-27.2/org/org-duration hides /usr/share/emacs/27.2/lisp/org/org-duration /home/alan/.emacs.d/.local/straight/build-27.2/org/org-datetree hides /usr/share/emacs/27.2/lisp/org/org-datetree /home/alan/.emacs.d/.local/straight/build-27.2/org/org-ctags hides /usr/share/emacs/27.2/lisp/org/org-ctags /home/alan/.emacs.d/.local/straight/build-27.2/org/org-crypt hides /usr/share/emacs/27.2/lisp/org/org-crypt /home/alan/.emacs.d/.local/straight/build-27.2/org/org-compat hides /usr/share/emacs/27.2/lisp/org/org-compat /home/alan/.emacs.d/.local/straight/build-27.2/org/org-colview hides /usr/share/emacs/27.2/lisp/org/org-colview /home/alan/.emacs.d/.local/straight/build-27.2/org/org-clock hides /usr/share/emacs/27.2/lisp/org/org-clock /home/alan/.emacs.d/.local/straight/build-27.2/org/org-capture hides /usr/share/emacs/27.2/lisp/org/org-capture /home/alan/.emacs.d/.local/straight/build-27.2/org/org-attach hides /usr/share/emacs/27.2/lisp/org/org-attach /home/alan/.emacs.d/.local/straight/build-27.2/org/org-attach-git hides /usr/share/emacs/27.2/lisp/org/org-attach-git /home/alan/.emacs.d/.local/straight/build-27.2/org/org-archive hides /usr/share/emacs/27.2/lisp/org/org-archive /home/alan/.emacs.d/.local/straight/build-27.2/org/org-agenda hides /usr/share/emacs/27.2/lisp/org/org-agenda /home/alan/.emacs.d/.local/straight/build-27.2/org/ol hides /usr/share/emacs/27.2/lisp/org/ol /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-w3m hides /usr/share/emacs/27.2/lisp/org/ol-w3m /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-rmail hides /usr/share/emacs/27.2/lisp/org/ol-rmail /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-mhe hides /usr/share/emacs/27.2/lisp/org/ol-mhe /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-irc hides /usr/share/emacs/27.2/lisp/org/ol-irc /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-info hides /usr/share/emacs/27.2/lisp/org/ol-info /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-gnus hides /usr/share/emacs/27.2/lisp/org/ol-gnus /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-eww hides /usr/share/emacs/27.2/lisp/org/ol-eww /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-eshell hides /usr/share/emacs/27.2/lisp/org/ol-eshell /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-docview hides /usr/share/emacs/27.2/lisp/org/ol-docview /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-bibtex hides /usr/share/emacs/27.2/lisp/org/ol-bibtex /home/alan/.emacs.d/.local/straight/build-27.2/org/ol-bbdb hides /usr/share/emacs/27.2/lisp/org/ol-bbdb /home/alan/.emacs.d/.local/straight/build-27.2/org/ob hides /usr/share/emacs/27.2/lisp/org/ob /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-tangle hides /usr/share/emacs/27.2/lisp/org/ob-tangle /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-table hides /usr/share/emacs/27.2/lisp/org/ob-table /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-sqlite hides /usr/share/emacs/27.2/lisp/org/ob-sqlite /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-sql hides /usr/share/emacs/27.2/lisp/org/ob-sql /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-shell hides /usr/share/emacs/27.2/lisp/org/ob-shell /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-sed hides /usr/share/emacs/27.2/lisp/org/ob-sed /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-screen hides /usr/share/emacs/27.2/lisp/org/ob-screen /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-scheme hides /usr/share/emacs/27.2/lisp/org/ob-scheme /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-sass hides /usr/share/emacs/27.2/lisp/org/ob-sass /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-ruby hides /usr/share/emacs/27.2/lisp/org/ob-ruby /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-ref hides /usr/share/emacs/27.2/lisp/org/ob-ref /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-python hides /usr/share/emacs/27.2/lisp/org/ob-python /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-processing hides /usr/share/emacs/27.2/lisp/org/ob-processing /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-plantuml hides /usr/share/emacs/27.2/lisp/org/ob-plantuml /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-perl hides /usr/share/emacs/27.2/lisp/org/ob-perl /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-org hides /usr/share/emacs/27.2/lisp/org/ob-org /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-octave hides /usr/share/emacs/27.2/lisp/org/ob-octave /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-ocaml hides /usr/share/emacs/27.2/lisp/org/ob-ocaml /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-maxima hides /usr/share/emacs/27.2/lisp/org/ob-maxima /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-matlab hides /usr/share/emacs/27.2/lisp/org/ob-matlab /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-makefile hides /usr/share/emacs/27.2/lisp/org/ob-makefile /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-lua hides /usr/share/emacs/27.2/lisp/org/ob-lua /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-lob hides /usr/share/emacs/27.2/lisp/org/ob-lob /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-lisp hides /usr/share/emacs/27.2/lisp/org/ob-lisp /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-lilypond hides /usr/share/emacs/27.2/lisp/org/ob-lilypond /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-latex hides /usr/share/emacs/27.2/lisp/org/ob-latex /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-js hides /usr/share/emacs/27.2/lisp/org/ob-js /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-java hides /usr/share/emacs/27.2/lisp/org/ob-java /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-haskell hides /usr/share/emacs/27.2/lisp/org/ob-haskell /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-groovy hides /usr/share/emacs/27.2/lisp/org/ob-groovy /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-gnuplot hides /usr/share/emacs/27.2/lisp/org/ob-gnuplot /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-fortran hides /usr/share/emacs/27.2/lisp/org/ob-fortran /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-forth hides /usr/share/emacs/27.2/lisp/org/ob-forth /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-exp hides /usr/share/emacs/27.2/lisp/org/ob-exp /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-eval hides /usr/share/emacs/27.2/lisp/org/ob-eval /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-eshell hides /usr/share/emacs/27.2/lisp/org/ob-eshell /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-emacs-lisp hides /usr/share/emacs/27.2/lisp/org/ob-emacs-lisp /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-dot hides /usr/share/emacs/27.2/lisp/org/ob-dot /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-ditaa hides /usr/share/emacs/27.2/lisp/org/ob-ditaa /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-css hides /usr/share/emacs/27.2/lisp/org/ob-css /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-core hides /usr/share/emacs/27.2/lisp/org/ob-core /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-comint hides /usr/share/emacs/27.2/lisp/org/ob-comint /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-clojure hides /usr/share/emacs/27.2/lisp/org/ob-clojure /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-calc hides /usr/share/emacs/27.2/lisp/org/ob-calc /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-awk hides /usr/share/emacs/27.2/lisp/org/ob-awk /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-R hides /usr/share/emacs/27.2/lisp/org/ob-R /home/alan/.emacs.d/.local/straight/build-27.2/org/ob-C hides /usr/share/emacs/27.2/lisp/org/ob-C Study the output of `M-x list-load-path-shadows`. ## `ox-hugo` defcustoms
org-hugo-section “posts”
org-hugo-use-code-for-kbd nil
org-hugo-preserve-filling t
org-hugo-delete-trailing-ws t
org-hugo-prefer-hyphen-in-tags t
org-hugo-allow-spaces-in-tags t
org-hugo-tag-processing-functions (org-hugo–tag-processing-fn-replace-with-spaces-maybe org-hugo–tag-processing-fn-replace-with-hyphens-maybe)
org-hugo-auto-set-lastmod nil
org-hugo-export-with-toc nil
org-hugo-export-with-section-numbers nil
org-hugo-front-matter-format “toml”
org-hugo-default-static-subdirectory-for-externals “ox-hugo”
org-hugo-external-file-extensions-allowed-for-copying (“jpg” “jpeg” “tiff” “png” “svg” “gif” “mp4” “pdf” “odt” “doc” “ppt” “xls” “docx” “pptx” “xlsx”)
org-hugo-date-format “%Y-%m-%dT%T%z”
org-hugo-paired-shortcodes “”
org-hugo-suppress-lastmod-period 0.0
org-hugo-front-matter-format “toml”
kaushalmodi commented 2 years ago

Linking bundles (i.e. pages with content in _index or index) is not support at the moment. This is already tracked in https://github.com/kaushalmodi/ox-hugo/issues/389 (I can accept a PR that fixes that).

In the meanwhile, I can suggest that you do this so the same structure of files that you have in your example:

#+macro: relref @@hugo:[@@ $1 @@hugo:]({{< relref "$2" >}})@@

Some introduction text to introduce the index of my blog posts. 
For longer articles please see the {{{relref(Articles Section,articles)}}}.

Related documentation: https://ox-hugo.scripter.co/doc/shortcodes/#org-macros


btw, instead of manually specifying a section and then _index as EXPORT_FILE_NAME separately, a more canonical approach would be to use the bundles feature supported by ox-hugo: https://ox-hugo.scripter.co/doc/hugo-bundle/#branch-bundle-example

#+macro: relref @@hugo:[@@ $1 @@hugo:]({{< relref "$2" >}})@@

* Articles
:PROPERTIES:
:EXPORT_HUGO_BUNDLE: articles
:EXPORT_FILE_NAME: _index
:END:
Content
* Some other page
:PROPERTIES:
:EXPORT_FILE_NAME: some-other-page
:END:
Some introduction text to introduce the index of my blog posts. 
For longer articles please see the {{{relref(Articles Section,articles)}}}.
kaushalmodi commented 2 years ago

I'll close this issue here, but feel free to ask further questions here for any clarification.

kaushalmodi commented 2 years ago

I have created another example of using relref shortcode and Org Macro in https://github.com/kaushalmodi/ox-hugo/issues/389#issuecomment-1039152317.