Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/samualtnorman/hackmud-wiki.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106# frozen_string_literal: trueclass BidirectionalLinksGenerator < Jekyll::Generator def generate(site) graph_nodes = [] graph_edges = []
all_pages = site.pages all_posts = site.posts.docs
all_docs = all_pages + all_posts
link_extension = ''
# Convert all Wiki/Roam-style double-bracket link syntax to plain HTML # anchor tag elements (<a>) with "internal-link" CSS class all_docs.each do |current_note| current_note.content.gsub!( /!\[\[(.+?)\]\]/, "", )
all_docs.each do |note_potentially_linked_to| note_title_regexp_pattern = Regexp.escape( File.basename( note_potentially_linked_to.basename, File.extname(note_potentially_linked_to.basename) ) ).gsub('\_', '[ _]').gsub('\-', '[ -]').capitalize
title_from_data = note_potentially_linked_to.data['title'] linkmdname = note_potentially_linked_to.data['linkmdname'] linkdisplayname = note_potentially_linked_to.data['linkdisplayname']
if title_from_data title_from_data = Regexp.escape(title_from_data) end
if linkmdname linkmdname = Regexp.escape(linkmdname) end
#if linkdisplayname # linkdisplayname = Regexp.escape(linkdisplayname) #end
new_href = "#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}" anchor_tag = "<a class='internal-link' href='#{new_href}'>\\1</a>" autolinktag = "<a class='internal-link' href='#{new_href}'>#{linkdisplayname}</a>"
# Replace double-bracketed links with label using note title # [[A note about cats|this is a link to the note about cats]] current_note.content.gsub!( /\[\[#{note_title_regexp_pattern}\|(.+?)(?=\])\]\]/i, anchor_tag )
# Replace double-bracketed links with label using note filename # [[cats|this is a link to the note about cats]] current_note.content.gsub!( /\[\[#{title_from_data}\|(.+?)(?=\])\]\]/i, anchor_tag )
# Replace double-bracketed links using note title # [[a note about cats]] current_note.content.gsub!( /\[\[(#{title_from_data})\]\]/i, anchor_tag )
# Replace double-bracketed links with label using linkmdname # [[cats_link|this is a link to the note about cats]] current_note.content.gsub!( /\[\[#{linkmdname}\|(.+?)(?=\])\]\]/i, anchor_tag )
# Replace double-bracketed links using note title # [[cats_link]] current_note.content.gsub!( /\[\[(#{linkmdname})\]\]/i, autolinktag )
# Replace double-bracketed links using note filename # [[cats]] current_note.content.gsub!( /\[\[(#{note_title_regexp_pattern})\]\]/i, anchor_tag ) end
# At this point, all remaining double-bracket-wrapped words are # pointing to non-existing pages, so let's turn them into disabled # links by greying them out and changing the cursor current_note.content = current_note.content.gsub( /\[\[([^\]]+)\]\]/i, # match on the remaining double-bracket links '<span class="text_invalid">\1 (dead link)</span>' ) end end
def note_id_from_note(note) note.data['title'].bytes.join endend