Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 0 additions & 27 deletions _pages/time-table.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,31 +119,4 @@ <h2 class="text-4xl text-center mb-8">
</tbody>
</table>
</div>

<script>
// 重複検知(後勝ち)
(function () {
const data = {
slot: {{ slot | jsonify }},
dayStart: {{ day_start_min | jsonify }},
dayEnd: {{ day_end_min | jsonify }},
rooms: {{ rooms | jsonify }},
events: {{ tt.events | jsonify }}
};
const map = new Map();
data.rooms.forEach(r => map.set(r, []));
const toMin = t => { const [h,m]=String(t).split(':').map(Number); return h*60+m; };
for (const ev of data.events) (map.get(ev.room)||map.set(ev.room,[]).get(ev.room)).push(ev);
for (const [room, list] of map) {
list.sort((a,b)=>toMin(a.start)-toMin(b.start));
for (let i=0;i<list.length-1;i++){
const a=list[i], b=list[i+1];
const as=Math.max(toMin(a.start), data.dayStart);
const ae=Math.min(toMin(a.end), data.dayEnd);
const bs=Math.max(toMin(b.start), data.dayStart);
if (ae>bs) console.warn(`[time-table] Overlap in "${room}":`, a, b, '→ later wins');
}
}
})();
</script>
</section>
47 changes: 47 additions & 0 deletions _tests/custom_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@

require 'json'
require 'yaml'
require 'time'

class CustomChecks < ::HTMLProofer::Check
BASE_PATH = '_site'

def run
filename = @runner.current_filename
puts "\tchecking ... " + filename.delete_prefix('_site')

check_directory_structure(filename) if filename.end_with?('.html')
check_time_table_overlaps if filename.end_with?('time-table/index.html')
end

# Check directory structure to ensure all pages are generated as index.html
Expand Down Expand Up @@ -45,4 +48,48 @@ def is_redirect_file?(filename)
content.include?("<meta http-equiv='refresh'") ||
content.include?('<meta http-equiv=refresh')
end

# Check time table overlaps using Range#cover?
def check_time_table_overlaps
data = YAML.load_file('_data/time_table.yml')

# 会議室ごとにイベントをグループ化
room_events = Hash.new { |h, k| h[k] = [] }

data['events'].each do |event|
start_time = Time.parse(event['start'])
end_time = Time.parse(event['end'])

room_events[event['room']] << {
title: event['title'],
start_str: event['start'],
end_str: event['end'],
range: (start_time...end_time) # 終了時間を含まない範囲
}
end

# 各会議室で重複チェック
room_events.each do |room, events|
# 開始時間でソート
sorted = events.sort_by { |e| e[:range].begin }

# 隣接するイベント間で重複をチェック
sorted.each_cons(2) do |a, b|
# Range#cover? で重複検出
if a[:range].cover?(b[:range].begin)
add_failure(
<<~ERROR_MESSAGE
タイムテーブルに重複があります [#{room}]:
\s #{a[:start_str]}-#{a[:end_str]}: #{a[:title]}
\s #{b[:start_str]}-#{b[:end_str]}: #{b[:title]}
ERROR_MESSAGE
)
end
end
end

puts "\t✓ タイムテーブル重複検知完了"
rescue => e
add_failure("タイムテーブル検証エラー: #{e.message}")
end
end