Mention other pages linking to current page

I’m necro-threading this @TerminalAddict to see if you might have figured this out in the last four years… I’m trying to get working the same BidirectionalLinksGenerator plugin that started this thread. I’ve adapted your solution for a more compact BackLinksGenerator plugin. But both your version, and Maxime’s version, don’t consistently work for links that are generated by a Liquid for loop iterating through site.pages or site.posts.

I wrote up my latest investigation in more detail here: Trouble with hooks for a custom backlink generator - #8 by steinea.

The summary is that this is my plugin:

class BidirectionalLinksGenerator < Jekyll::Generator
  def generate(site)

      Jekyll::Hooks.register :pages, :post_convert do |page|
        all_posts = site.posts.docs
        all_pages = site.pages

        all_docs = all_posts + all_pages

        all_docs.each do |current_note|
          notes_linking_to_current_note = all_docs.filter do |e|
            e.content.include?(current_note.url)
          end
          current_note.data['backlinks'] = notes_linking_to_current_note
        end
      end

    end

  end

I’ve added the hook logic, because without this the plugin runs before files are converted from markdown to html, and consequently Liquid has not yet been converted, and thus links that will be generated by Liquid aren’t picked up by the plugin. The :post_convert event means the plugin now runs after files have been converted but before they’ve rendered.

Unfortunately, backlinks are only generated sporadically. I have some big lists and tables that are generated by a Liquid loop iterating through a filter, and seemingly randomly those links will get picked up by the backlink generator. It’s very strange :thinking: