Changelog: remove a "XXX" in the 3.9.1 entry.
[tails.git] / bin / sanity-check-website
blob0e725d6741a002361d2bbcf598fd39855586587e
1 #!/usr/bin/env ruby
2 require 'date'
4 require 'test/unit'
5 Test::Unit.run = true
6 include Test::Unit::Assertions
8 # Force UTF-8. Ruby will default to the system locale, and if it is
9 # non-UTF-8, String-methods will fail when operating on non-ASCII
10 # strings.
11 Encoding.default_external = Encoding::UTF_8
12 Encoding.default_internal = Encoding::UTF_8
14 GIT_DIR=`git rev-parse --show-toplevel`
15 assert_equal(
16 0, $?.exitstatus,
17 "Failed to find Tails' Git root; this command must be run " +
18 "inside Tails Git repo"
21 def rfc2822_date?(date)
22 !!DateTime.rfc2822(date)
23 rescue ArgumentError
24 false
25 end
27 def page_meta_date_is_ok?(path)
28 meta_date_post_re = /^\[\[!meta\s+date="(?<date>.*)"\]\]$/
29 success = true
30 content_lines = File.new(path).read.split("\n")
31 matches = content_lines.grep(meta_date_post_re)
32 if matches.size != 1
33 STDERR.puts "#{path}: has #{matches.size} well-formed 'meta date' " +
34 "directives (must be 1)"
35 success = false
36 else
37 meta_date_line = matches.first
38 m = meta_date_post_re.match(meta_date_line)
39 meta_date = m['date']
40 if not(rfc2822_date?(meta_date))
41 STDERR.puts "#{path}: 'meta date' directive contains non-rfc2822 " +
42 "date: #{meta_date}"
43 success = false
44 end
45 end
46 return success
47 end
49 def po_file_meta_date_is_ok?(path)
50 meta_date_po_re_str = '\[\[!meta\s+date=\\\"(?<date>.*)\\\"\]\]\\\n'
51 success = true
52 content_lines = File.new(path).read.split("\n")
53 matches = content_lines.grep(Regexp.new("^msgid \"#{meta_date_po_re_str}\"$"))
54 if matches.size != 1
55 STDERR.puts "#{path}: has #{matches.size} 'meta date' msgid:s (must be 1)"
56 success = false
57 else
58 msgid = matches.first
59 msgid_index = content_lines.find_index(msgid)
60 msgstr_index = msgid_index + 1
61 msgstr_line = content_lines[msgstr_index]
62 m = Regexp.new("^msgstr \"(?:#{meta_date_po_re_str})?\"$").match(msgstr_line)
63 if m.nil?
64 STDERR.puts "#{path}: the 'meta date' msgid is not followed by a msgstr"
65 success = false
66 elsif m['date']
67 meta_date = m['date']
68 if not(rfc2822_date?(meta_date))
69 STDERR.puts "#{path}: 'meta date' msgstr contains non-rfc2822 " +
70 "date: #{meta_date}"
71 success = false
72 end
73 end
74 end
75 return success
76 end
78 # Main
80 success = true
82 meta_date_sorted_pages =
83 Dir.glob('wiki/src/{news,security,security/audits}/*.{mdwn,html}') - [
84 'wiki/src/security/audits.mdwn',
87 meta_date_sorted_pages.each do |post_path|
88 success = false unless page_meta_date_is_ok?(post_path)
89 Dir.glob(post_path.sub(/.(html|mdwn)$/, '') + '.*.po').each do |po_path|
90 success = false unless po_file_meta_date_is_ok?(po_path)
91 end
92 end
94 exit(success)