jekyll-alternate-permalinks 0.1.1 → 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: 149e95581dc32808745047d67bff6a615e2e8ebebe25dcbc9540c6b0ec8ab0fb
4
- data.tar.gz: 93eb9f4e7f5c82ef0fefcce67743a6edff8153344b215bd2e351d71e509f228b
3
+ metadata.gz: '08d5f1270f1d40d1936f70357c6d3db6e29374d8cee2ea1ce5f02b187def5388'
4
+ data.tar.gz: 38569d0722472d5e4e9f0b710da653e2173bb045fd20e0986a38992617b6f65b
5
5
  SHA512:
6
- metadata.gz: 24ad09f2d1a5c941822b8f1d2f36e565a4b226cbe71f8142b2cecd3638e4bee25937d81e618a0e2d2d630edfdbe59789dd980c5521370a42d865b93a9cb1d6d2
7
- data.tar.gz: 16985b17d9fc93a820de8c8e7d022bbeca789108ae72eb515bbf2d3913d5d436e94636ced82293b988b8110b8fe1b041bd54282a83935065e3e735bef4eb8e12
6
+ metadata.gz: 5f7be012f196cd706d4cd38d43bb2f8b3ddcee3e26cf9e1616ef81e816a08fc994b30af58b2ac3bd79fe2a0e6156cab2f16c5f7ff254b20a1c628387a57d9ae6
7
+ data.tar.gz: 06c18eb7c39c66428770af37521b4d9b02f66c45409d1eee483b2819efee29ef1cbc723552ff108f7ea0992b8cf59471fba531c2667f6ba6281a555225ffc2d9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 2020-10-26 -- v0.1.2
4
+
5
+ Use `Jekyll::PathManager`
6
+
3
7
  ## 2020-10-26 -- v0.1.1
4
8
 
5
9
  Minor refactorization and allows to use [frontmatter
@@ -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::Pathname.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.1
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
@@ -26,7 +26,6 @@ files:
26
26
  - README.md
27
27
  - lib/jekyll-alternate-permalinks.rb
28
28
  - lib/jekyll/alternate/permalinks.rb
29
- - lib/jekyll/alternate/permalinks/version.rb
30
29
  homepage: https://0xacab.org/sutty/jekyll/jekyll-alternate-permalinks
31
30
  licenses:
32
31
  - GPL-3.0
@@ -59,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
58
  - !ruby/object:Gem::Version
60
59
  version: '0'
61
60
  requirements: []
62
- rubygems_version: 3.1.2
61
+ rubygems_version: 3.3.26
63
62
  signing_key:
64
63
  specification_version: 4
65
64
  summary: Creates links from previous permalinks to the current one
@@ -1,9 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Jekyll
4
- module Alternate
5
- module Permalinks
6
- VERSION = '0.1.0'
7
- end
8
- end
9
- end