Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • sutty/jekyll/jekyll-write-and-commit-changes
1 result
Show changes
Commits on Source (6)
......@@ -29,6 +29,9 @@ plugins:
- jekyll-write-and-commit-changes
```
If you don't want a post to be saved, add `save: false` to its metadata.
It's useful on other plugins.
### Example
An ad-hoc plugin at `_plugins/change_something.rb`
......
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = 'jekyll-write-and-commit-changes'
spec.version = '0.1.2'
spec.version = '0.2.3'
spec.authors = %w[f]
spec.email = %w[f@sutty.nl]
......
......@@ -8,7 +8,9 @@ module Jekyll
base.class_eval do
# Writes changes to the file and adds it to git staged changes
def save
Jekyll.logger.debug "Writing #{relative_path}"
return unless data.fetch('save', true)
Jekyll.logger.debug 'Writing', path
file = File.open(path, File::RDWR | File::CREAT, 0o640) do |f|
f.flock(File::LOCK_EX)
......@@ -22,11 +24,17 @@ module Jekyll
f.truncate(f.pos)
end
site.staged_files << relative_path if file.zero?
site.staged_files << real_path if file.zero?
file.zero?
end
# Resolves the real path for the document
# @return [String]
def real_path
@real_path ||= Pathname.new(relative_path).realpath.relative_path_from(site.source).to_s
end
# Prepares the data for dumping, by excluding some keys and
# transforming other Documents replaced by jekyll-linked-posts.
#
......@@ -38,13 +46,19 @@ module Jekyll
case value
when Jekyll::Document
value.data['uuid']
when Jekyll::Convertible
value.data['uuid']
when Set
value.map do |v|
v.respond_to?(:data) ? v.data['uuid'] : v
end
when Array
value.map do |v|
v.is_a?(Jekyll::Document) ? v.data['uuid'] : v
v.respond_to?(:data) ? v.data['uuid'] : v
end
when Hash
value.transform_values do |v|
v.is_a?(Jekyll::Document) ? v.data['uuid'] : v
v.respond_to?(:data) ? v.data['uuid'] : v
end
else
value
......