~brettgilio/org-webring

b2d451d0e8b9e41e5425bae3c66d84244391566e — Brett Gilio 15 days ago d48dcc3
Check for duplicates in `org-webring-urls`

* Bump version to 1.7.1
* Define function, `org-webring--detect-duplicates' which uses a
hashtable to parse a given list, and check the elements for
duplicates.
* Wrap org-webring-generate-webring in conditional, executing only
when `org-webring--detect-duplicates' returns NIL.
3 files changed, 50 insertions(+), 30 deletions(-)

M README.md
M README.org
M org-webring.el
M README.md => README.md +2 -1
@@ 135,7 135,8 @@ set for the header.

### **Function**: org-webring-generate-webring

Generate the entire webring and return it as HTML.
When `org-webring--detect-duplicates` passes, generate the
entire webring and return it as HTML.


### **Function**: org-webring-copy-css *&optional target-dir*

M README.org => README.org +2 -1
@@ 94,7 94,8 @@ set for the header.
- Default Value: ~t~

*** *Function*: org-webring-generate-webring
Generate the entire webring and return it as HTML.
When ~org-webring--detect-duplicates~ passes, generate the
entire webring and return it as HTML.

*** *Function*: org-webring-copy-css /&optional target-dir/
Interactive function which prompts for a location to copy

M org-webring.el => org-webring.el +46 -28
@@ 12,7 12,7 @@
;; Co-author: Amin Bandali <bandali@gnu.org>
;; Co-author: Ivan Sokolov <ivan-p-sokolov@ya.ru>

;; Version: 1.7
;; Version: 1.7.1

;; Homepage: https://sr.ht/~brettgilio/org-webring
;; Repository: https://git.sr.ht/~brettgilio/org-webring


@@ 80,7 80,7 @@
  "Used to track the originating directory of asset files.")

(defconst org-webring-version
  "1.7"
  "1.7.1"
  "The current version of org-webring.")

(defcustom org-webring-items-total 3


@@ 266,6 266,21 @@ was introduced in Emacs 27) isn't available."
	 (org-webring--feed-text-prop item 'updated))
     atom-p)))

(defun org-webring--detect-duplicates (&optional test)
  "Check `org-webring-urls' for the existence of duplicate
entries. Return ERROR when value is non-NIL."
  (let ((ht (make-hash-table
	     :test (or test #'equal))) ret)
    (dolist (x org-webring-urls)
      (incf (gethash x ht 0)))
    (maphash (lambda (key value)
               (when (> value 1)
		 (concat
		  (error "`org-webring-urls' contains a duplicate entry: %s"
			 (push key ret)))))
             ht)
    ret))

(defun org-webring--article-instance (item)
  "Generate the structure of a feed article from a given ITEM."
  (let ((desc-sanitized


@@ 299,32 314,35 @@ was introduced in Emacs 27) isn't available."
					    "GMT"))))))

(defun org-webring-generate-webring ()
  "Generate the entire webring and return it as HTML."
  (let* ((items (mapcan #'org-webring--get-items-from-url org-webring-urls))
         (sorted-items (cl-sort items #'time-less-p :key #'org-webring--pub-time))
         (most-recent (reverse (last sorted-items org-webring-items-total)))
         (articles (mapcar #'org-webring--article-instance most-recent)))
    (xmlgen
     `(section :class "org-webring"
	       ,(when org-webring-display-header
		  `(h4 ,(print org-webring-header)))
	       (section :class "org-webring-articles" ,@articles)
	       (p :class "org-webring-attribution"
		  ,@(when org-webring-display-generation-time
		      (list
		       `(span :class "org-webring-timestamp"
			      ,(format-time-string
				org-webring-timestamp-generate-format))
		       `(br)))
		  ,@(when org-webring-display-attribution
		      (list
		       (print "Generated with ")
		       `(a :href ,org-webring-attribution-link
			   :target "_blank"
			   ,org-webring-attribution-name)
		       (when org-webring-display-version
			 (print (concat " -- v"
					org-webring-version))))))))))
  "When `org-webring--detect-duplicates' passes, generate the
entire webring and return it as HTML."
  (unless (org-webring--detect-duplicates)
    (let* ((items (mapcan #'org-webring--get-items-from-url org-webring-urls))
           (sorted-items (cl-sort items
				  #'time-less-p :key #'org-webring--pub-time))
           (most-recent (reverse (last sorted-items org-webring-items-total)))
           (articles (mapcar #'org-webring--article-instance most-recent)))
      (xmlgen
       `(section :class "org-webring"
		 ,(when org-webring-display-header
		    `(h4 ,(print org-webring-header)))
		 (section :class "org-webring-articles" ,@articles)
		 (p :class "org-webring-attribution"
		    ,@(when org-webring-display-generation-time
			(list
			 `(span :class "org-webring-timestamp"
				,(format-time-string
				  org-webring-timestamp-generate-format))
			 `(br)))
		    ,@(when org-webring-display-attribution
			(list
			 (print "Generated with ")
			 `(a :href ,org-webring-attribution-link
			     :target "_blank"
			     ,org-webring-attribution-name)
			 (when org-webring-display-version
			   (print (concat " -- v"
					  org-webring-version)))))))))))

(defun org-webring-copy-css (&optional target-dir)
  "Interactive function which prompts for a location to