The following is a working but definitely cumbersome way to retrieve a page backlinks by using pure Liquid, in Jekyll.
Last active
May 31, 2021 08:25
-
-
Save xplosionmind/605e4a2a67ec704dfb738d9d6b984941 to your computer and use it in GitHub Desktop.
Pure Liquid Jekyll Backlinks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="box" id="backlinks"> | |
<h2>Backlinks</h2> | |
<p class="center"> | |
{% if page.lang == 'it' %} | |
Le pagine del sito che contengono un link a questa pagina.<br /> | |
Curioso riguardo cosa voglia dire? Leggi <a href="https://it.wikipedia.org/wiki/Backlink" target="_blank" title="Backlink su Wikipedia">questo articolo</a>. | |
{% else %} | |
All the pages of this website containing a link to the current page.<br />Curious about what this means? Check <a href="https://en.wikipedia.org/wiki/Backlink" target="_blank" title="Backlink on Wikipedia">this article</a>. | |
{% endif %} | |
</p> | |
{% comment %}+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
+ + | |
+ 100% Liquid backlinks parser based on pages permalinks. + | |
+ + | |
++++++++++++++++++++++++++++++++++++++++++++++++++++++++{% endcomment %} | |
<ul> | |
{% capture current_url %}{{ page.url }}{% endcapture %} | |
{% capture current_url_downcase %}{{ page.url | downcase }}{% endcapture %} | |
{% for entry in site.pages %} | |
{% unless entry.url contains '.json' or entry.url contains '.csv' or entry.url contains '.css' or entry contains '.txt' or entry.url contains 'home' or entry.url contains 'tuffo' or entry.url contains 'marmellata' or entry.url contains 'jam' %} | |
{% if entry.content contains page.url or entry.content contains current_url_downcase %} | |
<li> | |
<a href="{{ entry.url }}">{{ entry.title }}</a> | |
{% if entry.description %} | |
- {{ entry.description }} | |
{% else %} | |
- {{ entry.excerpt | strip_html | truncatewords: 30 }} | |
{% endif %} | |
</li> | |
{% endif %} | |
{% for redirect in page.redirect_from | split '/' %} | |
{% capture redirect_ %}/{{ redirect }}{% endcapture %} | |
{% if entry.content contains redirect_ %} | |
<li> | |
<a href="{{ entry.url }}">{{ entry.title }}</a> | |
{% if entry.description %} | |
- {{ entry.description }} | |
{% else %} | |
- {{ entry.excerpt | strip_html | truncatewords: 30 }} | |
{% endif %} | |
</li> | |
{% endif %} | |
{% endfor %} | |
{% endunless %} | |
{% endfor %} | |
{% for collection in site.collections %} | |
{% assign collection_name = collection.label %} | |
{% for entry in site.[collection_name] %} | |
{% if entry.content contains page.url or entry.content contains current_url_downcase %} | |
{% case collection_name %} | |
{% when 'notes' %} | |
<li><a href="{{ entry.url }}">{{ entry.title }}</a> - {% if entry.description %}{{ entry.description }}{% else %}{{ entry.excerpt | strip_html | truncatewords: 30 }}{% endif %}</li> | |
{% when 'sconnesso' %} | |
<li>🎙️ <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% when 'posts' %} | |
<li>📖 <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% when 'filinge' %} | |
<li>💭 <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% else %} | |
<li><a href="{{ entry.url }}">{{ entry.title }}</a> - {{ entry.excerpt | strip_html | truncatewords: 30 }}</li> | |
{% endcase %} | |
{% endif %} | |
{% for redirect in page.redirect_from | split '/' %} | |
{% capture redirect_ %}/{{ redirect }}{% endcapture %} | |
{% if entry.content contains redirect_ %} | |
{% case collection_name %} | |
{% when 'notes' %} | |
<li><a href="{{ entry.url }}">{{ entry.title }}</a> - {% if entry.description %}{{ entry.description }}{% else %}{{ entry.excerpt | strip_html | truncatewords: 30 }}{% endif %}</li> | |
{% when 'sconnesso' %} | |
<li>🎙️ <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% when 'posts' %} | |
<li>📖 <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% when 'filinge' %} | |
<li>💭 <a href="{{ entry.url }}">{{ entry.title }}</a></li> | |
{% else %} | |
<li><a href="{{ entry.url }}">{{ entry.title }}</a> - {{ entry.description }}</li> | |
{% endcase %} | |
{% endif %} | |
{% endfor %} | |
{% endfor %} | |
{% endfor %} | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment