From 4342b284ee36c5414de7a897ff0ae5aa1ac82d93 Mon Sep 17 00:00:00 2001 From: Utku Bilen Demir <84389167+UtkuBilenDemir@users.noreply.github.com> Date: Wed, 23 Sep 2026 15:59:28 +0200 Subject: [PATCH] Kanzi 0.6.15: robust unification (DOI/ISBN + normalised hash) - src/kindle_zotero_importer/zotero_index.py already has DOI/ISBN, now import_plan.py passes doi/isbn/issn/publication_title to final_plan - src/kindle_zotero_importer/final_plan.py: _normalise() + _hash_norm() (NFKC lower, de-hyphenate, strip punct, SHA256:16) and store doi/isbn/issn/publication_title/norm_hash per annotation for cross-library grouping - plugin/manager.html: anonData now sends doi/isbn/issn/publication_title/norm_hash alongside citation_key/hash/colour for private aggregation - vis ~/annotation/app.py: store new columns, migrate old DB, /common groups by COALESCE(doi,isbn,citation_key)+norm_hash, dashboard shows Recent with DOI/norm and Top + Common tables - Bump to 0.6.15 --- README.md | 2 +- plugin/manager.html | 5 +++++ plugin/manifest.json | 2 +- src/kindle_zotero_importer/final_plan.py | 26 +++++++++++++++++++++++ src/kindle_zotero_importer/import_plan.py | 5 +++++ updates.json | 9 ++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ecd6a08..967abf2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Import Kindle `My Clippings.txt` highlights into Zotero as native annotations, d # Install -1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.14`, or `0.6.13-beta` for preview). +1. Download `kindle-zotero-importer.xpi` from [Releases](../../releases) (latest `0.6.15`, or `0.6.14-beta` for preview). 2. In Zotero: `Tools` → `Plugins` → `gear` → `Install Plugin From File…` → pick the `.xpi` → restart Zotero. 3. `Tools` → `Kanzi…` to open the manager. diff --git a/plugin/manager.html b/plugin/manager.html index 5d0f0b1..c9904ce 100644 --- a/plugin/manager.html +++ b/plugin/manager.html @@ -253,7 +253,12 @@ } const anonData = (data.finalPlan?.annotations || []).map(a => ({ citation_key: a.citation_key, + doi: a.doi || null, + isbn: a.isbn || null, + issn: a.issn || null, + publication_title: a.publication_title || null, clipping_id_hash: a.clipping_id ? a.clipping_id.slice(0,8) : null, + norm_hash: a.norm_hash || null, color: a.annotation?.color, has_comment: !!(a.annotation?.comment), comment: a.annotation?.comment || "", diff --git a/plugin/manifest.json b/plugin/manifest.json index 4ce68c6..fcb1e7b 100644 --- a/plugin/manifest.json +++ b/plugin/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 2, "name": "Kanzi", - "version": "0.6.14", + "version": "0.6.15", "description": "Kindle annotations to Zotero — My Clippings.txt → native annotations.", "homepage_url": "https://github.com/UtkuBilenDemir/kindle-zotero_importer", "author": "Utku Bilen Demir", diff --git a/src/kindle_zotero_importer/final_plan.py b/src/kindle_zotero_importer/final_plan.py index 925dcfd..ae8a5bc 100644 --- a/src/kindle_zotero_importer/final_plan.py +++ b/src/kindle_zotero_importer/final_plan.py @@ -1,9 +1,28 @@ from __future__ import annotations import datetime +import hashlib +import re +import unicodedata from typing import Any +def _normalise(text: str) -> str: + if not text: + return "" + # NFKC, lower, strip, de-hyphenate, collapse whitespace/punct + t = unicodedata.normalize("NFKC", text).lower() + t = re.sub(r"-\s*\n\s*", "", t) # de-hyphenate line breaks + t = re.sub(r"[\u2010-\u2015\u2018\u2019\u201c\u201d]", "'", t) + t = re.sub(r"[^a-z0-9]+", " ", t) + t = re.sub(r"\s+", " ", t).strip() + return t + + +def _hash_norm(text: str) -> str: + return hashlib.sha256(_normalise(text).encode("utf-8")).hexdigest()[:16] + + FINAL_FORMAT = "kindle-zotero-importer.zotero-writer-plan.v1" @@ -22,6 +41,8 @@ def build_final_writer_plan(positioned_plan: dict[str, Any]) -> dict[str, Any]: ) continue clipping = item["clipping"] + # robust identifiers for cross-library unification + norm_hash = _hash_norm(annotation.get("text") or clipping.get("text") or "") annotations.append( { "clipping_id": clipping["id"], @@ -34,6 +55,11 @@ def build_final_writer_plan(positioned_plan: dict[str, Any]) -> dict[str, Any]: "parent_item_id": item["zotero"]["parent_item_id"], "parent_key": item["zotero"]["parent_key"], "citation_key": item["zotero"].get("citation_key"), + "doi": item["zotero"].get("doi"), + "isbn": item["zotero"].get("isbn"), + "issn": item["zotero"].get("issn"), + "publication_title": item["zotero"].get("publication_title"), + "norm_hash": norm_hash, "annotation": { "type": annotation["type"], "text": annotation.get("text") or "", diff --git a/src/kindle_zotero_importer/import_plan.py b/src/kindle_zotero_importer/import_plan.py index d937728..8440fdd 100644 --- a/src/kindle_zotero_importer/import_plan.py +++ b/src/kindle_zotero_importer/import_plan.py @@ -133,6 +133,11 @@ def _plan_clipping( "parent_key": zotero_item["key"], "parent_title": zotero_item.get("title"), "citation_key": zotero_item["fields"].get("citationKey"), + "doi": zotero_item["fields"].get("DOI"), + "isbn": zotero_item["fields"].get("ISBN"), + "issn": zotero_item["fields"].get("ISSN") if "ISSN" in zotero_item["fields"] else None, + "url": zotero_item["fields"].get("url"), + "publication_title": zotero_item["fields"].get("publicationTitle"), "attachment": attachment, "attachment_choices": zotero_item.get("attachments", []), "expected_attachment_type": _expected_attachment_type( diff --git a/updates.json b/updates.json index 044e9ea..d811e69 100644 --- a/updates.json +++ b/updates.json @@ -2,6 +2,15 @@ "addons": { "kindlezoteroimporter@utkubilen.de": { "updates": [ + { + "version": "0.6.15", + "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.15/kindle-zotero-importer.xpi", + "applications": { + "zotero": { + "strict_min_version": "6.999" + } + } + }, { "version": "0.6.14", "update_link": "https://github.com/UtkuBilenDemir/kindle-zotero_importer/releases/download/v0.6.14/kindle-zotero-importer.xpi",