jekyll-write-and-commit-changes 0.2.3 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b1861eb1e9821fc6eeb6b728019add0efc2594dab19d9c927702fc56c16776a6
4
- data.tar.gz: 69f8e3bdd0b90a7b55b66d200b39ee9f60a413e122fd402f4566eb69342cbf7f
3
+ metadata.gz: 42e65059fbab88eb06a68f3c1e42fc2389668974e53bc23a88f3d67801e35e88
4
+ data.tar.gz: 9c6d9ef54754b55a6b636574877af27edf7e9db69cfb9057958229acc2a56afd
5
5
  SHA512:
6
- metadata.gz: a3f0498280143b872d32706442c6889b3ae463674624fe28b9fbdf2c635bd7c23d9d6c5e558efe3e709409f53b4a06fbe59e48736037be12b1ee56bc230dfa84
7
- data.tar.gz: 3c6da359fbb2c6b7cd793f20c8a2978222adb191e8374a3d647ac374a0d0e80f8288a4174fb084ceb9f18908e7df2f67494fac924a2638c4b84be40e3ec087b9
6
+ metadata.gz: c0931c6af609c62eb5ffe49f3666aff1914735be38a79953f886dfe2e146429364871d2cde90aee9b7ce0d5435b10abd15e493f66af1865b7686628dfa3b8565
7
+ data.tar.gz: 7167de921885b9dff4cdc6486948f529cfa72c7e1d438701ba92c7b86ed6cccd093d2e6b3dbb8b3168a3fc1e4cc635b4d27047b0beb450f8bb7c1715796c498c
checksums.yaml.gz.sig ADDED
Binary file
data/README.md CHANGED
@@ -47,6 +47,13 @@ Jekyll::Hooks.register :site, :post_read do |site|
47
47
  end
