jekyll-taxonomy-redirects 0.1.2 → 0.1.3

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: ac7596a15210c659dc9b7589ed6688e3a0b16dba11218b3571d1addc801bd6ed
4
- data.tar.gz: d7298ff8169e778e299c929643e44f9d753b517d7d5e378b457dfe47ab1edba0
3
+ metadata.gz: '0840e3d5e7160918bd0f9bd46b1f35104fe146ee5cb4572b40443b64bd564ff4'
4
+ data.tar.gz: 8b41088a085c61ce5fe0db9b4b1db23ecd332edf23c199ef2c3e4ede6f0845bd
5
5
  SHA512:
6
- metadata.gz: 8ebe92f8f243dae9b44b1e51666e2edfb9572a52059a59fb411b5e9b8a5eec98a608a44913bcd21a17e46c2c1961903d19ce5fc65e4c81397b848ef49b312b3d
7
- data.tar.gz: b46a332f4f8d3a3bb1460de62530fed6ee7ab5b457db12ae6236bd0943ddd522c06916f0bfd68adb086dd69e473fbdf277de9a9eb1fb20d3201ca85c4833e52f
6
+ metadata.gz: e43630d2f190fccb097b996792b67135525dbc5ff97524609d8556ed83275205cec5e31af05772dfc0fedf3df99917635dcd4062be438825e1192990dc53ced1
7
+ data.tar.gz: a0229f817dc21dde9b52d6c04ff7ac8a74403fdf4a854e05804a9b675f3bda7058225cab7fe58bb49c5fd4c5152bd99b118c06c9b895168aac9a40fdd04c7a40
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
  module Jekyll
3
3
  module TaxonomyRedirects
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
6
6
  end
7
7
 
@@ -1,46 +1,35 @@
1
1
  # frozen_string_literal: true
2
2
  require "json"
3
+ require "fileutils"
3
4
 
4
- # Jekyll plugin: generates legacy taxonomy redirect stubs, e.g.
5
- # /category/:slug/ -> /venues/:slug/
6
- # /tags/:slug/ -> /acts/:slug/
7
- #
8
- # Works with any taxonomy provider (core categories/tags or jekyll-archives),
9
- # because it only needs the slug lists (site.categories.keys / site.tags.keys).
10
- #
11
- # Add to Gemfile and enable in _config.yml under `plugins:` then configure:
12
- #
13
- # taxonomy_redirects:
14
- # roots:
15
- # - { from: "/category", to: "/venues" }
16
- # - { from: "/tags", to: "/acts" }
17
- # maps:
18
- # - { type: "category", from: "/category", to: "/venues" }
19
- # - { type: "tag", from: "/tags", to: "/acts" }
20
- # emit_canonical: true
21
- #
22
5
  module Jekyll
23
6
  module TaxonomyRedirects
24
- class RedirectPage < Jekyll::Page
25
- def initialize(site, from_path, dest_url, emit_canonical: true)
26
- @site = site
27
- @base = site.source
28
- @dir = from_path # e.g. "category/union-chapel"
29
- @name = "index.html"
30
- process(@name)
7
+ # A static file that writes redirect HTML straight to the destination.
8
+ class RedirectStaticFile < Jekyll::StaticFile
9
+ def initialize(site, dir, name, dest_url, emit_canonical: true)
10
+ super(site, site.source, dir, name, nil)
11
+ @dest_url = dest_url
12
+ @emit_canonical = emit_canonical
13
+ end
31
14
 
32
- self.data = { "layout" => nil, "sitemap" => false }
33
- self.content = template(dest_url, emit_canonical)
15
+ # Always write our generated content (it's tiny).
16
+ def write(dest)
17
+ dest_path = destination(dest)
18
+ FileUtils.mkdir_p(File.dirname(dest_path))
19
+ File.open(dest_path, "wb") { |f| f.write(html) }
20
+ true
34
21
  end
35
22
 
36
- def template(dest_url, emit_canonical)
37
- canonical = emit_canonical ? %(<link rel="canonical" href="#{dest_url}">\n) : ""
23
+ private
24
+
25
+ def html
26
+ canonical = @emit_canonical ? %Q(<link rel="canonical" href="#{@dest_url}">\n) : ""
38
27
  <<~HTML
39
28
  <!doctype html><meta charset="utf-8">
40
- <meta http-equiv="refresh" content="0; url=#{dest_url}">
29
+ <meta http-equiv="refresh" content="0; url=#{@dest_url}">
41
30
  #{canonical}<title>Moved</title>
42
- <p>Moved to <a href="#{dest_url}">#{dest_url}</a>.</p>
43
- <script>location.replace(#{dest_url.to_json});</script>
31
+ <p>Moved to <a href="#{@dest_url}">#{@dest_url}</a>.</p>
32
+ <script>location.replace(#{@dest_url.to_json});</script>
44
33
  HTML
45
34
  end
46
35
  end
@@ -60,10 +49,10 @@ module Jekyll
60
49
  from = trim_slashes(r["from"].to_s)
61
50
  to = ensure_trailing_slash(r["to"].to_s)
62
51
  next if from.empty? || to.empty?
63
- site.pages << RedirectPage.new(site, from, to, emit_canonical: emit_canonical)
52
+ site.static_files << RedirectStaticFile.new(site, from, "index.html", to, emit_canonical: emit_canonical)
64
53
  end
65
54
 
66
- # Map per-slug redirects
55
+ # Per-slug redirects from taxonomies
67
56
  maps.each do |m|
68
57
  type = m["type"].to_s # "category" or "tag"
69
58
  from = trim_slashes(m["from"].to_s)
@@ -77,9 +66,9 @@ module Jekyll
77
66
  end
78
67
 
79
68
  slugs.each do |slug|
80
- from_path = File.join(from, slug) # e.g. "category/union-chapel"
81
- dest_url = "/" + File.join(to, slug, "") # e.g. "/venues/union-chapel/"
82
- site.pages << RedirectPage.new(site, from_path, dest_url, emit_canonical: emit_canonical)
69
+ from_dir = File.join(from, slug) # e.g. "category/union-chapel"
70
+ dest_url = "/" + File.join(to, slug, "") # e.g. "/venues/union-chapel/"
71
+ site.static_files << RedirectStaticFile.new(site, from_dir, "index.html", dest_url, emit_canonical: emit_canonical)
83
72
  end
84
73
  end
85
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-taxonomy-redirects
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Cross