jekyll-migrate-permalink 0.1.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 +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +32 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jekyll-migrate-permalink.gemspec +23 -0
- data/lib/jekyll/commands/migrate_permalink.rb +54 -0
- data/lib/jekyll/migrate/permalink/version.rb +7 -0
- data/lib/jekyll/migrate/permalink.rb +11 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9aa3e159978a144363692cb37c043400820b1aaf
|
4
|
+
data.tar.gz: 551ad25d8bd6fdda11bcbdff51e1f3d0e2d09ba0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a2463d4a9768ab3c57464084a1e0ee024d66cdc0979c3d06de567b199c70fd872cdd689f13194a6cc74d7e01676215669b123bfe1090115fba75fb390b78583
|
7
|
+
data.tar.gz: f769390180c7f7b2318fd11001c6f401ea292953d7f94cf6acbf2f5ba6592905a8cac1cf671a60d0347e1446b3a1d1667fc48de41489d91ab1eb47d65d034e2c
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Max Chadwick
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# jekyll-migrate-permalink
|
2
|
+
|
3
|
+
### What Is This?
|
4
|
+
|
5
|
+
`jekyll-migrate-permalink` is a plugin that aims to make your life easier if you're considering changing your [permalink](https://jekyllrb.com/docs/permalinks/). I got the idea for this plugin as I was considering a switch from `/blog/:title` to `/title`.
|
6
|
+
|
7
|
+
A change to your permalink means that any backlinks to your site will break. You have a few options...
|
8
|
+
|
9
|
+
- Redirect all old URLs to the new permalinks.
|
10
|
+
- Continue serving old content at your old URL and only use the new permalink style for new content
|
11
|
+
|
12
|
+
`jekyll-migrate-permalink` can help you with either approach.
|
13
|
+
|
14
|
+
### Redirect all old URLs to the new permalink
|
15
|
+
|
16
|
+
The [`jekyll-redirect-from`](https://github.com/jekyll/jekyll-redirect-from) plugin is [available on GitHub pages](https://pages.github.com/versions/) can be used to for creating redirects. However, to do this you need to update your front matter with a `redirect_from` specifying the old URL. `jekyll-migrate-permalink` makes this process painless.
|
17
|
+
|
18
|
+
1. Before changing your permalink style in `_config.yml` run `jekyll migrate-permalink`. The front matter will be updated on all your posts with a `redirect_from` referencing your post's current URL.
|
19
|
+
2. Update your permalink in `_config.yml`
|
20
|
+
3. Build your site!
|
21
|
+
|
22
|
+
### Continue serving old content at old URLs
|
23
|
+
|
24
|
+
`jekyll-migrate-plugin` can also help with this approach. Again, it's painless
|
25
|
+
|
26
|
+
1. Before changing your permalink style in `_config.yml` run `jekyll migrate-permalink --strategy retain`. The front matter will be updated on all your posts with a `permalink` referencing your current post's URL.
|
27
|
+
2. Update your permalink in `_config.yml`
|
28
|
+
3. Build your site!
|
29
|
+
|
30
|
+
### Caveats
|
31
|
+
|
32
|
+
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.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jekyll/migrate/permalink"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jekyll/migrate/permalink/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jekyll-migrate-permalink"
|
8
|
+
spec.version = Jekyll::Migrate::Permalink::VERSION
|
9
|
+
spec.authors = ["Max Chadwick"]
|
10
|
+
spec.email = ["mpchadwick@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A custom Jekyll command to help deal with side effects of changing your permalink}
|
13
|
+
spec.homepage = "https://github.com/mpchadwick/jekyll-migrate-permalink"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module Commands
|
3
|
+
class MigratePermalinks < Command
|
4
|
+
class << self
|
5
|
+
def init_with_program(prog)
|
6
|
+
prog.command(:"migrate-permalink") do |c|
|
7
|
+
c.description "Migrate your permalinks"
|
8
|
+
c.option "strategy", "-s", "--strategy STRATEGY", "Strategy"
|
9
|
+
|
10
|
+
add_build_options(c)
|
11
|
+
|
12
|
+
c.action do |args, opts|
|
13
|
+
opts["serving"] = false
|
14
|
+
Jekyll::Commands::MigratePermalinks.process(args, opts)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def process(args, opts)
|
20
|
+
Jekyll.logger.adjust_verbosity(opts)
|
21
|
+
options = configuration_from_options(opts)
|
22
|
+
site = Jekyll::Site.new(options)
|
23
|
+
|
24
|
+
site.reset
|
25
|
+
site.read
|
26
|
+
|
27
|
+
site.posts.docs.each do |post|
|
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
|
33
|
+
|
34
|
+
if opts["strategy"] == "retain"
|
35
|
+
frontmatter["permalink"] = post.url
|
36
|
+
else
|
37
|
+
if frontmatter["redirect_from"].is_a? Array
|
38
|
+
frontmatter["redirect_from"].push(post.url)
|
39
|
+
else
|
40
|
+
frontmatter["redirect_from"] = [post.url]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
output = "#{frontmatter.to_yaml}---\n\n#{content}"
|
45
|
+
File.write(post.path, output, :mode => "w")
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-migrate-permalink
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Max Chadwick
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- mpchadwick@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- .gitignore
|
49
|
+
- .travis.yml
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- jekyll-migrate-permalink.gemspec
|
57
|
+
- lib/jekyll/commands/migrate_permalink.rb
|
58
|
+
- lib/jekyll/migrate/permalink.rb
|
59
|
+
- lib/jekyll/migrate/permalink/version.rb
|
60
|
+
homepage: https://github.com/mpchadwick/jekyll-migrate-permalink
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.14.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: A custom Jekyll command to help deal with side effects of changing your permalink
|
84
|
+
test_files: []
|