jekyll-taxonomy-redirects 0.1.1 → 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 +4 -4
- data/lib/jekyll/taxonomy_redirects/version.rb +1 -1
- data/lib/jekyll/taxonomy_redirects.rb +27 -38
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0840e3d5e7160918bd0f9bd46b1f35104fe146ee5cb4572b40443b64bd564ff4'
|
|
4
|
+
data.tar.gz: 8b41088a085c61ce5fe0db9b4b1db23ecd332edf23c199ef2c3e4ede6f0845bd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e43630d2f190fccb097b996792b67135525dbc5ff97524609d8556ed83275205cec5e31af05772dfc0fedf3df99917635dcd4062be438825e1192990dc53ced1
|
|
7
|
+
data.tar.gz: a0229f817dc21dde9b52d6c04ff7ac8a74403fdf4a854e05804a9b675f3bda7058225cab7fe58bb49c5fd4c5152bd99b118c06c9b895168aac9a40fdd04c7a40
|
|
@@ -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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
@
|
|
29
|
-
@
|
|
30
|
-
|
|
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
|
-
|
|
33
|
-
|
|
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
|
-
|
|
37
|
-
|
|
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.
|
|
52
|
+
site.static_files << RedirectStaticFile.new(site, from, "index.html", to, emit_canonical: emit_canonical)
|
|
64
53
|
end
|
|
65
54
|
|
|
66
|
-
#
|
|
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
|
-
|
|
81
|
-
dest_url
|
|
82
|
-
site.
|
|
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
|