Module: VivlioStarter::CLI::EntriesCommands
- Defined in:
- lib/vivlio_starter/cli/entries.rb
Overview
================================================================
Module: entries メタデータ抽出ヘルパ
提供機能:
- build_entry: HTML から entries 用の { path:, title: } を組み立てる
- extract_html_title: HTML の <title> を抽出する
利用者:
- Build::VivliostyleConfigWriter(workspace の用途別 entries 生成)
- Build::EpubBuilder(EPUB 用 entries 生成)
かつての vs entries(ルート entries.js の手動生成コマンド)は
P4 のワークスペース分離で実体を失ったため撤去した
(vivlioverso-manual-flow-removal-spec.md)。
Class Method Summary collapse
-
.build_entry(html_file) ⇒ Hash
HTML ファイルから entries 用エントリを組み立てる。 タイトルは
タグ優先、無ければファイル名の番号を除いた部分。. - .extract_html_title(path) ⇒ Object
Class Method Details
.build_entry(html_file) ⇒ Hash
HTML ファイルから entries 用エントリを組み立てる。 タイトルは
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/vivlio_starter/cli/entries.rb', line 29 def build_entry(html_file) base_name = File.basename(html_file, '.html') title = base_name html_title = extract_html_title(html_file) if html_title && !html_title.empty? title = html_title elsif html_title.to_s.empty? && (base_name =~ /^\d+-(.+)$/) title = ::Regexp.last_match(1) end # パスを相対パス形式に正規化(./を接頭辞として付与) normalized_path = html_file.start_with?('./') ? html_file : "./#{html_file}" { path: normalized_path, title: title } end |
.extract_html_title(path) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/vivlio_starter/cli/entries.rb', line 45 def extract_html_title(path) return unless File.exist?(path) content = File.read(path) ::Regexp.last_match(1).strip if content =~ %r{<title>(.+?)</title>} rescue StandardError => e # タイトル抽出失敗時はフォールバック名が使われるため、原因をデバッグログに残す Common.log_debug("[entries] #{path} のタイトル抽出に失敗: #{e.class}: #{e.}") nil end |