Browse Source

Move the script to here and fix the submodule

Aaron Mueller 6 years ago
parent
commit
058a0636fa
2 changed files with 35 additions and 1 deletions
  1. 1
    1
      .gitmodules
  2. 34
    0
      scripts/weak-link-checker.rb

+ 1
- 1
.gitmodules View File

@@ -1,3 +1,3 @@
1 1
 [submodule "wiki-data"]
2 2
 	path = wiki-data
3
-	url = https://github.com/CTHN/wiki-data
3
+	url = git@github.com:CTHN/wiki-data.git

+ 34
- 0
scripts/weak-link-checker.rb View File

@@ -0,0 +1,34 @@
1
+#!/usr/bin/env ruby
2
+
3
+# Simple script to check broken links in the wiki. This is a weak and simple
4
+# check to work with markdown, html and even php scripts. Keep in mind that
5
+# the script does not find linked pages through "meta-pages" like a php script
6
+# which links all files in the /user/ folder.
7
+#
8
+# Last change: 2014-06-27, Aaron Mueller <mail@aaron-mueller.de>
9
+
10
+
11
+blacklist = [
12
+  'mainpage',
13
+  'error_404'
14
+]
15
+
16
+Dir.chdir(File.join(File.dirname(__FILE__), '..', 'wiki-data'))
17
+
18
+files = Dir.glob('pages/**/*')
19
+    .delete_if {|file| Dir.exists?(file) }
20
+wiki_links = files
21
+    .map {|file| file[6..-1].split('.').first }
22
+    .delete_if {|file| blacklist.include?(file) }
23
+
24
+files.each do |file|
25
+  content = File.new(file).read
26
+  wiki_links.reject! do |link|
27
+    not content.scan(/#{link}/).empty?
28
+  end
29
+end
30
+
31
+wiki_links.each do |broken_link|
32
+  puts "Check linkage for '#{broken_link}'."
33
+end
34
+puts "#{wiki_links.size} in total."

Loading…
Cancel
Save