jekyll-wikilinks 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jekyll-wikilinks.rb +68 -0
- data/lib/jekyll-wikilinks/version.rb +7 -0
- metadata +47 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaacfcf7a6de57c6c9d002a59c332521c0883cafafc0d724b6df45bee5be3053
|
4
|
+
data.tar.gz: adebf54d3556e767e8c96c5d083b7dd444b9ba5747b86be28f6724b59aca9881
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: afc278ad86c5cae713715435216b4514d28b81d62132394ed7703eefa17794171197ddaeeb306cecef5aa111e511c14d3923fe2e5404ba4a4064305bc1f53746
|
7
|
+
data.tar.gz: 1357f4c985b87fc762020001acc3eed0cb6a7e900e89127690606749a6b9063349d6ed75c36a133be964256993ba0e2ea081dc88a1bc58ceb0c2ac737a131ab9
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "jekyll"
|
3
|
+
require_relative "jekyll-wikilinks/version"
|
4
|
+
|
5
|
+
# can't use converters because it does not have access to jekyll's 'site'
|
6
|
+
# object -- which we need to build a element's href attribute.
|
7
|
+
class JekyllWikilinks < Jekyll::Generator
|
8
|
+
|
9
|
+
def generate(site)
|
10
|
+
wikilinks_collection = site.config["wikilinks_collection"]
|
11
|
+
wikilinks_collection = "notes" if wikilinks_collection.nil? || wikilinks_collection.empty?
|
12
|
+
all_notes = site.collections[wikilinks_collection].docs
|
13
|
+
# i like the idea, but the solution style isn't robust enough yet...
|
14
|
+
# all_pages = site.pages
|
15
|
+
all_docs = all_notes # + all_pages
|
16
|
+
link_extension = !!site.config["use_html_extension"] ? '.html' : ''
|
17
|
+
|
18
|
+
all_docs.each do |cur_note|
|
19
|
+
parse_wiki_links(site, all_docs, cur_note, link_extension)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def parse_wiki_links(site, all_notes, note, link_extension)
|
24
|
+
# some regex taken from vscode-markdown-notes: https://github.com/kortina/vscode-markdown-notes/blob/master/syntaxes/notes.tmLanguage.json
|
25
|
+
# Convert all Wiki/Roam-style double-bracket link syntax to plain HTML
|
26
|
+
# anchor tag elements (<a>) with "internal-link" CSS class
|
27
|
+
all_notes.each do |note_potentially_linked_to|
|
28
|
+
namespace_from_filename = File.basename(
|
29
|
+
note_potentially_linked_to.basename,
|
30
|
+
File.extname(note_potentially_linked_to.basename)
|
31
|
+
)
|
32
|
+
|
33
|
+
# Replace double-bracketed links using note title
|
34
|
+
# [[feline.cats]]
|
35
|
+
# ⬜️ vscode-markdown-notes version: (\[\[)([^\|\]]+)(\]\])
|
36
|
+
note.content = note.content.gsub(
|
37
|
+
/\[\[#{namespace_from_filename}\]\]/i,
|
38
|
+
"<a class='wiki-link' href='#{site.baseurl}#{note_potentially_linked_to.data['permalink']}#{link_extension}'>#{note_potentially_linked_to.data['title'].downcase}</a>"
|
39
|
+
)
|
40
|
+
|
41
|
+
# Replace double-bracketed links with alias (right)
|
42
|
+
# [[feline.cats|this is a link to the note about cats]]
|
43
|
+
# ✅ vscode-markdown-notes version: (\[\[)([^\]\|]+)(\|)([^\]]+)(\]\])
|
44
|
+
note.content = note.content.gsub(
|
45
|
+
/(\[\[)(#{namespace_from_filename})(\|)([^\]]+)(\]\])/i,
|
46
|
+
"<a class='wiki-link' href='#{site.baseurl}#{note_potentially_linked_to.data['permalink']}#{link_extension}'>\\4</a>"
|
47
|
+
)
|
48
|
+
|
49
|
+
# Replace double-bracketed links with alias (left)
|
50
|
+
# [[this is a link to the note about cats|feline.cats]]
|
51
|
+
# ✅ vscode-markdown-notes version: (\[\[)([^\]\|]+)(\|)([^\]]+)(\]\])
|
52
|
+
note.content = note.content.gsub(
|
53
|
+
/(\[\[)([^\]\|]+)(\|)(#{namespace_from_filename})(\]\])/i,
|
54
|
+
"<a class='wiki-link' href='#{site.baseurl}#{note_potentially_linked_to.data['permalink']}#{link_extension}'>\\2</a>"
|
55
|
+
)
|
56
|
+
end
|
57
|
+
|
58
|
+
# At this point, all remaining double-bracket-wrapped words are
|
59
|
+
# pointing to non-existing pages, so let's turn them into disabled
|
60
|
+
# links by greying them out and changing the cursor
|
61
|
+
note.content = note.content.gsub(
|
62
|
+
/\[\[(.*)\]\]/i, # match on the remaining double-bracket links
|
63
|
+
<<~HTML.chomp # replace with this HTML (\\1 is what was inside the brackets)
|
64
|
+
<span title='There is no note that matches this link.' class='invalid-wiki-link'>[[\\1]]</span>
|
65
|
+
HTML
|
66
|
+
)
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-wikilinks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- shorty25h0r7
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-05-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- short2thingz@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/jekyll-wikilinks.rb
|
21
|
+
- lib/jekyll-wikilinks/version.rb
|
22
|
+
homepage: https://github.com/shorty25h0r7/jekyll-wikilinks
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata:
|
26
|
+
homepage_uri: https://github.com/shorty25h0r7/jekyll-wikilinks
|
27
|
+
source_code_uri: https://github.com/shorty25h0r7/jekyll-wikilinks
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: 2.4.0
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubygems_version: 3.2.17
|
44
|
+
signing_key:
|
45
|
+
specification_version: 4
|
46
|
+
summary: Add support for [[wikilinks]] (in markdown).
|
47
|
+
test_files: []
|