Created
August 29, 2023 10:00
-
-
Save jmahoney/1b8b76d9b78f1e58aea22811e12e3220 to your computer and use it in GitHub Desktop.
Find duplicated permalinks in a jekyll site
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "safe_yaml" | |
directory = ARGV[0] | |
if directory.nil? | |
$stderr.puts "Usage: bundle exec ruby everyone-hides.rb <directory>" | |
exit 1 | |
end | |
permalinks = [] | |
Dir.glob("#{directory}/**/*.{md,html}") do |file| | |
next if file =~ /_site/ | |
content = File.read(file) | |
frontmatter = SafeYAML.load(content, safe: true) | |
if frontmatter["permalink"] | |
permalinks << {permalink: frontmatter["permalink"], file: file} | |
end | |
end | |
exit if permalinks.group_by{|e| e[:permalink]}.select{|k, v| v.size > 1}.empty? | |
duplicates = permalinks.group_by{|e| e[:permalink]}.select{|k, v| v.size > 1}.each do |k, v| | |
puts "Permalink: #{k}" | |
v.each do |e| | |
puts " #{e[:file]}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment