jekyll-versioned_files 0.2.1 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +69 -59
- data/jekyll-versioned_files.gemspec +1 -1
- data/lib/jekyll/versioned_files/filedocuments.rb +96 -48
- data/lib/jekyll/versioned_files/frontmatter.rb +67 -0
- data/lib/jekyll/versioned_files/styler.rb +41 -0
- data/lib/jekyll/versioned_files/version.rb +1 -1
- data/lib/jekyll/versioned_files.rb +51 -19
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 355628a7a1699b8a47ade9692c67a4625451c65df9ffcf6354aa88818c0018ef
|
4
|
+
data.tar.gz: 85c07a87799c1d61c9e0dc7a7bd8790ae026e1079ed15fd4fc0330e00290af87
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 35dfdf041c9409ab3b3bddd1be5539197065fa416b2b08593caa05a968cdb4bc029378d4d387bbdf31a429679d7024007c4b689436a4b39e4f5a650cc5bae613
|
7
|
+
data.tar.gz: ec6904861df319a6422e5169daea21eabb5ee2d6e8917f19d50e1e9d25c2b9088ea238a0e70ecd466b0a8b6466bfe6e4694eb014d42683fd997bcb9b1881e437
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# jekyll-versioned_files plugin
|
2
2
|
|
3
|
-
This creates a [Jekyll::Collection](https://jekyllrb.com/docs/collections/) directory containing a document for each git revision of each file listed in a `_config.yml
|
3
|
+
This creates a [Jekyll::Collection](https://jekyllrb.com/docs/collections/) directory containing a document for each git revision of each file listed in a `_config.yml versioned_file_options[files]:` custom setting. It also creates sets of [git](https://git-scm.com/docs/git-diff) [diffs](https://en.wikipedia.org/wiki/Diff_utility) between those revisions.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -23,85 +23,67 @@ gems:
|
|
23
23
|
- jekyll-versioned_files
|
24
24
|
```
|
25
25
|
|
26
|
+
## Configuration
|
27
|
+
|
26
28
|
Add the collection setting in the `_config.yml`.
|
27
|
-
`{ versioned=>true }` must be set to the collection metadata for the designated versioned-files collection.
|
29
|
+
`{ versioned=>true }` must be set to the collection metadata for the designated versioned-files collection.
|
28
30
|
|
29
31
|
```yaml
|
30
|
-
# _config.yml
|
32
|
+
# _config.yml # versioned_files collection defaults
|
31
33
|
|
32
34
|
collections:
|
33
35
|
collection_labelname:
|
34
36
|
output: false
|
37
|
+
permalink: /:collection/:path/
|
35
38
|
versioned: true
|
36
39
|
```
|
37
40
|
|
38
|
-
|
41
|
+
`versioned_file_options` Configuration settings have been updated for the addition of the `git diff` feature.
|
39
42
|
|
40
|
-
|
43
|
+
`files` is the only requirement and takes one `sitesource/path/filename.ext` or an array of files.
|
44
|
+
The rest are defaults that can be changed.
|
41
45
|
|
42
|
-
|
43
|
-
# _config.yml
|
46
|
+
`formatting` sets the output type and ignore options for `git diff` files generated between pairs of file revisions.
|
44
47
|
|
45
|
-
|
46
|
-
|
48
|
+
- Set the `diff_ignore` options and the `output` style for the created comparison files.
|
49
|
+
- Read about the `git diff` [ignore options here](https://git-scm.com/docs/git-diff#git-diff---ignore-space-change)
|
50
|
+
- `diff_limit` will limit the diff pairs that are created to adjacent revisions only.
|
47
51
|
|
48
|
-
|
49
|
-
|
50
|
-
- _foo/bar.md
|
51
|
-
- hello_world.md
|
52
|
-
```
|
53
|
-
## Defaults
|
52
|
+
- `output: html` surrounds a deletion with `<del>` and an addition with `<ins>`.
|
53
|
+
- `output: markdown` uses `**strong**` for additions and `~~del~~` for deletions.
|
54
54
|
|
55
|
-
|
55
|
+
`frontmatter`
|
56
56
|
|
57
|
-
|
57
|
+
- The files Front Matter `permalink` key is changed to `orig_permalink` (if present) to prevent it from rendering out to that location. Change the name in the `_config`
|
58
|
+
- A [Front Matter](https://jekyllrb.com/docs/frontmatter/) key `sha` is added with the file's commit hash for a versioned file, and as an array of the two hashes use for `git diff`.
|
59
|
+
- A [Front Matter](https://jekyllrb.com/docs/frontmatter/) key `ver` is added with the revision version number or as an array containing the pair `diff` versions.
|
60
|
+
- If no changes have been made between the pair, a `No_Change: true` entry is added.
|
58
61
|
|
59
|
-
|
62
|
+
The created `diff` files insert a new Front Matter block at the top so any changes made to the original Front Matter will show up in the `page.content` [variable](https://jekyllrb.com/docs/variables/#page-variables)
|
60
63
|
|
61
64
|
```yaml
|
65
|
+
#_config.yml
|
66
|
+
|
67
|
+
versioned_file_options:
|
68
|
+
files: # file is required
|
69
|
+
- foo/bar.md
|
70
|
+
formatting:
|
71
|
+
diff_ignore:
|
72
|
+
ignore-all-space: false
|
73
|
+
ignore-blank-lines: true
|
74
|
+
ignore-space-change: true
|
75
|
+
diff_limit: false
|
76
|
+
output: markdown # or html
|
77
|
+
frontmatter:
|
78
|
+
permalink: orig_permalink # alt_name || false
|
79
|
+
sha: commit # alt_name || false
|
80
|
+
ver: ver # alt_name || false
|
62
81
|
|
63
|
-
collections:
|
64
|
-
versioned_files:
|
65
|
-
output: false
|
66
|
-
permalink: /:collection/:path/
|
67
|
-
versioned: true
|
68
|
-
```
|
69
|
-
### - Front Matter
|
70
|
-
|
71
|
-
- The files Front Matter `permalink` key is changed to `orig_permalink` (if present) to prevent it from rendering out to that location. Change the name in the `_config`
|
72
|
-
- A Front Matter key `sha` is added with the file's commit hash. Change the key name or remove it with the `git_versioned_frontmatter` setting
|
73
|
-
- A Front Matter key `ver` is added with the revision version number. Change the key name or remove it with the `git_versioned_frontmatter` setting
|
74
|
-
|
75
|
-
```yaml
|
76
|
-
git_versioned_frontmatter:
|
77
|
-
permalink: orig_permalink
|
78
|
-
sha: [ sha | false ]
|
79
|
-
ver: [ ver | false ]
|
80
82
|
```
|
81
83
|
|
82
84
|
## Usage
|
83
85
|
|
84
|
-
|
85
|
-
- `path/filename` is flattened in the versioned-files collection to `path_filename.ext`
|
86
|
-
|
87
|
-
```
|
88
|
-
# created directory & file structure
|
89
|
-
|
90
|
-
site.source
|
91
|
-
_collection_labelname
|
92
|
-
v1
|
93
|
-
_foo_bar.md
|
94
|
-
hello_world.md
|
95
|
-
v2
|
96
|
-
_foo_bar.md
|
97
|
-
hello_world.md
|
98
|
-
v3
|
99
|
-
hello_world.md
|
100
|
-
|
101
|
-
etc
|
102
|
-
```
|
103
|
-
|
104
|
-
The collection and documents/files can be accessed using [Jekyll Liquid](https://learn.cloudcannon.com/jekyll-cheat-sheet/) output for [collections](https://jekyllrb.com/docs/collections/):
|
86
|
+
[Collection](https://jekyllrb.com/docs/collections/) and [Documents](https://jekyllrb.com/docs/collections/#documents) can be accessed using [Jekyll Liquid](https://learn.cloudcannon.com/jekyll-cheat-sheet/) output:
|
105
87
|
|
106
88
|
```liquid
|
107
89
|
{{ site.collection_labelname }}
|
@@ -113,17 +95,45 @@ The collection and documents/files can be accessed using [Jekyll Liquid](https:/
|
|
113
95
|
{% end for %}
|
114
96
|
```
|
115
97
|
|
98
|
+
Versioned files are created at `site.source/_collection_labelname/v#/filename.ext`.
|
99
|
+
|
100
|
+
- `path/filename` is flattened in the versioned-files collection to `path_filename.ext`
|
101
|
+
|
102
|
+
Compared `diff` files are created at `site.source/_collection_labelname/diffs/v#/v#_v#_filename.ext`
|
103
|
+
|
104
|
+
```shell
|
105
|
+
# created directory & file structure
|
106
|
+
# site.source/
|
107
|
+
_collection_labelname/
|
108
|
+
diffs/
|
109
|
+
v1/
|
110
|
+
v1_v2_foo_bar.md
|
111
|
+
v1_v2_hello_world.md
|
112
|
+
v1_v3_hello_world.md
|
113
|
+
v2/
|
114
|
+
v2_v3_hello_world.md
|
115
|
+
v1/
|
116
|
+
foo_bar.md
|
117
|
+
hello_world.md
|
118
|
+
v2/
|
119
|
+
foo_bar.md
|
120
|
+
hello_world.md
|
121
|
+
v3/
|
122
|
+
hello_world.md
|
123
|
+
etc
|
124
|
+
```
|
125
|
+
|
116
126
|
### GitHub Pages + jekyll-versioned_files w/ Travis CI
|
117
127
|
|
118
128
|
As custom plugins do not work with GitHub Pages alone,
|
119
|
-
[Travis CI](https://travis-ci.org) can be used with the plugin to create the `_collection/
|
129
|
+
[Travis CI](https://travis-ci.org) w/ [GitHub deployment](https://docs.travis-ci.com/user/deployment/pages/) can be used with the plugin to create the `_collection/directory/` and `_collection/directory/versioned_files.ext` in the GitHub Pages repository - for GitHub Pages to access.
|
120
130
|
|
121
|
-
|
131
|
+
- If using Travis CI to create the files for GitHub Pages, the [collection](https://jekyllrb.com/docs/collections/) must be set in the `_config.yml` so gh-pages adds the collection when it renders the site.
|
122
132
|
|
123
133
|
Create a `.travis.yml` and set the `Environment Variable:` `$GITHUB_TOKEN` in Travis CI settings with a [GitHub Access Token](https://github.com/settings/tokens).
|
124
134
|
|
125
135
|
```yaml
|
126
|
-
#
|
136
|
+
# basic `.travis.yml` - add to gh-pages repo
|
127
137
|
|
128
138
|
language: ruby
|
129
139
|
rvm:
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.require_paths = ["lib"]
|
22
22
|
|
23
|
-
spec.add_dependency "jekyll", '~> 3.
|
23
|
+
spec.add_dependency "jekyll", '~> 3.7'
|
24
24
|
|
25
25
|
spec.add_development_dependency "bundler", "~> 1.16"
|
26
26
|
spec.add_development_dependency "rake", "~> 10.0"
|
@@ -1,85 +1,133 @@
|
|
1
1
|
module Jekyll
|
2
2
|
module VersionedFiles
|
3
3
|
class FileDocuments
|
4
|
-
|
4
|
+
attr_reader :diffoptions, :fname_paths
|
5
|
+
attr_accessor :line_count
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
#
|
7
|
+
DIFF_HEADER_REGEXP = %r!diff.+?@@.+?@@\n+?(?<=.)?!m
|
8
|
+
|
9
|
+
# Initialize FileDocuments.
|
9
10
|
#
|
10
11
|
# Returns nothing.
|
11
|
-
def initialize
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
@source_dir = site.source
|
16
|
-
@fname_paths = files.kind_of?(Array) ? files : files.scan(/.+/)
|
17
|
-
@fm_mods = VersionedFiles.frontmatter
|
12
|
+
def initialize
|
13
|
+
@diffoptions = VersionedFiles.format_options['diff_ignore']
|
14
|
+
@fname_paths = VersionedFiles.files
|
15
|
+
@style = Styler.new
|
18
16
|
end
|
19
17
|
|
20
18
|
# Creates the collection of versioned files in site.source directory
|
21
19
|
#
|
22
20
|
# Returns nothing
|
23
21
|
def create
|
24
|
-
|
25
|
-
|
22
|
+
revisions do |orig_file, sha_list|
|
23
|
+
sha_list.each_with_index do |sha, i|
|
26
24
|
ver = (i + 1).to_s
|
27
|
-
|
28
|
-
|
25
|
+
# Git revisioned file
|
26
|
+
composeversions(orig_file, sha, ver) do |content, data, file_path|
|
27
|
+
# dont re-write files
|
28
|
+
if File.exist?(file_path)
|
29
|
+
linecount(file_path)
|
30
|
+
next
|
31
|
+
end
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
+
version_content = FrontMatter.new(data)
|
34
|
+
version_content.content = content
|
35
|
+
write(file_path, version_content.update)
|
36
|
+
linecount(file_path)
|
37
|
+
end
|
38
|
+
end
|
33
39
|
|
34
|
-
|
40
|
+
sha_list.map!.with_index { |sha, i| [] << sha << (i + 1) }
|
41
|
+
# Git Diff combination files
|
42
|
+
composediffs(orig_file, line_count, sha_list.combination(2)) do |content, data, file_path|
|
43
|
+
content.sub!(DIFF_HEADER_REGEXP, '')
|
44
|
+
if change?(content)
|
45
|
+
VersionedFiles.frontmatter["no_change"] = false
|
46
|
+
styled_content = @style.style(content)
|
47
|
+
data.merge!(@style.stats.final)
|
48
|
+
else
|
49
|
+
VersionedFiles.frontmatter["no_change"] = "no_change"
|
50
|
+
data["no_change"] = true
|
51
|
+
end
|
52
|
+
|
53
|
+
fm = FrontMatter.new(data).create
|
54
|
+
diff_file = fm << styled_content
|
55
|
+
write(file_path, diff_file)
|
35
56
|
end
|
36
57
|
end
|
37
58
|
end
|
38
59
|
|
39
60
|
private
|
40
|
-
def
|
41
|
-
|
61
|
+
def change?(content)
|
62
|
+
!content.empty?
|
42
63
|
end
|
43
64
|
|
44
|
-
# Modify the versioned files' yaml front matter
|
45
|
-
#
|
46
|
-
# content - File content
|
47
|
-
# sha - current files commit hash
|
48
|
-
# ver - the number repersenting the files revision version
|
49
|
-
#
|
50
|
-
# Returns modified front matter
|
51
65
|
private
|
52
|
-
def
|
53
|
-
|
66
|
+
def composediffs(orig_file, lines, sha_pairs)
|
67
|
+
diff_dir = File.join(VersionedFiles.collection_dir, 'diffs')
|
68
|
+
VersionedFiles.make_dir(diff_dir)
|
69
|
+
# limit number of diff pairs
|
70
|
+
if VersionedFiles.format_options['diff_limit']
|
71
|
+
sha_pairs = sha_pairs.select { |pair| pair[1][1] - pair[0][1] == 1 }
|
72
|
+
end
|
73
|
+
|
74
|
+
sha_pairs.each do |pair|
|
75
|
+
data = {
|
76
|
+
"ver" => [pair[0][1], pair[1][1]],
|
77
|
+
"sha" => [pair[0][0], pair[1][0]]
|
78
|
+
}
|
79
|
+
diff_ver_dir = File.join(diff_dir, 'v'+pair[0][1].to_s)
|
80
|
+
file_name = 'v'+pair[0][1].to_s+'_v'+pair[1][1].to_s+'_'+flatten(orig_file)
|
54
81
|
|
55
|
-
|
56
|
-
|
82
|
+
VersionedFiles.make_dir(diff_ver_dir)
|
83
|
+
file_path = File.join(diff_ver_dir, file_name)
|
84
|
+
yield diff(orig_file, lines, pair[0][0], pair[1][0]), data, file_path
|
85
|
+
end
|
57
86
|
end
|
58
87
|
|
59
88
|
private
|
60
|
-
def
|
61
|
-
|
89
|
+
def composeversions(orig_file, sha, ver)
|
90
|
+
data = {"ver"=> ver, "sha"=> sha}
|
91
|
+
|
92
|
+
version_dir = File.join(VersionedFiles.collection_dir, 'v'+ver)
|
93
|
+
VersionedFiles.make_dir(version_dir)
|
94
|
+
|
95
|
+
file_path = File.join(version_dir, flatten(orig_file))
|
96
|
+
yield versioned_content(orig_file, sha), data, file_path
|
62
97
|
end
|
63
98
|
|
64
99
|
private
|
65
|
-
def
|
66
|
-
|
100
|
+
def diff(orig_file, lines, old_sha, new_sha)
|
101
|
+
%x{ git diff -U#{lines} --word-diff #{diffoptions} #{old_sha} #{new_sha} #{orig_file} }
|
67
102
|
end
|
68
103
|
|
69
|
-
# Collects the file content by its git commit hash
|
70
|
-
#
|
71
|
-
# fname_path - the `path/filename` to process
|
72
|
-
# sha - current fname_path's commit hash
|
73
|
-
# ver - the number repersenting the fname_path's revision version
|
74
|
-
#
|
75
|
-
# Returns file content to be writen
|
76
104
|
private
|
77
|
-
def
|
78
|
-
|
79
|
-
|
105
|
+
def flatten(orig_file)
|
106
|
+
orig_file.gsub("/", "_").delete_prefix("_")
|
107
|
+
end
|
108
|
+
|
109
|
+
private
|
110
|
+
def linecount(file_path)
|
111
|
+
lc = %x{ wc -l < #{file_path} }.to_i
|
112
|
+
self.line_count = lc unless line_count > lc
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
def revisions
|
117
|
+
fname_paths.each do |e|
|
118
|
+
self.line_count = 0
|
119
|
+
yield e, shalist(e)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private
|
124
|
+
def shalist(orig_file)
|
125
|
+
%x{ git rev-list --all #{orig_file} }.split("\n").reverse!
|
126
|
+
end
|
80
127
|
|
81
|
-
|
82
|
-
|
128
|
+
private
|
129
|
+
def versioned_content(orig_file, sha)
|
130
|
+
%x{ git cat-file -p #{sha}:#{orig_file} }.strip
|
83
131
|
end
|
84
132
|
|
85
133
|
private
|
@@ -0,0 +1,67 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module VersionedFiles
|
3
|
+
class FrontMatter
|
4
|
+
attr_accessor :data, :frontmatter, :new_data, :content
|
5
|
+
|
6
|
+
def data
|
7
|
+
@data ||= {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def frontmatter
|
11
|
+
@frontmatter = content.match(FRONTMATTER_REGEXP)[1] || nil
|
12
|
+
end
|
13
|
+
|
14
|
+
FRONTMATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m
|
15
|
+
# Initialize FileDocument.
|
16
|
+
#
|
17
|
+
# Returns nothing.
|
18
|
+
def initialize(new_data)
|
19
|
+
@data = {}
|
20
|
+
@fm_mods = VersionedFiles.frontmatter
|
21
|
+
@new_data = new_data || {}
|
22
|
+
end
|
23
|
+
|
24
|
+
# Updates the content's Front Matter
|
25
|
+
#
|
26
|
+
# Returns content with updated Front Matter
|
27
|
+
def update
|
28
|
+
mod_key("permalink") if data.has_key?("permalink") && @fm_mods["permalink"]
|
29
|
+
merge_data
|
30
|
+
@content.sub!(FRONTMATTER_REGEXP, to_frontmatter) || @content
|
31
|
+
end
|
32
|
+
|
33
|
+
# Creates a new Front matter block
|
34
|
+
#
|
35
|
+
# Returns content with updated Front Matter
|
36
|
+
def create
|
37
|
+
merge_data
|
38
|
+
to_frontmatter
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def merge_data
|
43
|
+
@new_data.each do |k,v|
|
44
|
+
next if !@fm_mods[k]
|
45
|
+
@data[@fm_mods[k]] = v # @new_data[k]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
def to_frontmatter
|
51
|
+
@data.to_yaml + "---\n\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
private
|
55
|
+
def to_data(content)
|
56
|
+
@data = SafeYAML.load(content) unless content.nil?
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
def mod_key(key)
|
61
|
+
if frontmatter
|
62
|
+
@data = SafeYAML.load(frontmatter[1].sub!(/#{key}/, @fm_mods[key]))
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Jekyll
|
2
|
+
module VersionedFiles
|
3
|
+
class Styler
|
4
|
+
attr_accessor :stats
|
5
|
+
|
6
|
+
DIFF_REGEX = %r!(\{\+)(.+?)(\+\})|(\[-)(.+?)(-\])!m
|
7
|
+
|
8
|
+
OUTPUT_STYLE = {
|
9
|
+
"markdown" => {
|
10
|
+
"add" => ['**','**'],
|
11
|
+
"del" => ['~~','~~']
|
12
|
+
},
|
13
|
+
"html" => {
|
14
|
+
"add" => ["<ins>", "</ins>"],
|
15
|
+
"del" => ["<del>", "</del>"]
|
16
|
+
}
|
17
|
+
}.freeze
|
18
|
+
# Initialize FileDocument.
|
19
|
+
#
|
20
|
+
# Returns nothing.
|
21
|
+
def initialize
|
22
|
+
@output = VersionedFiles.format_options['output']
|
23
|
+
@fm_mods = VersionedFiles.frontmatter
|
24
|
+
end
|
25
|
+
|
26
|
+
def style(content)
|
27
|
+
@stats = Counter.new
|
28
|
+
styled = content.gsub(DIFF_REGEX) do |m|
|
29
|
+
if $1 == "{+" && $3 == "+}"
|
30
|
+
@stats.ins
|
31
|
+
"#{OUTPUT_STYLE[@output]['add'][0]}#{$2}#{OUTPUT_STYLE[@output]['add'][1]}"
|
32
|
+
elsif $4 == "[-" && $6 == "-]"
|
33
|
+
@stats.del
|
34
|
+
"#{OUTPUT_STYLE[@output]['del'][0]}#{$5}#{OUTPUT_STYLE[@output]['del'][1]}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
styled || content
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,14 +1,24 @@
|
|
1
|
+
require 'jekyll/versioned_files/counter'
|
1
2
|
require 'jekyll/versioned_files/filecollection'
|
2
3
|
require 'jekyll/versioned_files/filedocuments'
|
4
|
+
require 'jekyll/versioned_files/frontmatter'
|
5
|
+
require 'jekyll/versioned_files/styler'
|
3
6
|
require 'jekyll/versioned_files/version'
|
4
7
|
|
5
8
|
module Jekyll
|
6
9
|
module VersionedFiles
|
7
10
|
class << self
|
8
|
-
attr_accessor :
|
9
|
-
:
|
11
|
+
attr_accessor :config_collection, :collection_dir, :collection_label,
|
12
|
+
:collection_metadata, :config_options, :diff_limit,
|
13
|
+
:files, :format_options, :frontmatter
|
10
14
|
end
|
11
15
|
|
16
|
+
ERROR_MSG = {
|
17
|
+
:Argument_options => "Missing `versioned_file_options` in config. Please update your _config.yml",
|
18
|
+
:Argument_files => "Missing a `versioned_file_options['files']` value in config. "\
|
19
|
+
"Please update your _config.yml with a file to process."
|
20
|
+
}.freeze
|
21
|
+
|
12
22
|
COLLECTION_LABEL = "versioned_files"
|
13
23
|
|
14
24
|
COLLECTION_METADATA = {
|
@@ -17,16 +27,38 @@ module Jekyll
|
|
17
27
|
"versioned" => true
|
18
28
|
}.freeze
|
19
29
|
|
30
|
+
FORMAT_OPTIONS = {
|
31
|
+
"diff_ignore" => {
|
32
|
+
"ignore-all-space" => false,
|
33
|
+
"ignore-blank-lines" => true,
|
34
|
+
"ignore-space-change" => true
|
35
|
+
},
|
36
|
+
"diff_limit" => false,
|
37
|
+
"output" => "markdown"
|
38
|
+
}.freeze
|
39
|
+
|
20
40
|
FRONTMATTER = {
|
21
41
|
"permalink" => "orig_permalink",
|
42
|
+
"no_change" => "no_change",
|
43
|
+
"diff_del" => "diff_del",
|
44
|
+
"diff_ins" => "diff_ins",
|
22
45
|
"sha" => "sha",
|
23
46
|
"ver" => "ver"
|
24
47
|
}.freeze
|
25
48
|
|
49
|
+
CONFIG_OPTIONS = {
|
50
|
+
"frontmatter" => FRONTMATTER,
|
51
|
+
"formatting" => FORMAT_OPTIONS
|
52
|
+
}.freeze
|
53
|
+
|
26
54
|
def self.make_dir(dir)
|
27
55
|
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
28
56
|
end
|
29
57
|
|
58
|
+
def self.merge!(default, new_hash)
|
59
|
+
Jekyll::Utils.deep_merge_hashes!(default, new_hash)
|
60
|
+
end
|
61
|
+
|
30
62
|
# Jekyll::Hook
|
31
63
|
#
|
32
64
|
# site - the site to which this collection belongs.
|
@@ -35,29 +67,29 @@ module Jekyll
|
|
35
67
|
Jekyll::Hooks.register :site, :after_init do |site|
|
36
68
|
self.config_collection = site.config['collections'].find{ |k, h| h['versioned'] }.to_a
|
37
69
|
|
38
|
-
raise ArgumentError,
|
39
|
-
|
40
|
-
self.files = site.config['git_versioned_file']
|
41
|
-
self.frontmatter = Jekyll::Utils.deep_merge_hashes(
|
42
|
-
FRONTMATTER,
|
43
|
-
site.config['git_versioned_frontmatter'] ||= {}
|
44
|
-
)
|
70
|
+
raise ArgumentError, ERROR_MSG[:Argument_options] unless site.config['versioned_file_options']
|
71
|
+
raise ArgumentError, ERROR_MSG[:Argument_files] unless site.config['versioned_file_options']['files']
|
45
72
|
|
46
|
-
self.collection_label
|
47
|
-
self.
|
48
|
-
|
49
|
-
|
50
|
-
|
73
|
+
self.collection_label = config_collection.empty? ? COLLECTION_LABEL : config_collection[0]
|
74
|
+
self.collection_metadata = merge!(COLLECTION_METADATA.dup, config_collection.last.to_h)
|
75
|
+
self.config_options = merge!(CONFIG_OPTIONS.dup, site.config['versioned_file_options'])
|
76
|
+
self.files = config_options['files']
|
77
|
+
self.files = files.kind_of?(Array) ? files : files.scan(/.+/)
|
78
|
+
self.frontmatter = config_options['frontmatter']
|
79
|
+
self.format_options = config_options['formatting']
|
80
|
+
self.format_options['diff_ignore'] = diffignore
|
51
81
|
|
52
82
|
collection = FileCollection.new(site)
|
53
83
|
# Merge versioned collection values into site.config,
|
54
84
|
# only adds values not in the _config.yml
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
85
|
+
merge!(site.config['collections'], {collection.label=>{collection.label=>collection.metadata}})
|
86
|
+
|
87
|
+
FileDocuments.new.create
|
88
|
+
end
|
59
89
|
|
60
|
-
|
90
|
+
private_class_method def self.diffignore
|
91
|
+
opts = format_options['diff_ignore'].select{ |k, v| v == true }.keys.join(" --")
|
92
|
+
"--" + opts unless opts.empty?
|
61
93
|
end
|
62
94
|
end
|
63
95
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jekyll-versioned_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- random-parts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '3.
|
19
|
+
version: '3.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '3.
|
26
|
+
version: '3.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,6 +85,8 @@ files:
|
|
85
85
|
- lib/jekyll/versioned_files.rb
|
86
86
|
- lib/jekyll/versioned_files/filecollection.rb
|
87
87
|
- lib/jekyll/versioned_files/filedocuments.rb
|
88
|
+
- lib/jekyll/versioned_files/frontmatter.rb
|
89
|
+
- lib/jekyll/versioned_files/styler.rb
|
88
90
|
- lib/jekyll/versioned_files/version.rb
|
89
91
|
homepage: https://github.com/random-parts/jekyll-versioned_files
|
90
92
|
licenses:
|