2025-02-10 15:59:08 +01:00
|
|
|
;;; linkding.el --- Linkding Integration -*- lexical-binding: t -*-
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;; Integration with Linkding.
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
(require 'json)
|
|
|
|
(require 'plz)
|
2025-02-11 15:17:52 +01:00
|
|
|
(require 'shr)
|
2025-02-10 15:59:08 +01:00
|
|
|
|
|
|
|
(defcustom linkding-host ""
|
|
|
|
"Hostname of the Linkding instance."
|
|
|
|
:type '(string)
|
|
|
|
:group 'linkding)
|
|
|
|
|
|
|
|
(defcustom linkding-user ""
|
|
|
|
"Linkding user name."
|
|
|
|
:type '(string)
|
|
|
|
:group 'linkding)
|
|
|
|
|
|
|
|
(defun linkding--get-api-key ()
|
|
|
|
"Get Linkding API key from auth store."
|
|
|
|
(let ((result (auth-source-search :host linkding-host :user linkding-user)))
|
|
|
|
(if result
|
|
|
|
(funcall (plist-get (car result) :secret))
|
|
|
|
nil)))
|
|
|
|
|
|
|
|
(defun linkding--build-headers ()
|
|
|
|
"Build headers for Linkding Lab API request."
|
|
|
|
`(("Content-Type" . "application/json")
|
|
|
|
("Authorization" . ,(concat "Token " (linkding--get-api-key)))))
|
|
|
|
|
|
|
|
(defun linkding-add-bookmark (url)
|
|
|
|
"Add URL as bookmark to Linkding."
|
|
|
|
(interactive "sURL: ")
|
|
|
|
(plz 'post (concat "https://" linkding-host "/api/bookmarks/")
|
|
|
|
:headers (linkding--build-headers)
|
|
|
|
:body (json-encode `(("url" . ,url)
|
|
|
|
("title" . "")
|
|
|
|
("description" . "")
|
|
|
|
("notes" . "")
|
|
|
|
("is_archived" . false)
|
|
|
|
("unread" . false)
|
|
|
|
("shared" . false)
|
|
|
|
("tag_names" . [])))))
|
|
|
|
|
2025-02-11 15:17:52 +01:00
|
|
|
(defun linkding-add-bookmark-at-point ()
|
|
|
|
"Add URL at point as bookmark to Linkding."
|
|
|
|
(interactive)
|
|
|
|
(linkding-add-bookmark (shr-url-at-point nil)))
|
|
|
|
|
2025-02-10 15:59:08 +01:00
|
|
|
(provide 'linkding)
|
|
|
|
;;; linkding.el ends here
|