forked from jondot/awesome-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dedup.rb
35 lines (28 loc) · 739 Bytes
/
dedup.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require 'rexml/document'
require 'open-uri'
require 'kramdown'
BASE_URI = ENV['BASE_URI'] || 'https://github.com/jondot/awesome-react-native'
html_readme = "<html>#{Kramdown::Document.new(open('README.md').read).to_html}</html>"
readme_doctree = REXML::Document.new(html_readme)
links = REXML::XPath.match(readme_doctree, '//a')
puts "Deduping #{links.size} links..."
map = {}
dups = []
links.each do |link|
href = link.attribute('href').to_s
uri = URI.join(BASE_URI, href)
if map[uri]
dups << href
end
map[uri] = href
end
unless dups.empty?
puts "\nDuplicate links:"
dups.each do |link|
puts "- #{link}"
puts `grep -nr '#{link}' README.md`
end
puts "\nDone with errors."
exit(1)
end
puts "\nDone."