Add config to toggle html extension in links
This commit is contained in:
		
							parent
							
								
									5d190b6a97
								
							
						
					
					
						commit
						9232ce3ded
					
				| @ -6,6 +6,10 @@ exclude:             ['_includes/notes_graph.json'] | |||||||
| # Pages deploys your repository (which is usually the repository name). | # Pages deploys your repository (which is usually the repository name). | ||||||
| baseurl:             / | 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 | permalink:           pretty | ||||||
| relative_permalinks: false | relative_permalinks: false | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -22,7 +22,7 @@ layout: default | |||||||
|       <div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(1fr);"> |       <div style="display: grid; grid-gap: 1em; grid-template-columns: repeat(1fr);"> | ||||||
|       {% for backlink in page.backlinks %} |       {% for backlink in page.backlinks %} | ||||||
|         <div class="backlink-box"> |         <div class="backlink-box"> | ||||||
|         <a class="internal-link" href="{{ backlink.url }}">{{ backlink.title }}</a><br> |         <a class="internal-link" href="{{ backlink.url }}{%- if site.use_html_extension -%}.html{%- endif -%}">{{ backlink.title }}</a><br> | ||||||
|         <div style="font-size: 0.9em">{{ backlink.excerpt | strip_html | truncatewords: 20 }}</div> |         <div style="font-size: 0.9em">{{ backlink.excerpt | strip_html | truncatewords: 20 }}</div> | ||||||
|         </div> |         </div> | ||||||
|       {% endfor %} |       {% endfor %} | ||||||
|  | |||||||
| @ -4,4 +4,4 @@ title: Consistency is key | |||||||
| 
 | 
 | ||||||
| Show up. Do the work. Be consistent. | 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]]. | ||||||
|  | |||||||
| @ -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. | 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 | ### 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. | 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. | ||||||
|  | |||||||
| @ -9,6 +9,8 @@ class BidirectionalLinksGenerator < Jekyll::Generator | |||||||
| 
 | 
 | ||||||
|     all_docs = all_notes + all_pages |     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 |     # Convert all Wiki/Roam-style double-bracket link syntax to plain HTML | ||||||
|     # anchor tag elements (<a>) with "internal-link" CSS class |     # anchor tag elements (<a>) with "internal-link" CSS class | ||||||
|     all_docs.each do |current_note| |     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]] |         # [[A note about cats|this is a link to the note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i, |           /\[\[#{title_from_filename}\|(.+?)(?=\])\]\]/i, | ||||||
|           "<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>" |           "<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links with label using note filename |         # Replace double-bracketed links with label using note filename | ||||||
|         # [[cats|this is a link to the note about cats]] |         # [[cats|this is a link to the note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i, |           /\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i, | ||||||
|           "<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>" |           "<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links using note title |         # Replace double-bracketed links using note title | ||||||
|         # [[a note about cats]] |         # [[a note about cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[(#{note_potentially_linked_to.data['title']})\]\]/i, |           /\[\[(#{note_potentially_linked_to.data['title']})\]\]/i, | ||||||
|           "<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>" |           "<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" | ||||||
|         ) |         ) | ||||||
| 
 | 
 | ||||||
|         # Replace double-bracketed links using note filename |         # Replace double-bracketed links using note filename | ||||||
|         # [[cats]] |         # [[cats]] | ||||||
|         current_note.content = current_note.content.gsub( |         current_note.content = current_note.content.gsub( | ||||||
|           /\[\[(#{title_from_filename})\]\]/i, |           /\[\[(#{title_from_filename})\]\]/i, | ||||||
|           "<a class='internal-link' href='#{note_potentially_linked_to.url}'>\\1</a>" |           "<a class='internal-link' href='#{note_potentially_linked_to.url}#{link_extension}'>\\1</a>" | ||||||
|         ) |         ) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
| @ -71,7 +73,7 @@ class BidirectionalLinksGenerator < Jekyll::Generator | |||||||
|       # Nodes: Graph |       # Nodes: Graph | ||||||
|       graph_nodes << { |       graph_nodes << { | ||||||
|         id: note_id_from_note(current_note), |         id: note_id_from_note(current_note), | ||||||
|         path: current_note.url, |         path: "#{current_note.url}#{link_extension}", | ||||||
|         label: current_note.data['title'], |         label: current_note.data['title'], | ||||||
|       } unless current_note.path.include?('_notes/index.html') |       } unless current_note.path.include?('_notes/index.html') | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Maxime Vaillancourt
						Maxime Vaillancourt