From 9232ce3ded24e7adc7175010fb3dc39aa2a52d04 Mon Sep 17 00:00:00 2001 From: Maxime Vaillancourt Date: Tue, 26 Jan 2021 08:32:07 -0500 Subject: [PATCH] Add config to toggle html extension in links --- _config.yml | 4 ++++ _layouts/note.html | 2 +- _notes/consistency.md | 2 +- _notes/your-first-note.md | 2 ++ _plugins/bidirectional_links_generator.rb | 12 +++++++----- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/_config.yml b/_config.yml index 11728ea..d8dbcc5 100644 --- a/_config.yml +++ b/_config.yml @@ -6,6 +6,10 @@ exclude: ['_includes/notes_graph.json'] # Pages deploys your repository (which is usually the repository name). baseurl: / +# If you are using a host that cannot resolve URLs that do +# not end with .html (such as Neocities), set this to 'true'. +use_html_extension: false + permalink: pretty relative_permalinks: false diff --git a/_layouts/note.html b/_layouts/note.html index 26a9f3e..0edb519 100644 --- a/_layouts/note.html +++ b/_layouts/note.html @@ -22,7 +22,7 @@ layout: default
{% for backlink in page.backlinks %} {% endfor %} diff --git a/_notes/consistency.md b/_notes/consistency.md index e97fb5e..d0ff2fb 100644 --- a/_notes/consistency.md +++ b/_notes/consistency.md @@ -4,4 +4,4 @@ title: Consistency is key Show up. Do the work. Be consistent. -Then go take a look at the [first note](/your-first-note){: .internal-link}. +Then go take a look at the [[Your first note|first note]]. diff --git a/_notes/your-first-note.md b/_notes/your-first-note.md index da18511..190a4cf 100644 --- a/_notes/your-first-note.md +++ b/_notes/your-first-note.md @@ -23,6 +23,8 @@ Since the Web is all about HTML, you can always use plain HTML if you want, like Of course, you can also link to external websites, like this: [this is a link to Wikipedia](https://wikipedia.org/). Again, you can use plain HTML if you prefer. +**Note about static hosts**: if you use a static host that doesn't support URLs that don't end with `.html` (such as Neocities), try changing the `use_html_extension` value to `true` in the `_config.yml` file and restart the Jekyll server (or re-build the site). This adds a `.html` extension to note URLs and may resolve issues with links. If you're still having trouble, I recommend using Netlify to host your digital garden: it's free, easy to use, and fully supports this template's features out of the box. + ### Automatic bi-directional links Notice in the "Notes mentioning this note" section that there is another note linking to this note. This is a bi-directional link, and those are automatically created when you create links to other notes. diff --git a/_plugins/bidirectional_links_generator.rb b/_plugins/bidirectional_links_generator.rb index e0fee75..1efa1eb 100644 --- a/_plugins/bidirectional_links_generator.rb +++ b/_plugins/bidirectional_links_generator.rb @@ -9,6 +9,8 @@ class BidirectionalLinksGenerator < Jekyll::Generator all_docs = all_notes + all_pages + link_extension = !!site.config["use_html_extension"] ? '.html' : '' + # Convert all Wiki/Roam-style double-bracket link syntax to plain HTML # anchor tag elements () with "internal-link" CSS class all_docs.each do |current_note| @@ -22,28 +24,28 @@ class BidirectionalLinksGenerator < Jekyll::Generator # [[A note about cats|this is a link to the note about cats]] current_note.content = current_note.content.gsub( /\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i, - "\\1" + "\\1" ) # Replace double-bracketed links with label using note filename # [[cats|this is a link to the note about cats]] current_note.content = current_note.content.gsub( /\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i, - "\\1" + "\\1" ) # Replace double-bracketed links using note title # [[a note about cats]] current_note.content = current_note.content.gsub( /\[\[(#{note_potentially_linked_to.data['title']})\]\]/i, - "\\1" + "\\1" ) # Replace double-bracketed links using note filename # [[cats]] current_note.content = current_note.content.gsub( /\[\[(#{title_from_filename})\]\]/i, - "\\1" + "\\1" ) end @@ -71,7 +73,7 @@ class BidirectionalLinksGenerator < Jekyll::Generator # Nodes: Graph graph_nodes << { id: note_id_from_note(current_note), - path: current_note.url, + path: "#{current_note.url}#{link_extension}", label: current_note.data['title'], } unless current_note.path.include?('_notes/index.html')