Skip to content

Commit

Permalink
[meta] change font, remove [[]] on broken links, remove cruft
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-brennan committed Oct 20, 2024
1 parent a26761d commit 1ac3f2a
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 61 deletions.
4 changes: 4 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

<link rel="icon" type="image/png" href="data:image/png;base64,iVBORw0KGgo=">

<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=EB+Garamond:ital,wght@0,400..800;1,400..800&display=swap" rel="stylesheet">

<link rel="stylesheet" href="{{ site.baseurl }}/styles.css">

{% if page.excerpt %}
Expand Down
4 changes: 2 additions & 2 deletions _includes/notes_graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@
graphWrapper.appendChild(element);

const reportWindowSize = () => {
element.setAttribute("width", window.innerWidth);
element.setAttribute("height", window.innerHeight);
element.setAttribute("width", graphWrapper.getBoundingClientRect().width);
element.setAttribute("height", window.innerHeight * 0.8);
};

window.onresize = reportWindowSize;
Expand Down
3 changes: 0 additions & 3 deletions _pages/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ Welcome, weary traveller. Take a seat, drink some water. You must be wondering w

<div class="backlink-box">
You'll be here for some time. Why not begin by reading about my major projects on my [[Works]] page? Or perhaps you'd like to browse the [[Library]], or read a few posts on my [[Blog]]? If you need help with navigating this site, step on over to the [[Arcana]] page, or [[Search]].
<div class="shortcut-hint shortcut-hint--with-top-margin">
Psst...press <code>Ctrl</code>+<code>?</code> to be transported to the search page magically ✨
</div>
</div>

My apologies, I do forget my introductions sometimes. I am Martin Brennan, the keeper of this codex. I am a writer, and above all I enjoy writing genre fiction. I write horror, sci-fi, fantasy, western, and everything else in-between, first in longhand or at the typewriter, then processed into the devil-machine.
Expand Down
104 changes: 53 additions & 51 deletions _plugins/bidirectional_links_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,38 @@ def generate(site)
graph_nodes = []
graph_edges = []

all_notes = site.collections['notes'].docs
all_films = site.collections['film'].docs
all_notes = site.collections["notes"].docs
all_films = site.collections["film"].docs
all_pages = site.pages
all_posts = site.posts

all_nodes = all_notes + all_films + all_posts # defining what should be visualized in the graph
all_docs = all_notes + all_pages + all_films + all_posts # ... and where bidirectional links are generated

link_extension = !!site.config["use_html_extension"] ? '.html' : ''
link_extension = !!site.config["use_html_extension"] ? ".html" : ""

# 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|
all_docs.each do |note_potentially_linked_to|
title_from_filename = File.basename(
note_potentially_linked_to.basename,
File.extname(note_potentially_linked_to.basename)
).gsub('_', ' ').gsub('-', ' ').capitalize

filename = File.basename(
note_potentially_linked_to.basename,
File.extname(note_potentially_linked_to.basename)
)

new_href = "#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}"
title_from_filename =
File
.basename(
note_potentially_linked_to.basename,
File.extname(note_potentially_linked_to.basename)
)
.gsub("_", " ")
.gsub("-", " ")
.capitalize

filename =
File.basename(
note_potentially_linked_to.basename,
File.extname(note_potentially_linked_to.basename)
)

new_href =
"#{site.baseurl}#{note_potentially_linked_to.url}#{link_extension}"
anchor_tag = "<a class='internal-link' href='#{new_href}'>\\1</a>"

