# Orgmode how to name headlines anchors

**URL:** <https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129>\
**Category:** support\
**Tags:** org-mode\
**Created:** [July 3, 2023, 8:30pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129 "2023-07-03T20:30:47Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [July 3, 2023, 8:30pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/1 "2023-07-03T20:30:47Z")

</div>

when i do this in orgmode:

```auto
* Who Should Support Us
** Law Enforcement
** Environmental Protection

```

i get this in html:

```auto
<ul>
<li><a href="#headline-1">Who Should Support Us</a>
<ul>
<li><a href="#headline-2">Law Enforcement</a>
</li>
<li><a href="#headline-3">Environmental Preservation</a>
</li>

```

which is fine unless i want to add headings in between, because then the anchor ref changes. any links i’ve already setup within the website or given out, go to an incorrect place.

is there a way to make the headline ref absolute in the sense that  
**#headline-1 would be #Who-Should-Support-Us**  
so the order won’t change the links themselves?

i can’t figure out how to do it from  
[Configure Markup](https://gohugo.io/getting-started/configuration-markup/)

and though i could do something like this ([kaushalmodi code](https://github.com/kaushalmodi/hugo-onyx-theme/blob/master/layouts/partials/headline-hash.html)):

```auto
{{ . | replaceRE "(<h[2-9] id=\"([^\"]+)\".+)(</h[2-9]+>)" "${1}&nbsp;<a class=\"headline-hash\" href=\"#${2}\">#</a> ${3}" | safeHTML }}

```

or write my own replacement script to act on the html code externally,

it would be nice if there were already some mechanism that is available to deal with this.

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [July 3, 2023, 9:11pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/3 "2023-07-03T21:11:48Z")

</div>

If you are using Hugo’s native Org parsing, then that id generation is done by the goorg package: [GitHub - niklasfasching/go-org: Org mode parser with html & pretty printed org rendering. also shitty static site generator.](https://github.com/niklasfasching/go-org).

You can open an Issue on that repo to check with the author if what you want is supported.

---

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [July 3, 2023, 9:22pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/4 "2023-07-03T21:22:18Z")

</div>

thx for this kaushalmodi!

i have been using whatever comes with hugo, because i read somewhere that it is what we **should** use (can’t remember where, but something to do with blackfriday markdown).

however, this is the second time ox-hugo has been mentioned.

i would appreciate knowing what i really **should** use (if such a statement can be made) and possibly why.

i did find this discussion:  
[Ox-hugo & go-org](https://discourse.gohugo.io/t/ox-hugo-go-org/21254)

and am tempted to try ox-hugo.

and this:  
[Why ox-hugo?](https://ox-hugo.scripter.co/doc/why-ox-hugo/)

ya i’m really tempted!

---

<div class="post-metadata">

**Author:** ![kaushalmodi](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/kaushalmodi/32/2567_2.png) [@kaushalmodi](https://discourse.gohugo.io/u/kaushalmodi)\
**Post date:** [July 3, 2023, 10:00pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/5 "2023-07-03T22:00:22Z")

</div>

> i would appreciate knowing what i really **should** use

Yeah, I wouldn’t make that statement for anyone. You need to try out all the approaches and pick what works the best for you.

I happen to like the `ox-hugo` approach 😉

---

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [July 3, 2023, 10:53pm UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/6 "2023-07-03T22:53:07Z")

</div>

> [@kaushalmodi](#):
>
> Yeah, I wouldn’t make that statement for anyone. You need to try out all the approaches and pick what works the best for you.
> 
> I happen to like the `ox-hugo` approach 😉

ok k!  
i’ve been reading up on ox-hugo and will try it tonight.

there is an item saying conversion from markdown isn’t necessary, which is understandable, but my site has been done in org-mode (then go-orged), so i presume most of it should work with no problem. however, the front-matter (from what i see on the ox-hugo site) is more extensive and a bit different.

for instance, i just have something like this:

```auto
type or paste code here---
title: Media
date: 2023-01-02T22:20:11-08:00
author: prauthor
description: Media articles and other items published regarding fireworks issues.
categories: [wellnes,erudite,operate]
tags: [fireworks,media]

```

which is quite different from the screenshots [here](https://ox-hugo.scripter.co).  
not a big deal of course, but just wondering if there is a front-matter ‘converter’?

---

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [July 4, 2023, 4:14am UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/7 "2023-07-04T04:14:54Z")

</div>

i can’t get ox-hugo to load.

i’ve followed the steps in the [quickstart](https://ox-hugo.scripter.co/doc/quick-start/#org-target--content-org-created).

i’ve tried ox-hugo from both melpa and melpa-stable. one error i was getting in messages with the former was there was no ox-hugo-autoloads

right now i’m trying ox-hugo-0.12.2 from melpa-stable, but the C-c C-e doesn’t give me H H. however, i’m not getting the autoloads error.

i’ve have as stated in the quickstart

```auto
(with-eval-after-load 'ox
  (require 'ox-hugo))

```

the only way i get anywhere is to  
M-x load-file  
~/.emacs.d/elpa/ox-hugo-0.12.2/ox-hugo.el  
that at leasts gives me C-c C-e H H  
and things seem to work, though, sometimes i get  
**Cannot use unknown “blackfriday” back-end as a parent**  
(if i DO have the require 'ox-hugo code)

so why is the (require 'ox-hugo) bit not working?

---

<div class="post-metadata">

**Author:** ![pradesigner](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pradesigner/32/15713_2.png) [@pradesigner](https://discourse.gohugo.io/u/pradesigner)\
**Post date:** [July 5, 2023, 2:03am UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/8 "2023-07-05T02:03:03Z")

</div>

though i’d still like to get ox-hugo working, i’ve solved my issue with absolutizing the #headlines-x with the following script:

```auto
#!/usr/bin/env zsh

# absolutifies headlines for hugo generated html

# mechanism:
# take all #headline-x
# replace it with the actual headline wording (spaces -> -)

# example:
# <li><a href="#headline-1">Structure of Site</a>
# becomes
# <li><a href="#Structure-of-Site">Structure of Site</a>

# for the file
F=$1

# grab all the #headline-x and its description then split into array on \n
str=$(perl -ne 'print "$1|$2\n" if /<li><a href="(#headline-\d+)">(.+)<\/a>/' $F)
lines=(${(f)str})

# using assoc array (only because i've never tried it before)
declare -A aa
for l in $lines; do
    # split into assoc array
    aa=(${(s:|:)l})
    key=${${(k)aa}#\#} #rm the '#' symbol
    val=${(v)aa} 
    lnk=${val// /-} #replace sp with -

    #echo "$key -> $val -> $lnk"

    # do the replacements
    perl -pi -e "s/$key/$lnk/g" $F
    
done

exit

```

the files i go after (just because of the way my site is setup) are the index.html in updated public/ dir _after_ we hugo the content/ dir.

i use find to pick out the index.html files in the specific directory i’m interested in and feed these to the above script, huhd.sh:

```auto
find $DIR -name "index.html" -exec huhd.sh "{}" \;

```

so the ‘Human Safety’ link in the toc of this [page](http://towardsfreedom.com/ictvity/ethology/fireworks/helpful-alliances/):

```auto
http://towardsfreedom.com/ictvity/ethology/fireworks/helpful-alliances/#Human-Safety
was changed from being the sometimes inconvenient
http://towardsfreedom.com/ictvity/ethology/fireworks/helpful-alliances/#headline-5

```

and if it changes position later on to say #headline-9, i won’t have to rewrite all the links pointing to it.

imho, it would be nice if this sort of absolutization of headings could be added to hugo, but this script does the job for now.

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [July 7, 2023, 2:03am UTC](https://discourse.gohugo.io/t/orgmode-how-to-name-headlines-anchors/45129/9 "2023-07-07T02:03:10Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
