Module: VivlioStarter::CLI::Build::PartTitleGenerator
- Defined in:
- lib/vivlio_starter/cli/build/part_title_generator.rb
Overview
中扉(Part Title Page)の生成モジュール
catalog.yml の部タイトルから _partN.md を .cache/vs/ に生成し、 VFM 変換で _partN.html をプロジェクトルートに出力する。 中扉は右ページ(奇数ページ)に部タイトルを印刷し、裏面は白紙となる。
Class Method Summary collapse
-
.convert_to_html!(basename) ⇒ Object
中扉 Markdown を VFM 変換して HTML を生成する SectionBuilder の既存パイプライン(pre_process → convert → post_process)を再利用.
-
.generate_all! ⇒ Array<String>
中扉ページを一括生成する catalog.yml に部タイトルがなければ何もしない.
-
.insert_part_titles_into(chapter_htmls, base_dir = '.') ⇒ Array<String>
部タイトル情報と章 HTML リストから、中扉を適切な位置に挿入した HTML リストを返す 各部の先頭章の直前に _partN.html を挿入する.
-
.write_part_markdown!(path, title) ⇒ Object
中扉の Markdown を .cache/vs/ に書き出す frontmatter の class: part-title で CSS を適用し、title で PDF アウトラインに反映する.
Class Method Details
.convert_to_html!(basename) ⇒ Object
中扉 Markdown を VFM 変換して HTML を生成する SectionBuilder の既存パイプライン(pre_process → convert → post_process)を再利用
84 85 86 87 88 |
# File 'lib/vivlio_starter/cli/build/part_title_generator.rb', line 84 def convert_to_html!(basename) PreProcessCommands.execute_pre_process({}, [basename]) ConvertCommands.execute_convert({}, [basename]) PostProcessCommands.execute_post_process({}, [basename]) end |
.generate_all! ⇒ Array<String>
中扉ページを一括生成する catalog.yml に部タイトルがなければ何もしない
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vivlio_starter/cli/build/part_title_generator.rb', line 36 def generate_all! parts = CatalogLoader.load_part_titles if parts.empty? Common.log_info('[PartTitle] 部タイトルが定義されていません。中扉生成をスキップします。') return [] end Common.ensure_cache_dir! generated = [] parts.each do |part| basename = "_part#{part[:number]}" md_path = File.join(Common::CACHE_DIR, "#{basename}.md") # --- Phase: Markdown 生成 --- write_part_markdown!(md_path, part[:title]) # --- Phase: HTML 変換 --- convert_to_html!(basename) generated << basename end Common.log_success("[PartTitle] 中扉を #{generated.size} 件生成しました: #{generated.join(', ')}") generated end |
.insert_part_titles_into(chapter_htmls, base_dir = '.') ⇒ Array<String>
部タイトル情報と章 HTML リストから、中扉を適切な位置に挿入した HTML リストを返す 各部の先頭章の直前に _partN.html を挿入する
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/vivlio_starter/cli/build/part_title_generator.rb', line 95 def insert_part_titles_into(chapter_htmls, base_dir = '.') parts = CatalogLoader.load_part_titles return chapter_htmls if parts.empty? # 各部の先頭章番号 → 中扉 HTML のマッピングを構築 insertion_map = {} parts.each do |part| next unless part[:first_chapter] part_html = File.join(base_dir, "_part#{part[:number]}.html") next unless File.exist?(part_html) # 先頭章番号をゼロ埋め2桁にして、対応する HTML ファイル名のプレフィックスを生成 prefix = format('%02d-', part[:first_chapter]) insertion_map[prefix] = part_html end return chapter_htmls if insertion_map.empty? # 章 HTML リストを走査し、各部の先頭章の直前に中扉を挿入 result = [] inserted = Set.new chapter_htmls.each do |html_path| bn = File.basename(html_path) insertion_map.each do |prefix, part_html| if bn.start_with?(prefix) && !inserted.include?(part_html) result << part_html inserted << part_html end end result << html_path end result end |
.write_part_markdown!(path, title) ⇒ Object
中扉の Markdown を .cache/vs/ に書き出す frontmatter の class: part-title で CSS を適用し、title で PDF アウトラインに反映する
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vivlio_starter/cli/build/part_title_generator.rb', line 67 def write_part_markdown!(path, title) content = <<~MD --- class: part-title title: #{title} --- # #{title} MD FileUtils.mkdir_p(File.dirname(path)) File.write(path, content, encoding: 'utf-8') end |