# Replace double-bracketed links with label using note title
Expand All @@ -45,11 +52,11 @@ def generate(site)
# Replace double-bracketed links with label using note filename
# [[cats|this is a link to the note about cats]]
current_note.content.gsub!(
/\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i,
/\[\[#{note_potentially_linked_to.data["title"]}\|(.+?)(?=\])\]\]/i,
anchor_tag
)
current_note.data["excerpt"]&.content&.gsub!(
/\[\[#{note_potentially_linked_to.data['title']}\|(.+?)(?=\])\]\]/i,
/\[\[#{note_potentially_linked_to.data["title"]}\|(.+?)(?=\])\]\]/i,
anchor_tag
)

Expand All @@ -67,11 +74,11 @@ def generate(site)
# Replace double-bracketed links using note title
# [[a note about cats]]
current_note.content.gsub!(
/\[\[(#{note_potentially_linked_to.data['title']})\]\]/i,
/\[\[(#{note_potentially_linked_to.data["title"]})\]\]/i,
anchor_tag
)
current_note.data["excerpt"]&.content&.gsub!(
/\[\[(#{note_potentially_linked_to.data['title']})\]\]/i,
/\[\[(#{note_potentially_linked_to.data["title"]})\]\]/i,
anchor_tag
)

Expand All @@ -88,10 +95,7 @@ def generate(site)

# Replace double-bracketed links using note filename
# [[cats]]
current_note.content.gsub!(
/\[\[(#{filename})\]\]/i,
anchor_tag
)
current_note.content.gsub!(/\[\[(#{filename})\]\]/i, anchor_tag)
current_note.data["excerpt"]&.content&.gsub!(
/\[\[(#{filename})\]\]/i,
anchor_tag
Expand All @@ -101,55 +105,53 @@ def generate(site)
# 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
<<~HTML.chomp # replace with this HTML (\\1 is what was inside the brackets)
<span title='There is no note that matches this link.' class='invalid-link'>
<span class='invalid-link-brackets'>[[</span>
\\1
<span class='invalid-link-brackets'>]]</span></span>
HTML
)
current_note.content =
current_note
.content
.gsub(/\[\[([^\]]+)\]\]/i) do |match|
link_text = $1.split("|").last # Take the part after the pipe
<<~HTML.chomp
<span title='There is no note that matches this link.' class='invalid-link'>
#{link_text}
</span>
HTML
end
end

# Identify note backlinks and add them to each note
all_nodes.each do |current_note|
# Nodes: Jekyll
notes_linking_to_current_note = all_notes.filter do |e|
e.content.include?(current_note.url)
end
notes_linking_to_current_note =
all_notes.filter { |e| e.content.include?(current_note.url) }

# Nodes: Graph
graph_nodes << {
id: note_id_from_note(current_note),
path: "#{site.baseurl}#{current_note.url}#{link_extension}",
label: current_note.data['title'],
} unless current_note.path.include?('_notes/index.html')
unless current_note.path.include?("_notes/index.html")
graph_nodes << {
id: note_id_from_note(current_note),
path: "#{site.baseurl}#{current_note.url}#{link_extension}",
label: current_note.data["title"]
}
end

# Edges: Jekyll
current_note.data['backlinks'] = notes_linking_to_current_note
current_note.data["backlinks"] = notes_linking_to_current_note

# Edges: Graph
notes_linking_to_current_note.each do |n|
graph_edges << {
source: note_id_from_note(n),
target: note_id_from_note(current_note),
target: note_id_from_note(current_note)
}
end
end

File.write('_includes/notes_graph.json', JSON.dump({
edges: graph_edges,
nodes: graph_nodes,
}))
File.write(
"_includes/notes_graph.json",
JSON.dump({ edges: graph_edges, nodes: graph_nodes })
)
end

def note_id_from_note(note)
note.data['title']
.dup
.gsub(/\W+/, ' ')
.delete(' ')
.to_i(36)
.to_s
note.data["title"].dup.gsub(/\W+/, " ").delete(" ").to_i(36).to_s
end
end
8 changes: 3 additions & 5 deletions _sass/_style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ $color-box-background: mix($color-primary, white, 4%);
// $color-box-background-bold: #4e60e2;
$color-box-background-bold: #45479c;
$border-radius: 4px;
// $font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Helvetica, Arial,
// sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol;
$font-family: Georgia, serif;
// $font-family: "Source Serif Pro", "Apple Garamond", "Baskerville", "Libre Baskerville", "Droid Serif", "Times New Roman", "Times", serif;
$font-family: "EB Garamond", "Georgia", serif;

body {
background-color: #fff5e6;
Expand All @@ -28,7 +25,7 @@ body {
}

@media (min-width: 1280px) {
font-size: 1.2rem;
font-size: 1.4rem;
}

@media (max-width: 700px) {
Expand Down Expand Up @@ -386,6 +383,7 @@ nav {
width: 100%;
padding: 10px;
box-sizing: border-box;
font-family: $font-family;
}
}

Expand Down

0 comments on commit 1ac3f2a

Please sign in to comment.