From 8701d11963179fd49f478560b902c776895bd1f4 Mon Sep 17 00:00:00 2001 From: b123400 Date: Sun, 31 Dec 2023 08:59:43 +0900 Subject: [PATCH] Add more log and copy images to another location --- src/model/text.rb | 2 +- src/plugin/text_info.rb | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/model/text.rb b/src/model/text.rb index 009cf817c..957319722 100644 --- a/src/model/text.rb +++ b/src/model/text.rb @@ -13,7 +13,7 @@ module Text class ImageLink attr_accessor :src, :style def attributes - { 'src' => @src, 'style' => @style } + { 'src' => @src, 'style' => @style, 'alt' => '' } end def clean! end diff --git a/src/plugin/text_info.rb b/src/plugin/text_info.rb index 61d178399..fe941116f 100644 --- a/src/plugin/text_info.rb +++ b/src/plugin/text_info.rb @@ -903,6 +903,7 @@ def match(node_set, iksnr) return name end def extract_image(html_file, name, type, lang, iksnrs) + LogFile.debug "Extracting image to #{name}" if html_file && File.exist?(html_file) resource_dir = (File.join(ODDB::IMAGE_DIR, type.to_s, lang.to_s)) FileUtils.mkdir_p(resource_dir) @@ -1274,7 +1275,7 @@ def parse_textinfo(meta_info) return end styles = res[1] - extract_image(html_name, meta_info.title, meta_info.type, meta_info.lang, meta_info.authNrs) + textinfo_pi_name = nil if type == :fi if is_same_html && !@options[:reparse] && reg && reg.fachinfo && text_info.descriptions.keys.index(meta_info.lang) LogFile.debug "parse_textinfo #{__LINE__} #{meta_info.iksnr} at #{nr_uptodate}: #{type} #{html_name} is_same_html #{html_name}" @@ -1292,8 +1293,18 @@ def parse_textinfo(meta_info) end textinfo_pi = @parser.parse_patinfo_html(html_name, @format, meta_info.title, styles) update_patinfo_lang(meta_info, { meta_info.lang => textinfo_pi } ) + textinfo_pi_name = textinfo_pi.name textinfo_pi = nil end + # Extract image to path generated from XML title, + # This should be the "correct" path + extract_image(html_name, meta_info.title, meta_info.type, meta_info.lang, meta_info.authNrs) + # However, ODBA is always buggy, sometimes it just doesn't like saving objects #231 + # There's case which the Html pointed the image to a wrong path, and we cannot update + # the HTML because ODBA's problem, so here we extract image to path generated from the wrong H1 title, + if !textinfo_pi_name.nil? + extract_image(html_name, textinfo_pi_name, meta_info.type, meta_info.lang, meta_info.authNrs) + end LogFile.debug "parse_textinfo #{__LINE__} at #{nr_uptodate}: #{type} textinfo #{textinfo.to_s.split("\n")[0..2]}" if self.respond_to?(:textinfo) if reg reg.odba_store