[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/kiwix e191c31 09/18: improve function kiwix-get-librari
From: |
Stefan Monnier |
Subject: |
[elpa] externals/kiwix e191c31 09/18: improve function kiwix-get-libraries to support remote Docker server |
Date: |
Wed, 4 Aug 2021 18:28:10 -0400 (EDT) |
branch: externals/kiwix
commit e191c312e5c9343fd9601c45a8ccd017479ee475
Author: stardiviner <numbchild@gmail.com>
Commit: stardiviner <numbchild@gmail.com>
improve function kiwix-get-libraries to support remote Docker server
---
kiwix.el | 51 +++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 43 insertions(+), 8 deletions(-)
diff --git a/kiwix.el b/kiwix.el
index c12614a..f11fddd 100644
--- a/kiwix.el
+++ b/kiwix.el
@@ -6,7 +6,7 @@
;; Keywords: kiwix wikipedia
;; Homepage: https://github.com/stardiviner/kiwix.el
;; Created: 23th July 2016
-;; Version: 1.0.3
+;; Version: 1.1.0
;; Package-Requires: ((emacs "24.4") (request "0.3.0") (elquery "0.1.0"))
;; Copyright (C) 2019-2020 Free Software Foundation, Inc.
@@ -133,22 +133,57 @@ Set it to ‘t’ will use Emacs built-in ‘completing-read’."
(const :tag "xwidget browser" xwidget-webkit-browse-url))
:safe #'symbolp)
+
+(defvar kiwix-libraries ()
+ "A list of Kiwix libraries.")
+
(defun kiwix--get-library-name (file)
"Extract library name from library file."
(replace-regexp-in-string "\\.zim\\'" "" file))
(defun kiwix-get-libraries ()
"Check out all available Kiwix libraries."
- (when kiwix-zim-dir
- (mapcar #'kiwix--get-library-name
- (directory-files kiwix-zim-dir nil ".*\\.zim\\'"))))
-
-(defvar kiwix-libraries (kiwix-get-libraries)
- "A list of Kiwix libraries.")
+ (cond
+ ;; ZIM library files on remote Docker server, parse index HTML page.
+ ((eq kiwix-server-type 'docker-remote)
+ (let ((url (format "%s:%s" kiwix-server-url kiwix-server-port)))
+ (request url
+ :type "GET"
+ :sync t
+ :parser (lambda ()
+ (let ((html (elquery-read-string
(buffer-substring-no-properties (point-min) (point-max)))))
+ (setq kiwix-libraries
+ (mapcar
+ ;; remove "/" from "/<zim_library_name>"
+ (lambda (slash_library)
+ (substring slash_library 1 nil))
+ ;; extract plist values. list of
"/<zim_library_name>"
+ (mapcar 'cadr
+ ;; extract nodes properties in plist
+ (mapcar #'elquery-props
+ ;; return a list of elquery nodes
+ (elquery-children
+ ;; return the <div
class="book__list">
+ (car (elquery-$ ".book__list"
html)))))))
+ (elquery-children (first (elquery-$ ".book__list" html)))))
+ :error (cl-function
+ (lambda (&rest args &key error-thrown &allow-other-keys)
+ (message "Function kiwix-get-libraries error.")))
+ :success (cl-function
+ (lambda (&key _data &allow-other-keys)
+ _data))
+ :status-code '((404 . (lambda (&rest _) (message (format "Endpoint %s
does not exist." url))))
+ (500 . (lambda (&rest _) (message (format "Error from
%s." url))))))))
+ ;; ZIM library files on local host, parse directory files.
+ ((or (eq kiwix-server-type 'kiwix-serve-local)
+ (eq kiwix-server-type 'docker-local))
+ (when (and (file-directory-p kiwix-zim-dir) (file-readable-p
kiwix-zim-dir))
+ (mapcar #'kiwix--get-library-name
+ (directory-files kiwix-zim-dir nil ".*\\.zim\\'"))))))
(defun kiwix-libraries-refresh ()
"A helper function to refresh available Kiwx libraries."
- (setq kiwix-libraries (kiwix-get-libraries)))
+ (kiwix-get-libraries))
(defun kiwix-select-library (&optional filter)
"Select Kiwix library name."
- [elpa] externals/kiwix updated (0c5e161 -> 71e770c), Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix c273429 06/18: refactor and remove the variable `kiwix--selected-library', Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix ca03a65 01/18: use Docker server by default, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix c871bef 07/18: refactor function kiwix-at-point to separate into smaller functional functions, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 7e0b82c 04/18: refresh ZIM libraries list once-time per package loading, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 12e13c8 02/18: support remote Docker service, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 423f607 05/18: Concentrate all kiwix library dir variables into only one, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 716f3c4 12/18: Add condition to detect kiwix library path exist to fix GitHub Actions, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix e191c31 09/18: improve function kiwix-get-libraries to support remote Docker server,
Stefan Monnier <=
- [elpa] externals/kiwix 0ec84f3 03/18: use dynamic ZIM library path, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 3330d7e 08/18: Add extra library "elquery" for parsing HTTP query HTML result, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix a33c4a2 16/18: Fix kiwix-libraries variable not initialized by function kiwix-get-libraries, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 0f85022 17/18: Add autoload cookies and improve docstring, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix f49557d 11/18: Fix format three fields, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix f9cae99 13/18: Improve kiwix-server-type docstring, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix c0c597d 14/18: Improve package config examples on README, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 9521d3b 15/18: Change default kiwix-server-type to docker-local, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix 71e770c 18/18: Update config example in source code document section, Stefan Monnier, 2021/08/04
- [elpa] externals/kiwix d1e8fa2 10/18: Fix void variable kiwix-zim-dir, Stefan Monnier, 2021/08/04