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: ...@@ -29,6 +29,9 @@ plugins:
- jekyll-write-and-commit-changes - 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 ### Example
An ad-hoc plugin at `_plugins/change_something.rb` An ad-hoc plugin at `_plugins/change_something.rb`
......
# frozen_string_literal: true
Gem::Specification.new do |spec| Gem::Specification.new do |spec|
spec.name = 'jekyll-write-and-commit-changes' spec.name = 'jekyll-write-and-commit-changes'
spec.version = '0.1.2' spec.version = '0.2.3'
spec.authors = %w[f] spec.authors = %w[f]
spec.email = %w[f@sutty.nl] spec.email = %w[f@sutty.nl]
......
...@@ -8,7 +8,9 @@ module Jekyll ...@@ -8,7 +8,9 @@ module Jekyll
base.class_eval do base.class_eval do
# Writes changes to the file and adds it to git staged changes # Writes changes to the file and adds it to git staged changes
def save 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| file = File.open(path, File::RDWR | File::CREAT, 0o640) do |f|
f.flock(File::LOCK_EX) f.flock(File::LOCK_EX)
...@@ -22,11 +24,17 @@ module Jekyll ...@@ -22,11 +24,17 @@ module Jekyll
f.truncate(f.pos) f.truncate(f.pos)
end end
site.staged_files << relative_path if file.zero? site.staged_files << real_path if file.zero?
file.zero? file.zero?
end 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 # Prepares the data for dumping, by excluding some keys and
# transforming other Documents replaced by jekyll-linked-posts. # transforming other Documents replaced by jekyll-linked-posts.
# #
...@@ -38,13 +46,19 @@ module Jekyll ...@@ -38,13 +46,19 @@ module Jekyll
case value case value
when Jekyll::Document when Jekyll::Document
value.data['uuid'] 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 when Array
value.map do |v| value.map do |v|
v.is_a?(Jekyll::Document) ? v.data['uuid'] : v v.respond_to?(:data) ? v.data['uuid'] : v
end end
when Hash when Hash
value.transform_values do |v| value.transform_values do |v|
v.is_a?(Jekyll::Document) ? v.data['uuid'] : v v.respond_to?(:data) ? v.data['uuid'] : v
end end
else else
value value
......