Module: VivlioStarter::CLI::IndexCommands

Defined in:
lib/vivlio_starter/cli/index.rb,
lib/vivlio_starter/cli/index/term_line.rb,
lib/vivlio_starter/cli/index/term_spread.rb,
lib/vivlio_starter/cli/index/term_pattern.rb,
lib/vivlio_starter/cli/index/term_ranking.rb,
lib/vivlio_starter/cli/index/index_library.rb,
lib/vivlio_starter/cli/index/yomi_inferrer.rb,
lib/vivlio_starter/cli/index/main_reference.rb,
lib/vivlio_starter/cli/index/scoring_engine.rb,
lib/vivlio_starter/cli/index/yomi_overrides.rb,
lib/vivlio_starter/cli/index/heading_outline.rb,
lib/vivlio_starter/cli/index/hierarchical_index.rb,
lib/vivlio_starter/cli/index/code_block_stripper.rb,
lib/vivlio_starter/cli/index/index_match_scanner.rb,
lib/vivlio_starter/cli/index/index_plan_reporter.rb,
lib/vivlio_starter/cli/index/index_size_estimator.rb,
lib/vivlio_starter/cli/index/unified_page_builder.rb,
lib/vivlio_starter/cli/index/main_reference_suggester.rb,
lib/vivlio_starter/cli/index/index_candidate_extractor.rb

Overview

================================================================

Module: IndexCommands

索引機能のヘルパーメソッドを提供 CLI コマンド本体は samovar/index_command.rb で定義

Defined Under Namespace

Modules: CodeBlockStripper, TermPattern, YomiOverrides Classes: HeadingOutline, HierarchicalIndex, IndexCandidateExtractor, IndexLibrary, IndexMatchScanner, IndexPlanReporter, IndexSizeEstimator, MainReference, MainReferenceSuggester, ScoringEngine, TermLine, TermRanking, TermSpread, UnifiedPageBuilder, YomiInferrer

Constant Summary collapse

INDEX_TERMS_MISSING_MESSAGE =
<<~MSG
  索引語辞書(config/index_glossary_terms.yml)に語がありません
  🟡  原稿に [用語|読み] という書き方で手動登録した語のみが索引に載ります
  🟡  自動索引機能を有効にするには: vs index:auto -> vs index:apply
MSG

Class Method Summary collapse

Class Method Details

.add_post_build_message(message) ⇒ Object



40
41
42
43
# File 'lib/vivlio_starter/cli/index/index_match_scanner.rb', line 40

def self.add_post_build_message(message)
  @post_build_messages ||= []
  @post_build_messages << message unless @post_build_messages.include?(message)
end

.emit_index_message(message, use_log_warn: true) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/vivlio_starter/cli/index/index_match_scanner.rb', line 55

def self.emit_index_message(message, use_log_warn: true)
  message.each_line do |line|
    text = line.rstrip
    next if text.empty?

    if use_log_warn
      Common.log_warn(text.sub(/\A🟡\s*/, ''))
    else
      Common.log_always(text)
    end
  end
end

.flush_post_build_messagesObject



45
46
47
48
49
50
51
52
53
# File 'lib/vivlio_starter/cli/index/index_match_scanner.rb', line 45

def self.flush_post_build_messages
  return if @post_build_messages.nil? || @post_build_messages.empty?

  @post_build_messages.each do |message|
    emit_index_message(message, use_log_warn: false)
  end

  @post_build_messages.clear
end

.index_enabled?Boolean

索引・用語集機能が有効かどうか(実体は Common。前処理も同じ述語を見る)

Returns:

  • (Boolean)


80
# File 'lib/vivlio_starter/cli/index.rb', line 80

def index_enabled? = Common.index_enabled?

.process_index_for_build!(chapters) ⇒ Object

ビルドパイプラインから呼び出される索引・用語集処理

Parameters:

  • chapters (Array<String>)

    対象章のリスト



46
47
48
49
50
51
52
# File 'lib/vivlio_starter/cli/index.rb', line 46

def process_index_for_build!(chapters)
  return unless index_enabled?

  require_relative 'index/unified_index_manager'
  manager = UnifiedIndexManager.new
  manager.build_index!(chapters)
end

.resolve_chapters(tokens) ⇒ Object

対象章を解決

Parameters:

  • tokens (Array<String>)

    対象章トークン(省略時は全章)



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/vivlio_starter/cli/index.rb', line 84

def resolve_chapters(tokens)
  resolver = TokenResolver::Resolver.new
  entries = resolver.resolve(tokens)

  if entries.any?
    basenames = entries.select(&:valid?).map(&:basename)
    Common.log_info("引数から対象章を特定しました: #{basenames.join(', ')}")
    basenames
  else
    begin
      require_relative 'build/catalog_loader'
      chapters = Build::CatalogLoader.load_existing_basenames
      Common.log_info("catalog.yml から対象章を特定しました: #{chapters.size}")
      chapters
    rescue StandardError => e
      Common.log_warn("catalog.yml の読み込みに失敗したため、全 Markdown ファイルを対象にします: #{e.message}")
      chapters = Dir.glob('*.md').map { |f| File.basename(f, '.md') }.sort
      Common.log_info("カレントディレクトリの全ファイルを対象にします: #{chapters.size}")
      chapters
    end
  end
end

.tag_chapters_for_build!(chapters) ⇒ Object

章ごとの索引タグ付けだけを行う(索引ページ・用語集ページは作らない)。

なぜ分けるのか(build-mode-parity-spec.md §4):

索引処理は 2 つの性質を併せ持つ。**章ごとのタグ付け**は 1 章だけで
答えが出るが、**索引ページ・ページ番号・主要参照**は全章そろわないと
決まらない。後者を理由に前者まで単章ビルドから外していたため、
「単章では素のテキスト、全章では索引語」という食い違いが生まれ、
前処理側に埋め合わせ(strip_index_markup!)を置くことになっていた。

タグ付けだけなら章を絞っても正しく動く。全書籍を単位とする警告
(用語集語がビルド対象章に出現しません 等)は呼ばないので、章を絞った
ときの誤検知も起きない——それが full_catalog_scope? ガードの目的だった。

単章と全章で変わらないもの: タグの有無・クラス・data-yomi 単章では正しく出せないもの: 主要参照(他章の出現を知る必要がある)。 ただし index_data の中だけで完結し、出力される要素には現れない。

Parameters:

  • chapters (Array<String>)

    対象章の basename



72
73
74
75
76
77
# File 'lib/vivlio_starter/cli/index.rb', line 72

def tag_chapters_for_build!(chapters)
  return unless index_enabled?

  require_relative 'index/index_match_scanner'
  IndexMatchScanner.new(defer_warnings: true).scan_all_chapters!(chapters, read_only: false)
end