jekyll_custom_permalink 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 23d765af94dfb8fde47e0bf948f8051fc14841a2c8324a8b16d3f18461835ca4
4
+ data.tar.gz: 84102fea573672f031173789b61429041d04e2682fa9c04f7a98af1164a1831d
5
+ SHA512:
6
+ metadata.gz: 4bec2416a3af0162ccc7f11a678a86eee737f47edc92e93e872e5cf3eea7a23b716bdd266f5bac2f271f7949e4a9ea60242fb916f0ff4fec49e69380a0909281
7
+ data.tar.gz: e90221aa72389233877636c849ec6c102bb295221fc9351139869cac70972a2393819bc1338846442c5a403de432d1804b92a5a09c72cbc04afe0419a98ef09e
data/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Niklas Eicker.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Jekyll custom permalink
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll_custom_permalink.svg)](https://badge.fury.io/rb/jekyll_custom_permalink)
4
+
5
+ This Jekyll plugin allows you to use custom Front Matter in the `permalink` setting of collections.
6
+
7
+ ## Installation
8
+
9
+ Add the plugin to your site's Gemfile:
10
+ ```ruby
11
+ group :jekyll_plugins do
12
+ # your other jekyll plugins...
13
+ gem 'jekyll_custom_permalink', '~> 0.0'
14
+ end
15
+ ```
16
+
17
+ Then run
18
+ ```bash
19
+ $ bundle install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Lets assume that you have some options for your collection "projects" defined in `_config`:
25
+ ```yml
26
+ collections:
27
+ projects:
28
+ output: true
29
+ permalink: projects/:title/
30
+ ```
31
+
32
+ You would like to use custom Front Matter in the paths of your projects. For example, it would be great to be able to include the Front Matter variable `type` in the links to your projects, which is defined in every file belonging to the "projects" collection.
33
+ ```yml
34
+ ---
35
+ layout: page
36
+ type: python
37
+ title: MyAwesomeProject
38
+ ---
39
+ Some content
40
+ ```
41
+
42
+ You can use the `type` variable in your permalink by first adding it to an array of custom permalink placeholders for the collection, and then adding the placeholder to the permalink setting prefixed with a `:` like every other Jekyll placeholder.
43
+ ```yml
44
+ collections:
45
+ projects:
46
+ output: true
47
+ custom_permalink_placeholders: ["type"]
48
+ permalink: projects/:type/:title/
49
+ ```
50
+ These settings lead to the "project" page, shown above, to be live at `/projects/python/MyAwesomeProject`.
51
+
52
+ If the variable is not defined, it is ignored for the permalink. Meaning `projects/:type/:title/` will be like `projects/:title/` for a document without `type` set in its Front Matter. This is the same behaviour as for the default Jekyll placeholders.
@@ -0,0 +1,8 @@
1
+ module JekyllCustomPermalink
2
+ autoload :VERSION, 'jekyll_custom_permalink/version.rb'
3
+
4
+ class CustomPermalinkError < StandardError; end
5
+ class CustomPermalinkSetupError < CustomPermalinkError; end
6
+ end
7
+
8
+ require 'jekyll_custom_permalink/custom_permalink.rb'
@@ -0,0 +1,29 @@
1
+ module JekyllCustomPermalink
2
+ class CustomPermalink < Jekyll::Generator
3
+ safe true
4
+ priority :low
5
+
6
+ def generate(site)
7
+ # nothing to do, wait for hook
8
+ end
9
+
10
+ Jekyll::Hooks.register :documents, :pre_render do |doc|
11
+ begin
12
+ # check if jekyll can resolve the url template
13
+ doc.url
14
+ rescue NoMethodError => error
15
+ begin
16
+ if !doc.collection.metadata.fetch("custom_permalink_placeholders").is_a?(Array)
17
+ raise CustomPermalinkSetupError, "The custom placeholders need to be an array! Check the settings of your '#{doc.collection.label}' collection."
18
+ end
19
+ def doc.url_template
20
+ @custom_url_template ||= collection.metadata.fetch("custom_permalink_placeholders").inject(collection.url_template){|o,m| o.sub ":" + m, data[m].to_s}
21
+ end
22
+ rescue KeyError
23
+ # "custom_permalink_placeholders"
24
+ raise CustomPermalinkSetupError, "No custom placeholders defined for the '#{doc.collection.label}' collection. Define an array of placeholders under the key 'custom_permalink_placeholders'. \nCaused by: " + error.to_s
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllCustomPermalink
2
+ VERSION = '0.0.1'
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_custom_permalink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Niklas Eicker
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ description: Jekyll plugin allowing usage of custom Front Matter in the `permalink`
42
+ setting of collections.
43
+ email:
44
+ - hello@nikl.me
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - LICENSE.md
50
+ - README.md
51
+ - lib/jekyll_custom_permalink.rb
52
+ - lib/jekyll_custom_permalink/custom_permalink.rb
53
+ - lib/jekyll_custom_permalink/version.rb
54
+ homepage: https://github.com/NiklasEi/jekyll_custom_permalink
55
+ licenses:
56
+ - MIT
57
+ metadata:
58
+ bug_tracker_uri: https://github.com/NiklasEi/jekyll_custom_permalink/issues
59
+ documentation_uri: https://github.com/NiklasEi/jekyll_custom_permalink
60
+ homepage_uri: https://github.com/NiklasEi/jekyll_custom_permalink
61
+ source_code_uri: https://github.com/NiklasEi/jekyll_custom_permalink
62
+ changelog_uri: https://github.com/NiklasEi/jekyll_custom_permalink/blob/master/changelog.md
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: 1.9.3
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubygems_version: 3.0.3
79
+ signing_key:
80
+ specification_version: 4
81
+ summary: Jekyll plugin allowing usage of custom Front Matter in the `permalink` setting
82
+ of collections.
83
+ test_files: []