jekyll-pdf 0.1.0 → 0.1.1
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 +4 -4
- data/Gemfile +5 -6
- data/README.md +60 -17
- data/lib/jekyll/pdf/document.rb +3 -3
- data/lib/jekyll/pdf/helper.rb +1 -2
- data/lib/jekyll/pdf/hooks.rb +1 -1
- data/lib/jekyll/pdf/partial.rb +6 -10
- metadata +2 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f528a86edb39066d05296d4e90d9daec587fbe3a
|
4
|
+
data.tar.gz: d7bae1c70e0528ce1b2db37637a0d50c3e8c8d29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8799316ad79950136609dc1ec7a2040a81f50462d9d22692ce504f4fde00b7ae46ce1900b9b8d11980a08381b4d792514e28aaf4385be238bf65dd099a3dddf3
|
7
|
+
data.tar.gz: 52d509a1be9525b904a393838f4b50c44d808a3df5de4f25833283ba4bcb03aabd7c43db1c39ce289f7ef7d8e9d3f5cbdaa42020cf05ff670f2fed589f5a10e6
|
data/Gemfile
CHANGED
@@ -1,9 +1,8 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
|
+
gemspec
|
2
3
|
|
3
|
-
|
4
|
-
gem
|
5
|
-
|
6
|
-
gem 'activesupport'
|
4
|
+
group :test do
|
5
|
+
gem "rake"
|
6
|
+
end
|
7
7
|
|
8
|
-
|
9
|
-
gem "jekyll-assets", "~> 2.0.0", :require => false
|
8
|
+
gem "jekyll-assets", "~> 2.2", :require => false
|
data/README.md
CHANGED
@@ -2,27 +2,38 @@
|
|
2
2
|
|
3
3
|
Dynamically generate PDFs from Jekyll pages, posts & documents.
|
4
4
|
|
5
|
-
|
5
|
+
[](https://travis-ci.org/abeMedia/jekyll-pdf)
|
6
|
+
[](https://gemnasium.com/github.com/abeMedia/jekyll-pdf)
|
6
7
|
|
7
|
-
|
8
|
+
## Usage
|
9
|
+
|
10
|
+
Add `gem "jekyll-pdf"` to your `Gemfile` and run `bundle`, then add `jekyll-pdf` to your `_config.yml` like so:
|
8
11
|
|
9
12
|
```yaml
|
10
13
|
gems:
|
11
14
|
- jekyll-pdf
|
12
15
|
```
|
13
16
|
|
14
|
-
Now add
|
17
|
+
Now add `pdf: true` to any page's or document's front-matter, that you'd like to create a PDF version of.
|
18
|
+
|
19
|
+
To activate **Jekyll PDF** for multiple pages or entire collections you can use Jekyll's [front-matter defaults](https://jekyllrb.com/docs/configuration/#front-matter-defaults). The following example will create PDFs for each post in your blog.
|
15
20
|
|
16
21
|
```yaml
|
17
|
-
|
22
|
+
defaults:
|
23
|
+
-
|
24
|
+
scope:
|
25
|
+
path: ""
|
26
|
+
type: "posts"
|
27
|
+
values:
|
28
|
+
pdf: true
|
18
29
|
```
|
19
30
|
|
20
|
-
|
31
|
+
Link to the PDF using the `{{ page.pdf_url }}` liquid variable.
|
21
32
|
|
22
33
|
|
23
34
|
## Configuration
|
24
35
|
|
25
|
-
**Jekyll PDF**
|
36
|
+
**Jekyll PDF** supports any configuration parameters [wkhtmltopdf](http://wkhtmltopdf.org/) does. For a full list of configuration parameters it supports see http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
|
26
37
|
|
27
38
|
```yaml
|
28
39
|
pdf:
|
@@ -31,32 +42,64 @@ pdf:
|
|
31
42
|
layout: layout | default: pdf
|
32
43
|
```
|
33
44
|
|
34
|
-
|
45
|
+
All configuration parameters (with exception of `cache`) can be overridden from your page's or it's PDF layout's front-matter.
|
46
|
+
|
47
|
+
### Cache Folder
|
48
|
+
|
49
|
+
If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets (unless specified otherwise).
|
50
|
+
|
51
|
+
## Layouts
|
35
52
|
|
36
53
|
**Jekyll PDF** will check for your current layout suffixed with `_pdf` e.g. if you're using a layout called `post`, it will look for `_layouts/post_pdf.html`, falling back to your default PDF layout (usually `_layouts/pdf.html`).
|
37
54
|
|
38
|
-
To override this add the `pdf_layout` variable to your page's YAML front-matter. For example:
|
55
|
+
To override this behaviour, add the `pdf_layout` variable to your page's YAML front-matter. For example:
|
39
56
|
|
40
57
|
```yaml
|
41
58
|
pdf_layout: my_custom_pdf_layout
|
42
59
|
```
|
43
60
|
|
44
|
-
## Partials
|
61
|
+
## Partials (Header, Footer & Cover Page)
|
45
62
|
|
46
|
-
We'll automatically look for all partials in `_includes` directory, e.g. `header_html: pdf_header.html` will tell Jekyll PDF use `_includes/pdf_header.html`.
|
63
|
+
We'll automatically look for all partials in `_includes` directory, e.g. `header_html: pdf_header.html` will tell Jekyll PDF use `_includes/pdf_header.html`.
|
47
64
|
|
48
|
-
|
65
|
+
Please note that wkhtmltopdf requires all partials to be valid HTML documents for example:
|
66
|
+
|
67
|
+
```html
|
68
|
+
<!DOCTYPE html>
|
69
|
+
<html>
|
70
|
+
<head>
|
71
|
+
<meta charset="utf-8" />
|
72
|
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.css">
|
73
|
+
</head>
|
74
|
+
<body>
|
75
|
+
Page {{ page.pdf.page }} of {{ page.pdf.topage }}
|
76
|
+
</body>
|
77
|
+
</html>
|
78
|
+
```
|
79
|
+
|
80
|
+
### Supported header & footer variables
|
81
|
+
|
82
|
+
| Liquid | Description |
|
83
|
+
|--------------------------------|-------------------------------------------------------------|
|
84
|
+
| `{{ page.pdf.page }}` | Replaced by the number of the pages currently being printed |
|
85
|
+
| `{{ page.pdf.topage }}` | Replaced by the number of the last page to be printed |
|
86
|
+
| `{{ page.pdf.section }}` | Replaced by the content of the current h1 tag |
|
87
|
+
| `{{ page.pdf.subsection }}` | Replaced by the content of the current h2 tag |
|
88
|
+
| `{{ page.pdf.subsubsection }}` | Replaced by the content of the current h3 tag |
|
49
89
|
|
50
|
-
If Jekyll Assets is installed, Jekyll PDF will automatically use the same cache folder as Jekyll Assets unless specified otherwise.
|
51
90
|
|
52
91
|
## Troubleshooting
|
53
92
|
|
54
|
-
###
|
93
|
+
### Images aren't displaying in the PDF
|
94
|
+
|
95
|
+
If your images aren't displaying in the PDF, this is most likely due to the fact that wkhtmltopdf doesn't know where to look. Try prefixing your image URLs with `file://{{ site.dest }}`.
|
96
|
+
For asset URLs in CSS files we recommend creating a separate CSS file overriding the URLs with the prefix mentioned above.
|
55
97
|
|
56
|
-
|
98
|
+
---
|
57
99
|
|
58
100
|
## To Do
|
59
101
|
|
60
|
-
-
|
61
|
-
-
|
62
|
-
-
|
102
|
+
- Remove dependencies for ActiveSupport & PDFKit
|
103
|
+
- Write tests (rspec)
|
104
|
+
- Package default PDF layout file in Gem
|
105
|
+
- Support layouts in partials
|
data/lib/jekyll/pdf/document.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'pdfkit'
|
2
|
-
require 'active_support/core_ext/hash/deep_merge'
|
3
2
|
|
4
3
|
module Jekyll
|
5
4
|
module PDF
|
@@ -22,7 +21,7 @@ module Jekyll
|
|
22
21
|
self.data['layout'] = layout
|
23
22
|
|
24
23
|
# Get PDF settings from the layouts
|
25
|
-
@settings
|
24
|
+
Jekyll::Utils.deep_merge_hashes!(@settings, self.getConfig(self.data))
|
26
25
|
|
27
26
|
PDFKit.configure do |config|
|
28
27
|
config.verbose = site.config['verbose']
|
@@ -50,7 +49,8 @@ module Jekyll
|
|
50
49
|
return settings if layout == nil
|
51
50
|
|
52
51
|
# Merge settings with parent layout settings
|
53
|
-
layout['pdf']
|
52
|
+
layout['pdf'] ||= {}
|
53
|
+
Jekyll::Utils.deep_merge_hashes!(layout['pdf'], settings)
|
54
54
|
|
55
55
|
return self.getConfig(layout)
|
56
56
|
end
|
data/lib/jekyll/pdf/helper.rb
CHANGED
@@ -2,8 +2,7 @@ module Jekyll
|
|
2
2
|
module PDF
|
3
3
|
module Helper
|
4
4
|
def fix_relative_paths
|
5
|
-
|
6
|
-
output = output.gsub(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2#{prefix}\\3\\2")
|
5
|
+
output.gsub!(/(href|src)=(['"])\/([^\/"']([^\"']*|[^"']*))?['"]/, "\\1=\\2file://#{site.dest}/\\3\\2") if output != nil
|
7
6
|
end
|
8
7
|
end
|
9
8
|
end
|
data/lib/jekyll/pdf/hooks.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Jekyll::Hooks.register :site, :post_write do |jekyll, payload|
|
3
3
|
if jekyll.data[:jekyll_pdf_partials]
|
4
4
|
jekyll.data[:jekyll_pdf_partials].each do |partial|
|
5
|
-
partial.
|
5
|
+
File.delete(partial) if File.exist?(partial)
|
6
6
|
end
|
7
7
|
jekyll.data.delete(:jekyll_pdf_partials)
|
8
8
|
end
|
data/lib/jekyll/pdf/partial.rb
CHANGED
@@ -42,8 +42,7 @@ module Jekyll
|
|
42
42
|
File.join(doc.path, partial)
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
def filename
|
45
|
+
def id
|
47
46
|
File.basename(path, File.extname(path)) + "-" + Digest::MD5.hexdigest(to_s) + File.extname(path)
|
48
47
|
end
|
49
48
|
|
@@ -74,19 +73,16 @@ module Jekyll
|
|
74
73
|
|
75
74
|
# generate temp file & set output to it's path
|
76
75
|
def write
|
77
|
-
tempfile = File.join(dir,
|
76
|
+
tempfile = File.absolute_path(File.join(dir, id))
|
78
77
|
unless File.exist?(tempfile)
|
79
78
|
FileUtils.mkdir_p(File.dirname(tempfile)) unless File.exist?(File.dirname(tempfile))
|
80
79
|
File.open(tempfile, 'w') {|f| f.write(to_s) }
|
81
80
|
end
|
82
|
-
site.data[:jekyll_pdf_partials] ||= []
|
83
|
-
site.data[:jekyll_pdf_partials] << self
|
84
81
|
@output = tempfile
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
File.delete(@output)
|
82
|
+
|
83
|
+
# store path for cleanup
|
84
|
+
site.data[:jekyll_pdf_partials] ||= []
|
85
|
+
site.data[:jekyll_pdf_partials] << "#{self}"
|
90
86
|
end
|
91
87
|
|
92
88
|
def place_in_layout?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Bouqdib
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-05-
|
11
|
+
date: 2016-05-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: wkhtmltopdf-installer
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: activesupport
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '4.2'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '4.2'
|
69
55
|
- !ruby/object:Gem::Dependency
|
70
56
|
name: jekyll
|
71
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,20 +72,6 @@ dependencies:
|
|
86
72
|
- - "~>"
|
87
73
|
- !ruby/object:Gem::Version
|
88
74
|
version: '3.1'
|
89
|
-
- !ruby/object:Gem::Dependency
|
90
|
-
name: rspec
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: '3.4'
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '3.4'
|
103
75
|
- !ruby/object:Gem::Dependency
|
104
76
|
name: bundler
|
105
77
|
requirement: !ruby/object:Gem::Requirement
|