Sha256: f470041e9d0b76b7ec892f397eccce5ba8535eff3714a67ac5e2750c1c856ab4

Contents?: true

Size: 1.22 KB

Versions: 2

Compression:

Stored size: 1.22 KB

Contents

module Jekyll
  module PreCommit
    module Checks
      class NoDuplicateTags < Check
        def check(staged, not_staged, site, args)
          raw = Hash.new
          normalized = Hash.new
          not_staged.each do |post|
            if post.data["tags"].size > 0
              post.data["tags"].each do |tag|
                if !raw[tag]
                  raw[tag] = post.relative_path
                end

                n = Jekyll::Utils.slugify(tag)
                if !normalized[n]
                  normalized[n] = Hash.new
                  normalized[n]["path"] = post.relative_path
                  normalized[n]["tag"] = tag
                end
              end
            end
          end

          staged.each do |post|
            if post.data["tags"].size > 0
              post.data["tags"].each do |tag|
                n = Jekyll::Utils.slugify(tag)

                if normalized[n] && !raw[tag]
                  @result[:ok] = false
                  @result[:message] += "The tag '#{tag}' appears to be duplicated and is listed as '#{normalized[n]["tag"]}' in #{normalized[n]["path"]}. "
                end
              end
            end
          end

          @result
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jekyll-pre-commit-0.3.0 lib/jekyll-pre-commit/checks/no_duplicate_tags.rb
jekyll-pre-commit-0.2.1 lib/jekyll-pre-commit/checks/no_duplicate_tags.rb