List of all links contained in a page

Dear All,

I am a beginner in Jekyll and this is my first post. Apologies if you find it trivial. I am building a scientific tutorial with Jekyll and I would like to include a list of references. I have a “tutorial-entry” collection, and I would like to find a simple way to optionally include a bibliography at the end of each tutorial-entry.

I can not use plugins, as my site is hosted by GitHub, so I thought I would proceed as follows:

  1. Create a “references” collection, with a “reference-id”, and a “reference-text”
  2. In a tutorial-entry, link to the reference using “reference-id”
  3. At the end of the tutorial-entry, browse all the "reference-id"s that have been linked in the entry, and produce a list of references using the corresponding “reference-text” attribute

My questions are:

  • Do you think this is feasible? Do you have better ways for achieving this task without plugins?
  • I am stuck with step 3. above, as I would have to loop over all the "reference-id"s that have been linked in the particular tutorial-entry, and I simply do not know how to do it. Do you have any examples I could look into? I have searched quite a lot around, and all I found was ways to create a “table of content”, which do not apply to me, as I do not want to loop over all _references, but only over the ones that have been used in the current tutorial-entry.

Thanks in advance for your help

not 100% sure I understand what you want, but rather than using another collection I would try to use a data file. In the data file you could list the references by aritcle or something, then just grab those. But you would have to keep them in sync which I think would be more trouble than it is worth.

Actually maybe you would put them in the front matter of the article so you could update everything in one place.

Do you have an example of an article that includes your references? like a mock up of what it would look like ideally? preferably on GH.

Thanks for your reply. You can see an example here

or in the attached image

Here I have 2 papers, [Tref00] and [Weid00], which are referenced in the text and then expanded at the end of the page. At the moment the references are hardwired (meaning that I really write down the tags and their expansions in my .md file). I am looking for a way to automatise this and I thought I could create a collection of _references, for instance:


reference-id: Tref00
reference-text: Trefethen, L. N. (2000). Spectral methods in MATLAB (Vol. 10). Society for Industrial and Applied Mathematics.

Then browse all the _references that have been called in a page and render them at the end. I am open to suggestions.

I think you may be trying to automate this too much. I don’t know how to look through page content ({{ content }}) for a specific value.

You might simplify the process by doing this instead. In a data file (e.g., _data/myrefs.yml) add your references like this:

Tref00: Trefethen, L. N. (2000). Spectral methods in MATLAB (Vol. 10). Society for Industrial and Applied Mathematics.
Weid00: Weideman, J. A., & Reddy, S. C. (2000). A MATLAB differentiation matrix suite. ACM Transactions on Mathematical Software (TOMS), 26(4), 465–519

Then below your article, look to see which references you cited in the article, and include the references like this:

{{site.data.myrefs.Tref00}}
{{site.data.myrefs.Weid00}}

This data reference will insert the value for {{Tref00}} and {{Weid00}}.

I understand you want to automate this process, but the above would be the simplest way.

The only solution that comes to mind for more automation would be to store a list of references used in your page’s front matter:

refs: 
- Tref00
- Weid00

Then implement a for loop that would check to see if the refs listed in the front matter matched refs in your myref.yml data file. If so, include them on the page. (If you want the exact logic, I could prob. work that out…)

However, I would advise against that simply because for loops will lengthen your build time. If you have a ton of these loops, it will take forever to build your site. And if you don’t have a ton of them, then automating the process with a complex for loop probably isn’t worth it.

1 Like

This is extremely helpful, thanks! I think that the strategy you mention is a very good compromise and I’m going to adopt it immediately.

Daniele