Skip to content

Instantly share code, notes, and snippets.

@jmahoney
Created August 29, 2023 10:00
Show Gist options
  • Save jmahoney/1b8b76d9b78f1e58aea22811e12e3220 to your computer and use it in GitHub Desktop.
Save jmahoney/1b8b76d9b78f1e58aea22811e12e3220 to your computer and use it in GitHub Desktop.
Find duplicated permalinks in a jekyll site
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