Search code examples
emacsorg-modehugo

ox-hugo: All figures and code snippets have the same number (1)


When exporting an org file to MD using ox-hugo, all code snippets and figures end up having the same number (1)

Links in the text will also have the same number (1) but in some cases they will have two different numbers even when they are pointing to the same source code. Below is MWE, the org file and the MD after exporting.

    * Summary
     
    Reference to script 1 ([[code:runscript1]])
     
    #+caption: Caption 1
    #+name: code:runscript1
    #+begin_src bash
      # Example
      /bin/bash 01-script.sh
    #+end_src
    First part of code snippet [[code:runprog]]
     
    The second part of snippet [[code:runprog]] shows
     
    #+caption: Caption 2
    #+name: code:runprog
    #+begin_src bash
      # Example
      /bin/bash 02-script.sh
    #+end_src
    ---
    title: "Test"
    date: 2022-11-25
    lastmod: 2022-12-09T00:05:39-04:00
    draft: false
    menu:
      sidebar:
        weight: 1001
        identifier: "test:weight 34"
        name: "Test"
    author:
      name: Me
      image: /images/author/test2.png
    hero: /images/posts/front/test2.svg
    math: true
    ---
     
    ## Summary {#summary}
     
    Reference to script 1 ([1](#code-snippet--code:runscript1))
     
    <a id="code-snippet--code:runscript1"></a>
    ```bash
    # Example
    /bin/bash 01-script.sh
    ```
    <div class="src-block-caption">
      <span class="src-block-number"><a href="#code-snippet--code:runscript1">Code Snippet 1</a>:</span>
      Caption 1
    </div>
     
    First part of code snippet [2](#code-snippet--code:runprog)
     
    The second part of snippet [1](#code-snippet--code:runprog) shows
     
    <a id="code-snippet--code:runprog"></a>
    ```bash
    # Example
    /bin/bash 02-script.sh
    ```
    <div class="src-block-caption">
      <span class="src-block-number"><a href="#code-snippet--code:runprog">Code Snippet 1</a>:</span>
      Caption 2
    </div>

  • A previous version of the same post (from November 25th) did not have such problem so I changed my config file from package.el to straight.el and checked out versions of org and ox-hugo from around that date but the results were the same.

  • There is a similar issue posted on ox-hugo github page but so far there has been no response

  • Most of the attempts were done on a Debian 11 machine with emacs 27.1 but I have also tried on a Windows 10 machine with emacs 28.2 with the same results

Thanks


Solution

  • [Comment converted to answer]

    This was apparently a bug in Org 9.6 and it affects more than the ox-hugo backend (maybe every backend). The author of ox-hugo has posted a question on the Org mode mailing list about it. A fix has been been submitted and it has been confirmed. The fix is here and if you use Org mode from the Git repo, you should be able to get the fixed version now.

    @KaushalModi (the author of ox-hugo) mentions in a comment above that the fix is now in the Org bugfix branch. I thought this meant that it would be available in the Org mode release on GNU ELPA, but I have not been able to verify that as of yet.