|
3 | 3 |
|
4 | 4 | require 'json'
|
5 | 5 | require 'yaml'
|
| 6 | +require 'time' |
6 | 7 |
|
7 | 8 | class CustomChecks < ::HTMLProofer::Check
|
8 | 9 | BASE_PATH = '_site'
|
9 | 10 |
|
10 | 11 | def run
|
11 | 12 | filename = @runner.current_filename
|
12 | 13 | puts "\tchecking ... " + filename.delete_prefix('_site')
|
| 14 | + |
13 | 15 | check_directory_structure(filename) if filename.end_with?('.html')
|
| 16 | + check_time_table_overlaps if filename.end_with?('time-table/index.html') |
14 | 17 | end
|
15 | 18 |
|
16 | 19 | # Check directory structure to ensure all pages are generated as index.html
|
@@ -45,4 +48,48 @@ def is_redirect_file?(filename)
|
45 | 48 | content.include?("<meta http-equiv='refresh'") ||
|
46 | 49 | content.include?('<meta http-equiv=refresh')
|
47 | 50 | end
|
| 51 | + |
| 52 | + # Check time table overlaps using Range#cover? |
| 53 | + def check_time_table_overlaps |
| 54 | + data = YAML.load_file('_data/time_table.yml') |
| 55 | + |
| 56 | + # 会議室ごとにイベントをグループ化 |
| 57 | + room_events = Hash.new { |h, k| h[k] = [] } |
| 58 | + |
| 59 | + data['events'].each do |event| |
| 60 | + start_time = Time.parse(event['start']) |
| 61 | + end_time = Time.parse(event['end']) |
| 62 | + |
| 63 | + room_events[event['room']] << { |
| 64 | + title: event['title'], |
| 65 | + start_str: event['start'], |
| 66 | + end_str: event['end'], |
| 67 | + range: (start_time...end_time) # 終了時間を含まない範囲 |
| 68 | + } |
| 69 | + end |
| 70 | + |
| 71 | + # 各会議室で重複チェック |
| 72 | + room_events.each do |room, events| |
| 73 | + # 開始時間でソート |
| 74 | + sorted = events.sort_by { |e| e[:range].begin } |
| 75 | + |
| 76 | + # 隣接するイベント間で重複をチェック |
| 77 | + sorted.each_cons(2) do |a, b| |
| 78 | + # Range#cover? で重複検出 |
| 79 | + if a[:range].cover?(b[:range].begin) |
| 80 | + add_failure( |
| 81 | + <<~ERROR_MESSAGE |
| 82 | + タイムテーブルに重複があります [#{room}]: |
| 83 | + \s #{a[:start_str]}-#{a[:end_str]}: #{a[:title]} |
| 84 | + \s #{b[:start_str]}-#{b[:end_str]}: #{b[:title]} |
| 85 | + ERROR_MESSAGE |
| 86 | + ) |
| 87 | + end |
| 88 | + end |
| 89 | + end |
| 90 | + |
| 91 | + puts "\t✓ タイムテーブル重複検知完了" |
| 92 | + rescue => e |
| 93 | + add_failure("タイムテーブル検証エラー: #{e.message}") |
| 94 | + end |
48 | 95 | end
|
0 commit comments