.Page.Fragments.Identifiers include only headings IDs

I was adding validation for fragments in links and I discovered that the only IDs taken into accounts in .Page.Fragments.Identifiers were those of headings, either automatic ones or defined through {#new_ID}
And it bugs me because I use quite a few ID sprinkled throughout my documents.
Extracting all the id=blabla in the html should be easy, or in case if there’s an issue of parsing priority, at least all mentions of id attributes in custom markdown attributes.
I’ll parse .RawContent myself.

Maybe not for your particular use case, but the are very useful for finding related content and creating your own TOC partials.

It’s not what you say, it’s how you say it.


Yes I always plan for all possible use cases in an autistic way so I’m always surprised when tools seem arbitrarily limited when complete ones would seem “simpler”, although simpler from my skewed perspective, not the developper’s.

So what solution makes the most sense here ?
Parsing the same page for all instances of render-link.html, or do I create an extended fragment list just once, somewhere, in a template/partial with a scratchpad ?

I can’t, this syntax is the worst, and a shame. I hope someone can explain me why this:

{{- with $url.Fragment }}
	    {{- if gt ( strings.Count . ($page.Store.Get "list_added_ids")) 1 }}
	      {{- errorf "Duplicate heading IDs for ID = \"%q\", link %q in file %q" . $destination $.Page.File.Filename }}
	      {{- else if eq ( strings.Count . ($page.Store.Get "list_added_ids")) 0 }}
	      {{- printf "No ID of name \"%q\", in link %q in file %q" . $destination $.Page.File.Filename }}
	      {{else }}
		  {{- $destination = print $destination "#" $url.Fragment }}
	      {{- end }}
	    {{- end }}

doesn’t work.
The printf statement is not shown. Sometimes. Then I refresh/rebuild, and it’s shown, or not, on the same page, but whether or not the link has a fragment present in the page or not. Depending on which FILE I am on when I save it.

{{ $page.Store.Get "list_added_ids"}}

    <p>	      {{ $url.Fragment}}

This, for the same code on the page I’m testing, displays

the-official-myth the-place-of-hunting the-place-of-insects what-a-natural-diet-is why_trad_diet_does_not_work def_feedback_effect -CkWmgL0k00" title="Un exemple de guérison miraculeuse sss


(so as you see it IS in the stored element) when I save the file where the stored object is initialized and defined) in my editor and displays nothing when I save the testing article’s page.
No code changed whatsoever, I just switch pages in my text editor and save. And it changes the page.

When I change all the Store for Scratch, I get constantly:

No ID of name ““def_feedback_effect””, in link “/en/instinctonutrition/” in file “/home/drm/WEBSITE/content/docs/Biology/essai.md”


def_feedback_effect AA

The link is [AA](presentation_instincto_en#def_feedback_effect) so it does include the fragment.

This whole thing is so incredibly obfuscated. Sorry for the confuse post, it is the most I can make sense of my issue.

I JUST want to validate fragments in local links…


I don’t know if you mean to label the post as offensive, it really wasn’t at all. I would rephrase it if I knew what irritated you ?

Pardon my ignorance, but do you add these as {#new_ID} to Markdown blocks?

I added .Fragments because I needed it and I find it incredibly useful. Also, i suspect many sites do 100% of all fragment linking to headings.

1 Like

I use only {#new_ID}`

I use

{{ .Page.Store.Set "all_ids" (delimit (strings.FindRE `#[:word:]+` .Page.RawContent) " ")}}

But in the same render-hook, what reason explains that following {{- $page := site.GetPage $path }}

{{ $page.Store.Get "all_ids"}}


 "/home/drm/WEBSITE/content/docs/Biology/presentation_instincto_en.md:1:1": "/home/drm/WEBSITE/themes/hugo-book/layouts/_default/_markup/render-link.html:24:11": execute of template failed at <$page.Store.Get>: error calling Get: runtime error: invalid memory address or nil pointer dereference 

while {{ .Page.Store.Get "all_ids"}} doesn’t pose problem ?
since I used .RawContent to define all_ids, shouldn’t that information be available whatever the context I used .Store.Get in ? Why does order count now ?