(concord-images-encode-url-as-id): Add optional argument `base'.
authorMORIOKA Tomohiko <tomo.git@chise.org>
Sun, 7 Apr 2019 11:43:21 +0000 (20:43 +0900)
committerMORIOKA Tomohiko <tomo.git@chise.org>
Wed, 5 Feb 2020 07:49:22 +0000 (16:49 +0900)
(concord-images-add-url): Likewise.
(concord-images-add-iiif): Likewise.

concord-images.el

index e51775d..7597b07 100644 (file)
@@ -1,8 +1,15 @@
 (concord-assign-genre 'image-resource "/usr/local/var/photo/db")
 
-(defun concord-images-encode-url-as-id (url)
+(defun concord-images-encode-url-as-id (url &optional base)
   (let (ret)
     (cond
+     ((and base
+          (string-match (concat "^" (regexp-quote base)) url))
+      (setq ret (substring url (match-end 0)))
+      (if (string-match "\\.[a-zA-Z0-9]+$" ret)
+         (substring ret 0 (match-beginning 0))
+       ret)
+      )
      ((string-match "^http://\\(hng\\|image\\)\\.\\(chise\\.org\\|kanji\\.zinbun\\.kyoto-u\\.ac\\.jp\\)/images/iiif/" url)
       (setq ret (substring url (match-end 0)))
       (if (string-match "\\.[a-zA-Z0-9]+$" ret)
      (t
       url))))
 
-(defun concord-images-add-url (url &optional iiif iip)
+(defun concord-images-add-url (url &optional iiif iip base)
   (let (img-id img-cobj)
     (unless (setq img-cobj (concord-decode-object '=location url
                                                  'image-resource))
-      (setq img-id (intern (concord-images-encode-url-as-id url)))
+      (setq img-id (intern (concord-images-encode-url-as-id url base)))
       (setq img-cobj (concord-make-object 'image-resource img-id))
       (concord-object-put img-cobj '=location url)
       (when iiif
       )
     img-cobj))
 
-(defun concord-images-add-iiif (url)
+(defun concord-images-add-iiif (url &optional base)
   (let (img-id img-cobj)
     (unless (setq img-cobj (concord-decode-object '=location url
                                                  'image-resource))
-      (setq img-id (intern (concord-images-encode-url-as-id url)))
+      (setq img-id (intern (concord-images-encode-url-as-id url base)))
       (setq img-cobj (concord-make-object 'image-resource img-id))
       (concord-object-put img-cobj '=location@iiif url))
     img-cobj))