Skip to content
This repository was archived by the owner on Jul 21, 2021. It is now read-only.

Commit 24921ee

Browse files
committed
Add functions in quickdocs-updater.readme.
1 parent 6ef6c7f commit 24921ee

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

README.markdown

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Usage
44

5+
## Requirements
6+
7+
* "timeout" (or "gtimeout" on Mac OS) command
8+
* Pandoc (for converting Markdown files)
9+
* Emacs (for converting Org files)
10+
511
## Installation
612

713
## Author

quickdocs-updater.asd

+4-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
:split-sequence)
2626
:components ((:module "src"
2727
:components
28-
((:file "quickdocs-updater"))))
28+
((:file "quickdocs-updater" :depends-on ("extracter"))
29+
(:file "release" :depends-on ("extracter"))
30+
(:file "readme")
31+
(:file "extracter"))))
2932
:description "Updates Quickdocs database"
3033
:long-description
3134
#.(with-open-file (stream (merge-pathnames

src/readme.lisp

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
(in-package :cl-user)
2+
(defpackage quickdocs-updater.readme
3+
(:use :cl)
4+
(:import-from :quickdocs-updater.release
5+
:readme-file)
6+
(:import-from :alexandria
7+
:ignore-some-conditions)
8+
(:export :convert-readme))
9+
(in-package :quickdocs-updater.readme)
10+
11+
(defparameter *timeout-command*
12+
#+darwin "gtimeout" ;; of coreutils
13+
#-darwin "timeout")
14+
15+
(defparameter *pandoc-path* (or (uiop:getenv "PANDOC_PATH")
16+
"pandoc"))
17+
18+
(defparameter *emacs-path* (or (uiop:getenv "EMACS_PATH")
19+
"emacs"))
20+
21+
(defun which (command)
22+
(handler-case
23+
(let* ((result (with-output-to-string (s)
24+
(uiop:run-program `("which" ,command)
25+
:output s
26+
:error-output *error-output*)))
27+
(newline-pos
28+
(position-if (lambda (char)
29+
(or (char= char #\Newline)
30+
(char= char #\Return)))
31+
result)))
32+
(if newline-pos
33+
(subseq result 0 newline-pos)
34+
result))
35+
(uiop:subprocess-error ()
36+
nil)))
37+
38+
(defun check-if-command-installed (&rest commands)
39+
(dolist (command commands)
40+
(or (which command)
41+
(error "Requiement ~S does not exist. Ensure if it's installed and check your PATH." command))))
42+
43+
(defun convert-readme (file)
44+
(check-type file pathname)
45+
(assert (uiop:file-exists-p file))
46+
(let ((type (pathname-type file)))
47+
(cond
48+
((or (null type)
49+
(string= type "txt"))
50+
(convert-plaintext-into-html file))
51+
((or (string= type "markdown")
52+
(string= type "md"))
53+
(convert-markdown-into-html file))
54+
((string= type "org")
55+
(convert-org-into-html file)))))
56+
57+
(defun convert-plaintext-into-html (file)
58+
(concatenate 'string "<pre>" (uiop:read-file-string file) "</pre>"))
59+
60+
(defun convert-markdown-into-html (file)
61+
(check-if-command-installed *timeout-command* *pandoc-path*)
62+
(ignore-some-conditions (uiop:subprocess-error)
63+
(with-output-to-string (s)
64+
(uiop:run-program `(,*timeout-command* 10 ,*pandoc-path* ,(namestring file))
65+
:force-shell t
66+
:output s
67+
:error-output *error-output*))))
68+
69+
(defun convert-org-into-html (file)
70+
(check-if-command-installed *timeout-command* *emacs-path*)
71+
(ignore-some-conditions (uiop:subprocess-error)
72+
(with-output-to-string (s)
73+
(uiop:run-program `(,*timeout-command*
74+
10
75+
,*emacs-path* "-Q" "-batch" "--file" ,(namestring file)
76+
"--eval" "(setq org-export-with-toc nil)"
77+
"--eval" "(princ (org-export-as-html 3 nil 'string t))")
78+
:force-shell t
79+
:output s
80+
:error-output *error-output*))))

0 commit comments

Comments
 (0)