jekyll_post_files 1.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e186f35615449ee1e71d05eedd8ca90a4d44b446
4
+ data.tar.gz: 3b9bb202ea17ce86cf6a0602308dc7dd7ef7027d
5
+ SHA512:
6
+ metadata.gz: 7895c34af3d092028e50282bd65724c134852e266fcf382d53776857611910497637aa58880cf77c21d50d0cf941815ed301b0008d0a9acf568b1e8f43f803b9
7
+ data.tar.gz: 4411b830897828d25758788bba82588da11e5d97079c94a367140ea45da93ce5fee135132caf99915c77d5ebe379f2afb139a4f3af1018673f1b55123c86b59e
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
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
@@ -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.
@@ -0,0 +1,195 @@
1
+ # jekyll_post_files
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/jekyll_post_files.svg)](https://badge.fury.io/rb/jekyll_post_files)
4
+
5
+ ## Easing the management of images (and other files) attached to Markdown posts
6
+
7
+ ### The pain of Jekyll's recommended posts assets management
8
+
9
+ 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.
10
+
11
+ 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.
12
+
13
+ Imagine you have these files:
14
+
15
+ ```
16
+ _posts/
17
+ 2016-06/
18
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
19
+
20
+ assets/
21
+ 2016-06-09-cloudflare/
22
+ cloudflare-architecture.png
23
+ performance-report-sample.pdf
24
+ ```
25
+
26
+ To use the image and PDF files in the post's Markdown, you will have to write this:
27
+
28
+ ```markdown
29
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
30
+ tempor incididunt ut labore et dolore magna aliqua.
31
+
32
+ ![Cloudflare architecture](/assets/2016-06-09-cloudflare/cloudflare-architecture.png)
33
+
34
+ Ut enim ad minim veniam,
35
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
36
+ consequat.
37
+
38
+ Here is [an example of performance report](/assets/2016-06-09-cloudflare/performance-report-sample.pdf).
39
+
40
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
41
+ tempor incididunt ut labore et dolore magna aliqua.
42
+ ```
43
+
44
+ Painful to write.
45
+
46
+ Imagine you want to change the post's publication date, or one of the file names?
47
+
48
+ Painful to update.
49
+
50
+ 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.
51
+
52
+ Painful, and prone to errors.
53
+
54
+ 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?
55
+
56
+ Painful to preview.
57
+
58
+ ### There must be another way
59
+
60
+ What if instead, you could have the files stored like that:
61
+
62
+ ```
63
+ _posts/
64
+ 2016-06-09-cloudflare/
65
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
66
+ cloudflare-architecture.png
67
+ performance-report-sample.pdf
68
+ ```
69
+
70
+ And if you could write your Markdown like this:
71
+
72
+ ```markdown
73
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
74
+ tempor incididunt ut labore et dolore magna aliqua.
75
+
76
+ ![Cloudflare architecture](cloudflare-architecture.png)
77
+
78
+ Ut enim ad minim veniam,
79
+ quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo
80
+ consequat.
81
+
82
+ Here is [an example of performance report](performance-report-sample.pdf).
83
+
84
+ Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
85
+ tempor incididunt ut labore et dolore magna aliqua.
86
+ ```
87
+
88
+ Much easier!
89
+
90
+ - Easy to store, everything is in one single folder.
91
+ - Easy to write, no path to add to file links
92
+ - Easy to update
93
+ - Easy to move from `_drafts/` to `_posts/`, without anything to change in the Mardown content
94
+ - Easy to edit in any editor with live preview
95
+
96
+ ### Not every assets need this
97
+
98
+ [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.
99
+
100
+ 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.
101
+
102
+ 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.
103
+
104
+ ## How does it work?
105
+
106
+ 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.
107
+
108
+ Let's say you have these files:
109
+
110
+ ```
111
+ _posts/
112
+ 2016-06-09-cloudflare/
113
+ 2016-06-09-so-long-cloudflare-and-thanks-for-all-the-fissh.md
114
+ cloudflare-architecture.png
115
+ performance-report-sample.pdf
116
+ ```
117
+
118
+ And your Jekyll settings for permalinks are these:
119
+
120
+ ```yaml
121
+ # Permalinks
122
+ permalink: /:year/:month/:day/:title/
123
+ ```
124
+
125
+ Jekyll with this plugin will generate the site content like this:
126
+
127
+ ```
128
+ 2016/
129
+ 06/
130
+ 09/
131
+ so-long-cloudflare-and-thanks-for-all-the-fissh/
132
+ index.html
133
+ cloudflare-logo.png
134
+ performance-report-sample.pdf
135
+ ```
136
+
137
+ If you change your Jekyll settings for permalinks like these:
138
+
139
+ ```yaml
140
+ # Permalinks
141
+ permalink: /:year/:month/:day/:title.html
142
+ ```
143
+
144
+ Jekyll with this plugin will generate the site content like this:
145
+
146
+ ```
147
+ 2016/
148
+ 06/
149
+ 09/
150
+ so-long-cloudflare-and-thanks-for-all-the-fissh.html
151
+ cloudflare-logo.png
152
+ performance-report-sample.pdf
153
+ ```
154
+
155
+ Handy, isn't it?
156
+
157
+ ## Installation
158
+
159
+ Add this line to your `Gemfile`:
160
+
161
+ ```ruby
162
+ gem 'jekyll_post_files'
163
+ ```
164
+
165
+ Execute this:
166
+
167
+ ```shell
168
+ $ bundle
169
+ ```
170
+
171
+ And add this line to your `_config.yml`:
172
+
173
+ ```yaml
174
+ gems:
175
+ - jekyll_post_files
176
+ ```
177
+
178
+ ## Usage
179
+
180
+ You don't have anything to do.
181
+
182
+ 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.
183
+
184
+ ## Contributing
185
+
186
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/nhoizey/jekyll-post-files](https://github.com/nhoizey/jekyll_post_files)
187
+
188
+ ## License
189
+
190
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
191
+
192
+ ## Thanks
193
+
194
+ Inspired by [this old Gist](https://gist.github.com/kevinoid/3131752) by [@kevinoid](https://github.com/kevinoid/).
195
+
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "jekyll_post_files"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,22 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jekyll_post_files/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "jekyll_post_files"
8
+ spec.version = JekyllPostFiles::VERSION
9
+ spec.authors = ["Nicolas Hoizey"]
10
+ spec.email = ["nicolas@hoizey.com"]
11
+
12
+ spec.summary = %q{In Jekyll, copy static files from the _posts to the _site folder.}
13
+ spec.description = %q{When using Jekyll, this plugin copies all static files that are in the source _posts subfolder of a Markdown post to the destination subfolder in _site.}
14
+ spec.homepage = "https://github.com/nhoizey/jekyll_post_files"
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
+ end
@@ -0,0 +1,60 @@
1
+ require "jekyll_post_files/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
@@ -0,0 +1,3 @@
1
+ module JekyllPostFiles
2
+ VERSION = "1.0.5"
3
+ end
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll_post_files
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Nicolas Hoizey
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-06-29 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
+ description: When using Jekyll, this plugin copies all static files that are in the
42
+ source _posts subfolder of a Markdown post to the destination subfolder in _site.
43
+ email:
44
+ - nicolas@hoizey.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - bin/console
55
+ - bin/setup
56
+ - jekyll_post_files.gemspec
57
+ - lib/jekyll_post_files.rb
58
+ - lib/jekyll_post_files/version.rb
59
+ homepage: https://github.com/nhoizey/jekyll_post_files
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
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: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.6.4
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: In Jekyll, copy static files from the _posts to the _site folder.
83
+ test_files: []