jekyll-rpg 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/collection_page.rb +1 -0
- data/lib/jekyll-rpg.rb +2 -1
- data/lib/references.rb +48 -24
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4dbaff86bfac3c1c821e36321851b94f3cc5e7dfa293543dc49809dfa3f331b1
|
4
|
+
data.tar.gz: e45e59b1260ae0b3f7c853e1780e436d123df64e604fdefbeac1f75bd1b036d1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf357ffe093de9d47beb3f7d9eb26ebe555c6ae312e10d54f397b81e7c6b0628cb083ef8f5f97bee46997970380531eb1ba7ae5c64411cd8b64cbd9d478f0442
|
7
|
+
data.tar.gz: 645a38316b3b70083c0783c2591f9565fbeca5c81fee926ceba3cbb6c3d6d785a595de74b2a0e74eb5155d62fc9eb50a5a519f303ec2e353435782d2d2c529b7
|
data/lib/collection_page.rb
CHANGED
data/lib/jekyll-rpg.rb
CHANGED
@@ -3,12 +3,13 @@
|
|
3
3
|
require 'jekyll'
|
4
4
|
require_relative 'references'
|
5
5
|
|
6
|
+
# Generates reference information for Jekyll Site
|
6
7
|
module JekyllRPG
|
7
8
|
# Bi-directional page links
|
8
9
|
Jekyll::Hooks.register :site, :post_read do |site|
|
9
10
|
ref = References.new(site)
|
10
11
|
|
11
|
-
site.data['graph'] = ref.
|
12
|
+
site.data['graph'] = ref.hashed_graph
|
12
13
|
|
13
14
|
site.data['broken_links'] = ref.broken_links
|
14
15
|
end
|
data/lib/references.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'collection_page'
|
4
|
+
require 'pry'
|
4
5
|
|
5
6
|
module JekyllRPG
|
7
|
+
# References within Jekyll Collections
|
6
8
|
class References
|
7
9
|
attr_accessor :collection_keys, :broken_links, :graph
|
8
10
|
|
@@ -15,7 +17,7 @@ module JekyllRPG
|
|
15
17
|
# Parse references from markdown links
|
16
18
|
@collection_keys.each do |collection|
|
17
19
|
@site.collections[collection].docs.each do |doc|
|
18
|
-
if doc.data['dm'] && !@site.
|
20
|
+
if doc.data['dm'] && !@site.config['dm_mode']
|
19
21
|
doc.data['published'] = false
|
20
22
|
else
|
21
23
|
referent = CollectionPage.new(
|
@@ -33,18 +35,18 @@ module JekyllRPG
|
|
33
35
|
|
34
36
|
# For each collection page, add where it is referenced
|
35
37
|
@collection_keys.each do |collection|
|
36
|
-
site.collections[collection].docs.each do |doc|
|
38
|
+
@site.collections[collection].docs.each do |doc|
|
37
39
|
page_refs = {}
|
38
40
|
|
39
41
|
# Get the information for every page the current doc is referenced in
|
40
42
|
# And push links to an array that represents the collections of those pages
|
41
|
-
referenced_in(collection, doc.data['slug']
|
43
|
+
referenced_in(collection, doc.data['slug']).each do |reference|
|
42
44
|
page_refs[reference.collection] = [] unless page_refs.key?(reference.collection)
|
43
45
|
page_refs[reference.collection].push(reference.markdown_link)
|
44
46
|
end
|
45
47
|
|
46
48
|
# Make sure links in collections are unique
|
47
|
-
page_refs.each do |k,v|
|
49
|
+
page_refs.each do |k, v|
|
48
50
|
page_refs[k] = v.uniq
|
49
51
|
end
|
50
52
|
|
@@ -58,41 +60,36 @@ module JekyllRPG
|
|
58
60
|
end
|
59
61
|
end
|
60
62
|
|
61
|
-
#print broken_links
|
62
|
-
|
63
63
|
# Create list of broken links
|
64
64
|
unwritten_pages.each do |edge|
|
65
|
-
@broken_links.push(
|
66
|
-
'reference_name' => edge['reference'].name,
|
67
|
-
'reference_collection' => edge['reference'].collection,
|
68
|
-
'reference_slug' => edge['reference'].slug,
|
69
|
-
'reference_link' => edge['reference'].markdown_link,
|
70
|
-
'referent_name' => edge['referent'].name,
|
71
|
-
'referent_collection' => edge['referent'].collection,
|
72
|
-
'referent_slug' => edge['referent'].slug,
|
73
|
-
'referent_link' => edge['referent'].markdown_link,
|
74
|
-
})
|
65
|
+
@broken_links.push(edge_hash(edge))
|
75
66
|
end
|
76
67
|
end
|
77
68
|
|
69
|
+
# Find all markdown links in document
|
70
|
+
# TODO - fails to find markdown link at very start of doc
|
71
|
+
# due to not finding any character that isn't an exclamation mark
|
78
72
|
def markdown_links(doc)
|
79
73
|
doc.to_s.scan(%r{(?<=[^!])\[.*?\]\(/.*?/.*?\)})
|
80
74
|
end
|
81
75
|
|
82
76
|
# returns link text, collection and slug
|
83
|
-
# [0](/1/2)
|
77
|
+
# [0](/1/2) - as a [0, 1, 2]
|
84
78
|
def link_components(link)
|
85
|
-
[link[
|
79
|
+
[link[/(?<=\[).*?(?=\])/], link[%r{(?<=/).*(?=/)}], link[%r{(?<=/)(?:(?!/).)*?(?=\))}]]
|
86
80
|
end
|
87
81
|
|
82
|
+
# Find a document based on its collection and slug
|
88
83
|
def find_page(collection, slug)
|
89
84
|
@site.collections[collection].docs.find { |doc| doc.data['slug'] == slug }
|
90
85
|
end
|
91
86
|
|
87
|
+
# Returns true if document cannot be found in collection
|
92
88
|
def page_missing(collection, slug)
|
93
89
|
@site.collections[collection].nil? || find_page(collection, slug).nil?
|
94
90
|
end
|
95
91
|
|
92
|
+
# Returns a hash of two CollectionPages representing a graph edge
|
96
93
|
def edge(referent, reference)
|
97
94
|
referenced_name, referenced_collection, referenced_slug = link_components(reference)
|
98
95
|
if page_missing(referenced_collection, referenced_slug)
|
@@ -113,18 +110,22 @@ module JekyllRPG
|
|
113
110
|
}
|
114
111
|
end
|
115
112
|
|
113
|
+
# Based on the graph, returns edges that a specific document is the referent of
|
116
114
|
def referenced_in(collection, slug)
|
117
|
-
@graph.select
|
118
|
-
|
119
|
-
|
115
|
+
@graph.select do |edge|
|
116
|
+
edge['reference'].collection == collection && edge['reference'].slug == slug
|
117
|
+
end.map { |edge| edge['referent'] }
|
120
118
|
end
|
121
119
|
|
120
|
+
# Based on the graph, returns documents that are referenced, but do not exist yet
|
122
121
|
def unwritten_pages
|
123
|
-
@graph.
|
124
|
-
|
125
|
-
|
122
|
+
@graph.reject do |edge|
|
123
|
+
edge['reference'].written
|
124
|
+
end
|
126
125
|
end
|
127
126
|
|
127
|
+
# Determines if refs table is required based on document,
|
128
|
+
# then collection, then site
|
128
129
|
def refs_table_required(doc)
|
129
130
|
if doc.data.key?('refs')
|
130
131
|
doc.data['refs']
|
@@ -135,6 +136,29 @@ module JekyllRPG
|
|
135
136
|
end
|
136
137
|
end
|
137
138
|
|
139
|
+
# Returns an easily accessible hash representing an edge for Jekyll purposes
|
140
|
+
def edge_hash(edge)
|
141
|
+
{
|
142
|
+
'reference_name' => edge['reference'].name,
|
143
|
+
'reference_collection' => edge['reference'].collection,
|
144
|
+
'reference_slug' => edge['reference'].slug,
|
145
|
+
'reference_link' => edge['reference'].markdown_link,
|
146
|
+
'referent_name' => edge['referent'].name,
|
147
|
+
'referent_collection' => edge['referent'].collection,
|
148
|
+
'referent_slug' => edge['referent'].slug,
|
149
|
+
'referent_link' => edge['referent'].markdown_link
|
150
|
+
}
|
151
|
+
end
|
152
|
+
|
153
|
+
# Returns a graph made up of hashed edges
|
154
|
+
def hashed_graph
|
155
|
+
@graph.map { |edge| edge_hash(edge) }
|
156
|
+
end
|
157
|
+
|
158
|
+
# The following three functions return a HTML table
|
159
|
+
# That for a specific document shows the documents that
|
160
|
+
# reference it
|
161
|
+
|
138
162
|
def refs_table(refs)
|
139
163
|
table = <<~TABLE
|
140
164
|
# Referenced By:
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-rpg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Lockwood
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-09-
|
11
|
+
date: 2019-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description: ''
|
28
56
|
email: tom@lockwood.dev
|
29
57
|
executables: []
|