jekyll-alternate-permalinks 0.1.2 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 424645ac87621f2b249e4e523f3f44ebd5f6cfd25566faba573ba675a040b6b3
4
- data.tar.gz: 687b40f77e034622c2f2aada3acb966e814f1cbe17bc131519754dc630aee4d0
3
+ metadata.gz: '08d5f1270f1d40d1936f70357c6d3db6e29374d8cee2ea1ce5f02b187def5388'
4
+ data.tar.gz: 38569d0722472d5e4e9f0b710da653e2173bb045fd20e0986a38992617b6f65b
5
5
  SHA512:
6
- metadata.gz: 3b995e5c0a8d75756355fa4bac679e27593e29434478d319803df846450ef70f9534ba6a5e5fd3bc3b3186f605c0a8f2ccaed716be4b8b4f5deae2785b108ce3
7
- data.tar.gz: 304183e38061f36c2a3085d2ea7334a88792e853db3944807e35135efbd1d0586cb05d0272ec04779da2e27bad2a21b29bfec432283586963fc540c2f92701f2
6
+ metadata.gz: 5f7be012f196cd706d4cd38d43bb2f8b3ddcee3e26cf9e1616ef81e816a08fc994b30af58b2ac3bd79fe2a0e6156cab2f16c5f7ff254b20a1c628387a57d9ae6
7
+ data.tar.gz: 06c18eb7c39c66428770af37521b4d9b02f66c45409d1eee483b2819efee29ef1cbc723552ff108f7ea0992b8cf59471fba531c2667f6ba6281a555225ffc2d9
@@ -2,31 +2,34 @@
2
2
 
3
3
  require 'pathname'
4
4
 
5
- # TODO: For extra boilerplate's sake (!), convert to a class that
6
- # renders as symlink
7
- #
8
- # TODO: Use hardlinks? There won't be a "canonical" file because they
9
- # all will be the same file, but the site would work on filesystems that
10
- # don't support symlinks.
11
- Jekyll::Hooks.register :site, :post_write do |site|
12
- # Traverse all files that could contain alternate-permalinks
13
- [site.pages, site.documents].flatten.each do |page|
14
- # Get a pathname for the file
15
- path = Pathname.new page.destination site.dest
16
-
17
- # Create a symlink for each alternate permalink
18
- page.data['alternate-permalinks']&.each do |alt|
19
- alt = Jekyll::PathManager.join(alt, 'index.html') if alt.end_with? '/'
20
-
21
- alt_path = Pathname.new site.in_dest_dir(alt)
22
-
23
- if File.exist? alt_path
24
- Jekyll.logger.warn "#{alt_path} already exists, skipping"
25
- else
26
- Jekyll.logger.debug "Symlink from #{path.relative_path_from(alt_path.dirname)} to #{alt}"
27
-
28
- FileUtils.mkdir_p(alt_path.dirname)
29
- File.symlink path.relative_path_from(alt_path.dirname), alt_path
5
+ module Jekyll
6
+ module AlternatePermalinks
7
+ extend self
8
+
9
+ def render(page)
10
+ return unless page.data['alternate-permalinks'].is_a? Array
11
+
12
+ site = page.site
13
+
14
+ # Get a pathname for the file
15
+ path = Pathname.new(page.destination(site.dest))
16
+
17
+ # Create a symlink for each alternate permalink
18
+ page.data['alternate-permalinks'].each do |alt|
19
+ alt = Jekyll::PathManager.join(alt, 'index.html') if alt.end_with? '/'
20
+
21
+ alt_path = Pathname.new(site.in_dest_dir(alt))
22
+
23
+ if alt_path.exist?
24
+ Jekyll.logger.warn 'Permalinks:', "#{alt_path} already exists, skipping"
25
+ else
26
+ relative_path = path.relative_path_from(alt_path.dirname)
27
+
28
+ Jekyll.logger.info 'Permalinks:', "Symlink from #{relative_path} to #{alt}"
29
+
30
+ FileUtils.mkdir_p(alt_path.dirname)
31
+ File.symlink(relative_path, alt_path)
32
+ end
30
33
  end
31
34
  end
32
35
  end
@@ -1,3 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'jekyll/alternate/permalinks'
4
+
5
+ Jekyll::Hooks.register :documents, :post_write do |document|
6
+ Jekyll::AlternatePermalinks.render document
7
+ end
8
+
9
+ Jekyll::Hooks.register :pages, :post_write do |page|
10
+ Jekyll::AlternatePermalinks.render page
11
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-alternate-permalinks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.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-10-26 00:00:00.000000000 Z
11
+ date: 2023-11-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Prevents broken links when renaming articles by keeping a list of previous
14
14
  permalinks and creating links between them
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  - !ruby/object:Gem::Version
59
59
  version: '0'
60
60
  requirements: []
61
- rubygems_version: 3.1.2
61
+ rubygems_version: 3.3.26
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Creates links from previous permalinks to the current one