Class: VivlioStarter::CLI::Build::BacklinkDeduplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/build/backlink_deduplicator.rb

Overview

ページマッピングを使って HTML のバックリンク重複を排除する

Defined Under Namespace

Classes: Occurrence, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_mapping) ⇒ BacklinkDeduplicator

Returns a new instance of BacklinkDeduplicator.



30
31
32
33
34
35
36
37
# File 'lib/vivlio_starter/cli/build/backlink_deduplicator.rb', line 30

def initialize(page_mapping)
  @page_mapping = page_mapping
  @glossary_removed = 0
  @body_removed = 0
  @index_removed = 0
  @index_ranges = 0
  @files_modified = []
end

Instance Attribute Details

#index_rangesObject (readonly)

索引ページで範囲表記へ畳んだ箇所の数(R8・テストと進捗表示から見る)



40
41
42
# File 'lib/vivlio_starter/cli/build/backlink_deduplicator.rb', line 40

def index_ranges
  @index_ranges
end

Instance Method Details

#deduplicate!Result

重複排除を実行するメインメソッド

Returns:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/vivlio_starter/cli/build/backlink_deduplicator.rb', line 44

def deduplicate!
  # --- Phase 1: ページマッピングからルックアップテーブルを構築 ---
  anchor_to_page = build_anchor_to_page_lookup
  index_anchor_to_page = build_index_anchor_to_page_lookup

  if anchor_to_page.empty? && index_anchor_to_page.empty?
    Common.log_info('[backlink-dedup] ページマッピングが空です。スキップします')
    return build_result
  end

  # --- Phase 2: 用語集バックリンク重複排除 ---
  unless anchor_to_page.empty?
    Common.log_info("[backlink-dedup] #{anchor_to_page.size} 件の glossary anchor → page マッピングを構築しました")
    deduplicate_glossary_backlinks!(anchor_to_page)
    deduplicate_body_glossary_links!(anchor_to_page)
  end

  # --- Phase 3: 索引ページの重複排除 ---
  unless index_anchor_to_page.empty?
    Common.log_info("[backlink-dedup] #{index_anchor_to_page.size} 件の index anchor → page マッピングを構築しました")
    deduplicate_index_page_links!(index_anchor_to_page)
    Common.log_info("[backlink-dedup] 索引の連続ページを #{@index_ranges} 箇所で範囲表記にまとめました") if @index_ranges.positive?
  end

  build_result
end