jekyll-postfiles 2.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 83ecad5523c6564d8bf0f84674f54ba82295ca03
4
+ data.tar.gz: 96a2acb28eb23d7771dcf2d845b4eed0f7f8a686
5
+ SHA512:
6
+ metadata.gz: c844451a153fa9dcd1451555b6839496f8ec43f30ae57e9cbf6435bd08eb1106860d77cc463e3b0fdd0573d1f00c9ce948dc4c666f9ec5fe6a06dbbaf4ed6114
7
+ data.tar.gz: b645575e93dbff13c94582fbcc635f3423a7d39773ca161f650276aca43f62b9bb9ff57a16a8c10862e12f664ad224cf3c8a210e3776e880327e1ec5295bfdd4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jekyll-post-files.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Nicolas Hoizey
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,196 @@
1
+ # jekyll-postfiles
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll-postfiles.svg)](https://badge.fury.io/rb/jekyll-postfiles)
4
+ [![Gem Downloads](https://img.shields.io/gem/dt/jekyll-postfiles.svg?style=flat)](http://rubygems.org/gems/jekyll-postfiles)
5
+
6
+ ## Easing the management of images (and other files) attached to Markdown posts
7
+
8
+ ### The pain of Jekyll's recommended posts assets management
9
+
10
+ Jekyll's natural way to deal with static files attached to posts, like images or PDFs, is to put them all in a global `assets/` (or `downloads/`) folder at the site root. Read "[Including images and resources](https://jekyllrb.com/docs/posts/#including-images-and-resources)" in Jekyll's documentation.
11
+
12
+ You can of course put files in subfolders of `assets/`, but it will be really cumbersome to manage posts' Markdown files in `_posts/` or a subfolder, and images elsewhere, and then use the good hierarchy in all Markdown image tags.
13
+
14
+ Imagine you have these files:
15
+
16
+ ```
17
+ _posts/
18
+ 2016-06/
19
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
20
+
21
+ assets/
22
+ 2016-06-09-cloudflare/
23
+ cloudflare-architecture.png
24
+ performance-report-sample.pdf
25
+ ```
26
+
27
+ To use the image and PDF files in the post's Markdown, you will have to write this:
28
+
29
+ ```markdown
30
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
31
+ tempor incididunt ut labore et dolore magna aliqua.
32
+
33
+ ![Cloudflare architecture](/assets/2016-06-09-cloudflare/cloudflare-architecture.png)
34
+
35
+ Ut enim ad minim veniam,
36
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
37
+ consequat.
38
+
39
+ Here is [an example of performance report](/assets/2016-06-09-cloudflare/performance-report-sample.pdf).
40
+
41
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
42
+ tempor incididunt ut labore et dolore magna aliqua.
43
+ ```
44
+
45
+ Painful to write.
46
+
47
+ Imagine you want to change the post's publication date, or one of the file names?
48
+
49
+ Painful to update.
50
+
51
+ What if you want to put new WIP Markdown files in `_drafts/`, and the attached assets somewhere in a way they won't be copied to the destination `_site/` folder next time you build the site? You can't put the files in the `assets/` folder, so when you will publish the draft, you will have to change the assets location in the Markdown file.
52
+
53
+ Painful, and prone to errors.
54
+
55
+ And what about previewing the content while editing? If you use an editor like [MacDown](http://macdown.uranusjr.com/) with live preview, how will it find the actual path to the images? What means `/assets/…` for the editor?
56
+
57
+ Painful to preview.
58
+
59
+ ### There must be another way
60
+
61
+ What if instead, you could have the files stored like that:
62
+
63
+ ```
64
+ _posts/
65
+ 2016-06-09-cloudflare/
66
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
67
+ cloudflare-architecture.png
68
+ performance-report-sample.pdf
69
+ ```
70
+
71
+ And if you could write your Markdown like this:
72
+
73
+ ```markdown
74
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
75
+ tempor incididunt ut labore et dolore magna aliqua.
76
+
77
+ ![Cloudflare architecture](cloudflare-architecture.png)
78
+
79
+ Ut enim ad minim veniam,
80
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
81
+ consequat.
82
+
83
+ Here is [an example of performance report](performance-report-sample.pdf).
84
+
85
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
86
+ tempor incididunt ut labore et dolore magna aliqua.
87
+ ```
88
+
89
+ Much easier!
90
+
91
+ - Easy to store, everything is in one single folder.
92
+ - Easy to write, no path to add to file links
93
+ - Easy to update
94
+ - Easy to move from `_drafts/` to `_posts/`, without anything to change in the Mardown content
95
+ - Easy to edit in any editor with live preview
96
+
97
+ ### Not every assets need this
98
+
99
+ [Some Jekyll users will try to convince you](http://stackoverflow.com/a/10366173/717195) it's a bad idea, because it means the asset is tightly linked to the post.
100
+
101
+ In my own experience, 95% of assets, at least, are used in one single post. And this is pretty common to find such requests from users of other static generators, like [Hugo](https://github.com/spf13/hugo/issues/147) ([fixed in May 2015](https://github.com/spf13/hugo/issues/147#issuecomment-104067783)), [Nikola](https://github.com/getnikola/nikola/issues/2266) ([already there, but not obvious or user friendly](https://github.com/getnikola/nikola/issues/2266#issuecomment-189211387)), [Octopress](http://stackoverflow.com/questions/17052468/insert-local-image-into-a-blog-post-with-octopress), etc.
102
+
103
+ But it's true this might not be ideal for all assets (the remaining 5%), so you can of course continue using full assets paths with `/assets/…` to have a few assets shared by several posts.
104
+
105
+ ## How does it work?
106
+
107
+ This plugin takes any file that is in posts folders, and copy them to the folder in which the post HTML page will be created.
108
+
109
+ Let's say you have these files:
110
+
111
+ ```
112
+ _posts/
113
+ 2016-06-09-cloudflare/
114
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
115
+ cloudflare-architecture.png
116
+ performance-report-sample.pdf
117
+ ```
118
+
119
+ And your Jekyll settings for permalinks are these:
120
+
121
+ ```yaml
122
+ # Permalinks
123
+ permalink: /:year/:month/:day/:title/
124
+ ```
125
+
126
+ Jekyll with this plugin will generate the site content like this:
127
+
128
+ ```
129
+ 2016/
130
+ 06/
131
+ 09/
132
+ so-long-cloudflare-and-thanks-for-all-the-fissh/
133
+ index.html
134
+ cloudflare-logo.png
135
+ performance-report-sample.pdf
136
+ ```
137
+
138
+ If you change your Jekyll settings for permalinks like these:
139
+
140
+ ```yaml
141
+ # Permalinks
142
+ permalink: /:year/:month/:day/:title.html
143
+ ```
144
+
145
+ Jekyll with this plugin will generate the site content like this:
146
+
147
+ ```
148
+ 2016/
149
+ 06/
150
+ 09/
151
+ so-long-cloudflare-and-thanks-for-all-the-fissh.html
152
+ cloudflare-logo.png
153
+ performance-report-sample.pdf
154
+ ```
155
+
156
+ Handy, isn't it?
157
+
158
+ ## Installation
159
+
160
+ Add this line to your `Gemfile`:
161
+
162
+ ```ruby
163
+ gem 'jekyll-postfiles'
164
+ ```
165
+
166
+ Execute this:
167
+
168
+ ```shell
169
+ $ bundle
170
+ ```
171
+
172
+ And add this line to your `_config.yml`:
173
+
174
+ ```yaml
175
+ gems:
176
+ - jekyll-postfiles
177
+ ```
178
+
179
+ ## Usage
180
+
181
+ You don't have anything to do.
182
+
183
+ Just put the images (and PDFs, etc.) in the same folder as your Markdown files, and use the standard Markdown image syntax, without any path.
184
+
185
+ ## Contributing
186
+
187
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/nhoizey/jekyll-postfiles](https://github.com/nhoizey/jekyll-postfiles)
188
+
189
+ ## License
190
+
191
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
192
+
193
+ ## Thanks
194
+
195
+ Inspired by [this old Gist](https://gist.github.com/kevinoid/3131752) by [@kevinoid](https://github.com/kevinoid/).
196
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/_release.sh ADDED
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+ # https://github.com/svenfuchs/gem-release
3
+
4
+ if [ -z "$1" ]; then
5
+ echo "Usage: provide the release type (patch, minor, major)."
6
+ exit -1
7
+ else
8
+ release_type="$@"
9
+ fi
10
+
11
+ gem bump --version "$release_type" --tag --release
@@ -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-postfiles/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll-postfiles"
8
+ spec.version = JekyllPostFiles::VERSION
9
+ spec.authors = ["Nicolas Hoizey"]
10
+ spec.email = ["nicolas@hoizey.com"]
11
+
12
+ spec.summary = %q{A Jekyll plugin to keep posts assets alongside their Markdown files}
13
+ spec.description = %q{This plugin takes any file that is in posts folders, and copy them to the folder in which the post HTML page will be created.}
14
+ spec.homepage = "https://nhoizey.github.io/jekyll-postfiles/"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_development_dependency "bundler", "~> 1.12"
21
+ spec.add_development_dependency "rake", "~> 10.0"
22
+ spec.add_development_dependency "rubocop", "~> 0.42"
23
+ end
@@ -0,0 +1,3 @@
1
+ module JekyllPostFiles
2
+ VERSION = "2.0.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require "jekyll-postfiles/version"
2
+ require "jekyll"
3
+
4
+ module Jekyll
5
+
6
+ class PostFile < StaticFile
7
+
8
+ # Initialize a new PostFile.
9
+ #
10
+ # site - The Site.
11
+ # base - The String path to the <source>.
12
+ # dir - The String path of the source directory of the file (rel <source>).
13
+ # name - The String filename of the file.
14
+ def initialize(site, base, dir, name, dest)
15
+ super(site, base, dir, name)
16
+ @name = name
17
+ @dest = dest
18
+ end
19
+
20
+ # Obtain destination path.
21
+ #
22
+ # dest - The String path to the destination dir.
23
+ #
24
+ # Returns destination file path.
25
+ def destination(dest)
26
+ File.join(@dest, @name)
27
+ end
28
+ end
29
+
30
+ class PostFileGenerator < Generator
31
+
32
+ # Copy the files from post's folder.
33
+ #
34
+ # post - A Post which may have associated content.
35
+ def copy_post_files(post)
36
+
37
+ postpath = post.path
38
+ postdir = File.dirname(postpath)
39
+ destdir = File.dirname(post.destination(""))
40
+
41
+ site = post.site
42
+ sitesrcdir = site.source
43
+ contents = Dir.glob(File.join(postdir, '**', '*')) do |filepath|
44
+ if filepath != postpath
45
+ filedir, filename = File.split(filepath[sitesrcdir.length..-1])
46
+ site.static_files <<
47
+ PostFile.new(site, sitesrcdir, filedir, filename, destdir)
48
+ end
49
+ end
50
+ end
51
+
52
+ # Generate content by copying files associated with each post.
53
+ def generate(site)
54
+ site.posts.docs.each do |post|
55
+ copy_post_files(post)
56
+ end
57
+ end
58
+ end
59
+
60
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-postfiles
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Hoizey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-08-04 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.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.42'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.42'
55
+ description: This plugin takes any file that is in posts folders, and copy them to
56
+ the folder in which the post HTML page will be created.
57
+ email:
58
+ - nicolas@hoizey.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - _release.sh
68
+ - jekyll-postfiles.gemspec
69
+ - lib/jekyll-postfiles.rb
70
+ - lib/jekyll-postfiles/version.rb
71
+ homepage: https://nhoizey.github.io/jekyll-postfiles/
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.6.4
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: A Jekyll plugin to keep posts assets alongside their Markdown files
95
+ test_files: []