aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/ocda_functions.org
diff options
context:
space:
mode:
authorRalph Amissah <ralph.amissah@gmail.com>2026-07-30 23:24:06 -0400
committerRalph Amissah <ralph.amissah@gmail.com>2026-07-31 14:48:09 -0400
commit569a22bdb0841f360af97683ded5006329a14b28 (patch)
tree5d8969d9c269792468219af492d068dfcb7ea720 /org/ocda_functions.org
parentdigest (sha256) for document root heading (title) (diff)
digests (sha256) a revisit
Diffstat (limited to 'org/ocda_functions.org')
-rw-r--r--org/ocda_functions.org76
1 files changed, 58 insertions, 18 deletions
diff --git a/org/ocda_functions.org b/org/ocda_functions.org
index 5970a06..70c688a 100644
--- a/org/ocda_functions.org
+++ b/org/ocda_functions.org
@@ -3399,33 +3399,73 @@ pure ObjGenericComposite obj_dom_set_collapsed_tags()(
****** return object digest
-#+NAME: ocdaFunc_obj_digest_return
-#+HEADER: :noweb yes
-#+BEGIN_SRC d
-// ↓ - object digest
-pure ubyte[32] obj_digest()(
- ObjGenericComposite obj,
-) {
- obj.metainfo.sha256 = obj.text.sha256Of;
- return obj.metainfo.sha256;
-}
-// ↑ - object digest
-#+END_SRC
+- body text digests
+- extract image digests
+ - text body digest
+ - image digest 1
+ - image digest 2
+ - you may want a "has_images" (do first)
-****** screen show/debug object digest
+- CONSIDER having text body separate from (foot|end)notes
+ - text body digest
+ - note digest 1
+ - note digest 2
+ - currently text body includes inline notes
+ - may not be worth it, but
+ - notes then could be altered independently of the text,
+ - and it gives a little more insight into document structure, which notes
+ belong to which objects
+ - but if going this route, some solution related to external links which
+ may change might be more significant, consider, i think for now keep as
+ is.
-#+NAME: ocdaFunc_obj_digest_debug
+#+NAME: ocdaFunc_obj_digest_return
#+HEADER: :noweb yes
#+BEGIN_SRC d
// ↓ - object digest
-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") {
- writeln(obj.metainfo.sha256.toHexString, " ", obj.metainfo.ocn, " ", obj.metainfo.is_a, " ", obj.metainfo.heading_lev_markup);
+ 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 {
- writeln(obj.metainfo.sha256.toHexString, " ", obj.metainfo.ocn, " ", obj.metainfo.is_a);
+ 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;
}