jekyll-migrate-permalink 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a90cd8a179f79d35c4cb92ce235689a3d27f66b5
4
- data.tar.gz: bf0d198b1a92a1250f8ef3d351ed975da4007b2b
3
+ metadata.gz: 73dac4e6c719e1b652d0bba9b4e2d0479f845126
4
+ data.tar.gz: 49fd29a1c4db9d6cf3cdf2fcdc8a9e229521dc53
5
5
  SHA512:
6
- metadata.gz: d169b5c1de9ae5e8350dd89d4308781d50eab11821c0f22d8842f26f1262ddbc26c69af7c335cbffece809119b2e76a33c33bbe78199287149e7c2f308224983
7
- data.tar.gz: 88d3f4d84b8d81b69cd960e78d4278cbde19d5fc9eb2d89cf136d3a1bf858c4ce276c888ae63b9e29e020c5a7b0e6c971b246a14eacf057fa326fafaf2f072b8
6
+ metadata.gz: 3bc9486ef3d7c1715847cc4b215a71cbb9942c1e10371b656b57268a12c8771639e4a9845fa6167453edb06a5cdf775f4d230c34ca9ca0800ba95ffb71bd620c
7
+ data.tar.gz: 520b8f1907ed35fc92eb21c96a6d6feb0302396d2843597c39da031063c1078ee1632352abcf727daf8fb3bce8b9432116de2785442b57ba177bf5fe08f3d653
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/README.md CHANGED
@@ -41,6 +41,6 @@ The [`jekyll-redirect-from`](https://github.com/jekyll/jekyll-redirect-from) plu
41
41
  2. Update your permalink in `_config.yml`
42
42
  3. Build your site!
43
43
 
44
- ### Caveats
44
+ ## Caveats
45
45
 
46
46
  Note that the plugin loads the front matter as YAML in order to safely manipulate, and then converts it back to a string. This process may result in some slight formatting changes to your front matter.
@@ -26,30 +26,36 @@ module Jekyll
26
26
 
27
27
  site.posts.docs.each do |post|
28
28
  content = File.read(post.path, Utils.merged_file_read_opts(site, options))
29
- if content =~ Document::YAML_FRONT_MATTER_REGEXP
30
- content = $POSTMATCH
31
- frontmatter = SafeYAML.load(Regexp.last_match(1))
32
- end
29
+ output = process_content(content, post.url, opts["stategy"])
30
+ File.write(post.path, output, :mode => "w")
31
+ end
32
+ end
33
33
 
34
- if frontmatter.nil?
35
- frontmatter = frontmatter.to_h
36
- end
34
+ def process_content(content, url, strategy)
35
+ if content =~ Document::YAML_FRONT_MATTER_REGEXP
36
+ content = $POSTMATCH
37
+ frontmatter = SafeYAML.load(Regexp.last_match(1))
38
+ end
37
39
 
38
- if opts["strategy"] == "retain"
39
- frontmatter["permalink"] = post.url
40
+ if frontmatter.nil?
41
+ frontmatter = frontmatter.to_h
42
+ end
43
+
44
+ if strategy == "retain" && !frontmatter["permalink"]
45
+ frontmatter["permalink"] = url
46
+ else
47
+ if frontmatter["redirect_from"].is_a? Array
48
+ frontmatter["redirect_from"].push(url)
49
+ elsif frontmatter["redirect_from"].is_a? String
50
+ frontmatter["redirect_from"] = [frontmatter["redirect_from"], url]
40
51
  else
41
- if frontmatter["redirect_from"].is_a? Array
42
- frontmatter["redirect_from"].push(post.url)
43
- else
44
- frontmatter["redirect_from"] = [post.url]
45
- end
52
+ frontmatter["redirect_from"] = [url]
46
53
  end
47
-
48
- output = "#{frontmatter.to_yaml}---\n\n#{content}"
49
- File.write(post.path, output, :mode => "w")
50
-
51
54
  end
52
55
 
56
+ output = "#{frontmatter.to_yaml}---\n\n#{content}"
57
+
58
+ output
53
59
  end
54
60
 
55
61
  end
@@ -1,7 +1,7 @@
1
1
  module Jekyll
2
2
  module Migrate
3
3
  module Permalink
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-migrate-permalink
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
  - Max Chadwick
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -46,6 +46,7 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - .gitignore
49
+ - .rspec
49
50
  - .travis.yml
50
51
  - Gemfile
51
52
  - LICENSE.txt