jekyll-linked-posts 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jekyll/linked_posts.rb +32 -25
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 567b5bf4cd5fbc9ed6b521ed1a76d6b609ac4bdd0d5e61b01f963ffe81ec6229
4
- data.tar.gz: 9fbca911800e53b4259be09b74d82c8d96e8e59c555a276b774310bf4b90cab1
3
+ metadata.gz: b90e7a22303bc20289f133ee54a2f59a60948728a9beb56ed6a4ac163f8d3678
4
+ data.tar.gz: c22383603722fc768d7b02c80be83edab9032d86cc8ab86c1169f43a6255da10
5
5
  SHA512:
6
- metadata.gz: 0d52bf528f5ad92507d44c698321e95cdfc7b1bd6506b5c618f6f4aafea9e97d2fdf76b56b0288653e4eeb1611b5541a19f22f4c776cafd78b82143d24cc46ae
7
- data.tar.gz: f1ecddd44fcc19576bbc58382df7371587ab3bcd60bb4c5b3ff74fc26c0a7af48d574324714633a24f13bf5310359ea76f27780c17121d8dd11997a4dea55ef9
6
+ metadata.gz: aaa69aa67d59681692f3b359f2884b2a3949d7a1fa5caff19e768d8daac72d1b8871ba514c2c8f9d9b975134870cc5f9fc2c798825e6976afd3dd70f19d91f0f
7
+ data.tar.gz: f4650ff35e5233daa11cdaa5b6a24ab8bcc13665c612274e41afaf3adffd8d8bd206bef1537f7b7c9752822ea854c2e5142bda4a3e11e4fe25a8e31d9d27cbe2
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Jekyll
2
4
  # Link posts by UUIDs
3
5
  class LinkedPosts
@@ -15,36 +17,41 @@ module Jekyll
15
17
  # If it doesn't find anything it'll show a warning and replace the
16
18
  # value for nil.
17
19
  def read
18
- docs.each do |doc|
20
+ indexed_documents.values.each do |doc|
19
21
  fields.each do |field|
20
22
  next unless doc.data.key? field
21
23
 
22
24
  # XXX: this lacks... elegance
23
25
  doc.data[field] =
24
26
  case doc.data[field]
25
- when String then
26
- find doc.data[field]
27
- when Array then
28
- doc.data[field].map do |doc|
29
- find doc
30
- end.compact
31
- when Hash
32
- doc.data[field].map do |f, uuid|
33
- [f, find(uuid)]
34
- end.to_h
35
- else
36
- Jekyll.logger.warn "Couldn't link posts on #{doc.path}"
37
- nil
38
- end
27
+ when String then find(doc.data[field])
28
+ when Array
29
+ doc.data[field].map do |doc|
30
+ find doc
31
+ end.compact
32
+ when Hash
33
+ doc.data[field].map do |f, uuid|
34
+ [f, find(uuid)]
35
+ end.to_h
36
+ else
37
+ Jekyll.logger.warn "Couldn't link posts on #{doc.path}"
38
+ nil
39
39
  end
40
+ end
40
41
  end
41
42
  end
42
43
 
43
44
  private
44
45
 
45
- # Obtain docs from the whole site
46
- def docs
47
- @docs ||= site.collections.map(&:last).map(&:docs).flatten
46
+ # Obtain docs from the whole site, indexing them by uuid
47
+ #
48
+ # @return [Hash]
49
+ def indexed_documents
50
+ @indexed_documents ||= site.documents.reduce({}) do |docs, doc|
51
+ docs.tap do |d|
52
+ d[doc.data['uuid']] = doc
53
+ end
54
+ end
48
55
  end
49
56
 
50
57
  # Search for UUIDs in these front matter fields. You can add more
@@ -54,19 +61,19 @@ module Jekyll
54
61
  # linked_fields:
55
62
  # - related
56
63
  # - lang
64
+ #
65
+ # @return [Array]
57
66
  def fields
58
67
  @fields ||= site.config.fetch('linked_fields', FIELDS).compact.uniq
59
68
  end
60
69
 
61
- # Find a post with the given UUID
70
+ # Find a post with the given UUID and log alert if missing.
71
+ #
72
+ # @return [Jekyll::Document,Nil]
62
73
  def find(uuid)
63
- r = docs.lazy.find do |doc|
64
- doc.data['uuid'] == uuid
74
+ indexed_documents[uuid].tap do |i|
75
+ Jekyll.logger.warn "#{uuid} couldn't be found" if i.nil?
65
76
  end
66
-
67
- Jekyll.logger.warn "#{uuid} couldn't be found" if r.nil?
68
-
69
- r
70
77
  end
71
78
  end
72
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-linked-posts
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2021-07-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -71,7 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  - !ruby/object:Gem::Version
72
72
  version: '0'
73
73
  requirements: []
74
- rubygems_version: 3.0.3
74
+ rubygems_version: 3.1.2
75
75
  signing_key:
76
76
  specification_version: 4
77
77
  summary: Adds linked posts to Jekyll