Create a list of links in a post

I am looking for a plugin, or perhaps to make a plugin, that takes all links in a page/post and creates a list of them at the bottom of the page (or anywhere you like…).

I have this working already in javascript, but realised it could probably be done at build time.

This is an example of what I have at the moment:

It currently only shows up in the @print rule in my CSS, so the <sup> and <ol> are usually hidden with CSS. The idea being that if you print, you can still see the URLs that were in the post.

Is there anything around like this, before I go down the rabbit hole of making a plugin? Do you think it is even doable?

Ah interesting idea. I haven’t come across this before and not in jekyll.

You could take your logic that works in JS and turn it into a node script that you call with input data and then print the result.

e.g.

$ node links.js page.md

Links:
1. A
2. B

Then you can write a Jekyll plugin in ruby that does a shell command similar to the command above. I believe backticks are the way to do this in ruby.
Then you can append the result to the contents of the page.

Or for a cleaner approach in the plugin, you could set the result as a value on the page object. Similar to if you had set the links list as a field in metadata.
Then in a layout file you can do:

---
---
<body>

{{ content }}

{{ printable_links }}

</body>