48
48
  ```
49
49
 
50
+ ## Sutty CMS
51
+
52
+ If you're using the [Sutty CMS](https://panel.sutty.nl), the plugin will
53
+ detect the layout schemas on the `_data/layouts/` directory and extract
54
+ the required attributes on the order they're set. This way the post will
55
+ not change the order of the attributes.
56
+
50
57
  ## Contributing
51
58
 
52
59
  Bug reports and pull requests are welcome on 0xacab.org at
@@ -1,25 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'digest'
3
4
  require 'jekyll/document'
4
5
 
5
6
  module Jekyll
6
7
  module DocumentWriter
8
+ EXCLUDED_ATTRIBUTES = %w[slug ext date excerpt].freeze
9
+ SUTTY_FIELDS = %w[permalink alternate_permalinks layout uuid render_with_liquid usuaries created_at last_modified_at].freeze
10
+
7
11
  def self.included(base)
8
12
  base.class_eval do
9
13
  # Writes changes to the file and adds it to git staged changes
14
+ #
15
+ # @return [Bool,nil]
10
16
  def save
11
17
  return unless data.fetch('save', true)
12
18
 
13
- Jekyll.logger.debug 'Writing', path
19
+ if File.exist?(path)
20
+ file_digest = Digest::SHA2.file(path).hexdigest
21
+ content_digest = Digest::SHA2.hexdigest(writable_content)
22
+
23
+ return if file_digest == content_digest
24
+
25
+ Jekyll.logger.debug 'Writing:', real_path
26
+ else
27
+ Jekyll.logger.debug 'Creating:', path
28
+ end
14
29
 
15
30
  file = File.open(path, File::RDWR | File::CREAT, 0o640) do |f|
16
31
  f.flock(File::LOCK_EX)
17
32
  f.rewind
18
-
19
- f.write(sanitized_data.to_yaml)
20
- f.write("---\n\n")
21
- f.write(content)
22
-
33
+ f.write(writable_content)
23
34
  f.flush
24
35
  f.truncate(f.pos)
25
36
  end
@@ -29,30 +40,16 @@ module Jekyll
29
40
  file.zero?
30
41
  end
31
42
 
32
- # Resolves the real path for the document
33
- # @return [String]
34
- def real_path
35
- @real_path ||= Pathname.new(relative_path).realpath.relative_path_from(site.source).to_s
36
- end
37
-
38
43
  # Prepares the data for dumping, by excluding some keys and
39
44
  # transforming other Documents replaced by jekyll-linked-posts.
40
45
  #
41
46
  # @return [Hash]
42
47
  def sanitized_data
43
- data.reject do |k, _|
44
- excluded_attributes.include? k
45
- end.transform_values do |value|
48
+ data.slice(*attributes).transform_values do |value|
46
49
  case value
47
- when Jekyll::Document
50
+ when Jekyll::Document, Jekyll::Convertible
48
51
  value.data['uuid']
49
- when Jekyll::Convertible
50
- value.data['uuid']
51
- when Set
52
- value.map do |v|
53
- v.respond_to?(:data) ? v.data['uuid'] : v
54
- end
55
- when Array
52
+ when Array, Set
56
53
  value.map do |v|
57
54
  v.respond_to?(:data) ? v.data['uuid'] : v
58
55
  end
@@ -66,8 +63,49 @@ module Jekyll
66
63
  end
67
64
  end
68
65
 
69
- def excluded_attributes
70
- @excluded_attributes ||= %w[slug ext date excerpt]
66
+ private
67
+
68
+ # Resolves the real path for the document
69
+ #
70
+ # @return [String]
71
+ def real_path
72
+ @real_path ||= Pathname.new(relative_path).realpath.relative_path_from(site.source).to_s
73
+ rescue Errno::ENOENT
74
+ relative_path
75
+ end
76
+
77
+ # @return [Array<String>]
78
+ def attributes
79
+ @attributes ||= data.keys - EXCLUDED_ATTRIBUTES
80
+ end
81
+
82
+ def layout?
83
+ layout.is_a? Hash
84
+ end
85
+
86
+ # @return [Hash,nil]
87
+ def layout
88
+ @layout ||= site.data.dig('layouts', data['layout'])
89
+ end
90
+
91
+ def fields
92
+ @fields ||= (layout.keys + SUTTY_FIELDS).uniq
93
+ end
94
+
95
+ # @return [String]
96
+ def writable_content
97
+ @writable_content ||=
98
+ begin
99
+ dumpable_data = sanitized_data
100
+ dumpable_data = dumpable_data.slice(*fields) if layout?
101
+
102
+ <<~CONTENT
103
+ #{dumpable_data.to_yaml.chomp}
104
+ ---
105
+
106
+ #{content.chomp}
107
+ CONTENT
108
+ end
71
109
  end
72
110
  end
73
111
  end
data.tar.gz.sig ADDED
Binary file
metadata CHANGED
@@ -1,14 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-write-and-commit-changes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - f
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2022-07-26 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIEYD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1ZAjlzw7LeJlju4BWUvKLjrbGiDNBYQir
29
+ lmyHhYXWV3gnozs08sM3BNzwsPwDwIhYOu3Kc+36DtEpKToUxqEGbsxX8uGzyp88
30
+ HTlaNsaHCZBeB2wgUYcIeO2lKdNu+V9WxfTRhYu+02OfLRv65qSfm6uck1Ml1Cg/
31
+ tn1Y7mLHSdnWPZCQhQZA0wX/SFL64DeozAwJLhYtKneU/m5PEqv9nNnJVCLlbODB
32
+ zFTjbsKtpWxNN+xWsJbjukggS8uX1400WqyjUCitDxDJknP+xeAg8wt2wT+IC1X1
33
+ zMY8gjxoBfwPum74cBTaZzYMpeGaS1fJ3N4NBU+SHLRDiKaVZzEnoNyJDHnsXXrX
34
+ MvF98+bTUHC9xcklH7RCO5uqUOq7cxIcMjzx3cpR6+AW6zXYQBjWfNB9KfaAstZy
35
+ cpurTQHNJfL/ah+9dYbgDXdG5HAAjRMAsWSvERw95YdN9XzQZCdUk5wUs+A6cNtO
36
+ AZZUMTVYNx8JqUeemxlXBRjsD/s=
37
+ -----END CERTIFICATE-----
38
+ date: 2025-08-28 00:00:00.000000000 Z
12
39
  dependencies:
13
40
  - !ruby/object:Gem::Dependency
14
41
  name: jekyll
@@ -84,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
84
111
  - !ruby/object:Gem::Version
85
112
  version: '0'
86
113
  requirements: []
87
- rubygems_version: 3.3.15
114
+ rubygems_version: 3.3.27
88
115
  signing_key:
89
116
  specification_version: 4
90
117
  summary: Write changes to the repository
metadata.gz.sig ADDED
Binary file