diff options
Diffstat (limited to 'src/sisudoc/ocda/meta/metadoc_from_src_functions.d')
| -rw-r--r-- | src/sisudoc/ocda/meta/metadoc_from_src_functions.d | 44 |
1 files changed, 42 insertions, 2 deletions
diff --git a/src/sisudoc/ocda/meta/metadoc_from_src_functions.d b/src/sisudoc/ocda/meta/metadoc_from_src_functions.d index f5c9bec..3bd9292 100644 --- a/src/sisudoc/ocda/meta/metadoc_from_src_functions.d +++ b/src/sisudoc/ocda/meta/metadoc_from_src_functions.d @@ -3184,10 +3184,50 @@ template docAbstractionFunctions() { } // ↑ - object tags // ↓ - object digest - pure ubyte[32] obj_digest()( + // pure + SHA_256_Hashes_ obj_digest(M)( ObjGenericComposite obj, + M manifested, ) { - obj.metainfo.sha256 = obj.text.sha256Of; + ubyte[32] safeComputeHash(H)(H file_with_path) @trusted { + auto file_read = File(file_with_path, "r"); + ubyte[32] file_sha256 = digest!SHA256(file_read.byChunk(4096 * 1024)); + return file_sha256; + } + obj.metainfo.sha256.text = obj.text.sha256Of; + string image_with_path; + string image_path = manifested.src.image_dir_path ~ "/"; + char[64] image_hash; + int n = 0; + if (obj.metainfo.is_a == "heading") { + obj.metainfo.sha256.summary ~= + obj.metainfo.sha256.text.toHexString ~ " " + ~ obj.metainfo.ocn.to!string ~ " " + ~ obj.metainfo.is_a ~ " " + ~ obj.metainfo.marked_up_level ~ "~ " + ~ obj.text; + // ~ image_summary; // heading assumed not to have image CONSIDER + } else { + if ((obj.text).match(rgx.inline_image)) { + foreach (m; (obj.text).matchAll(rgx.inline_image)) { + image_with_path = image_path ~ m["img"]; + ubyte[32] image_sha256 = safeComputeHash(image_with_path); + obj.metainfo.sha256.images = [ m["img"] : image_sha256 ]; + } + } + char[] image_summary; + if (obj.metainfo.sha256.images.length > 0) { + foreach (i,h; obj.metainfo.sha256.images) { + // writeln(h.toHexString.to!string, " - ", i); + image_summary ~= "\n" ~ h.toHexString.to!string ~ " - " ~ i; + } + } + obj.metainfo.sha256.summary ~= + obj.metainfo.sha256.text.toHexString + ~ " " ~ obj.metainfo.ocn.to!string ~ " " + ~ obj.metainfo.is_a + ~ image_summary; + } return obj.metainfo.sha256; } // ↑ - object digest |
