I am trying to implement internal back-linking as I have seen it is not supported. To do so, I plan on building a JSON containing the graph of all links in the data/ folder and using it to extract reverse links (ie. on page1, listing all the pages that mention it). If you have a better idea, please share !
Therefore I need a robust way to explore all my pages and extract the internal links mentioned (as relref, ref or []()) and generate the JSON. Maybe through a section custom format ? Ideally, I would need the permalink as well as the title.
you can create a custom JSON feed or a custom sitemap.
you can use my sample as starting point
so you get a 2 step implementation, feeding the results back to content.
1st create a new configDir to create only the sitemaps, and feed it back to content
specify it in the command line hugo --config createmap.toml
2nd create your site
thanks for the input.
I see how I can create a custom JSON feed or sitemap (I have done a couple for my website already) but I fail to see how your example helps me with extracting internal links from each pages : i.e. for page1, if it mentions as internal link page2.md and page3.md (either as relref or other mean), I want to be able to have this information in my output to generate a graph of all the internal navigation provided by the content. This implies probably parsing each markdown except if there is a field on .Page with provides this information.
Can you point me in the right direction please ?
ok @bep, I’ll try something along this path. Thank you.
I would need my custom page (that renders this Scratch) to be built last in order to be complete though. Is there any way to make it happen (built last) ?
Output formats gets rendered in the order they are defined, so if you … say define a JSON output format and define that to run last, that should (in theory) work.
In isolation, I would say no. But I have discussed a “page map” feature where you could navigate down the tree and render what you want, but that is a bigger feature … And I’m short for time as it is.
I managed to make something work with your idea @bep : I now have a generated file internal links (i.e. the graph edges and nodes).
Is there a way to exploit it again in the same pages, i.e. by rerendering the pages ? Or do I really need to do a build + copy of the generated file to /data/ + rebuild sourcing the data file ?
I would prefer to be able to keep the live reload…
I could not make it work that way (probably because the backlinks export is in the section _index whereas the backlinks crawling is in the individual posts and I could not manage to get them first)…
In the end I did it in two passes : build + copy to data/ + build.