about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2023-04-03 22:07:04 -0500
committerCase Duckworth2023-04-03 22:07:04 -0500
commita1cde11d5ebe95a365120eb5aeb7f65469e44b30 (patch)
treeecc91700447039733daebc04a6581dd01b92e7ed
parentIt builds now (diff)
downloadwikme-a1cde11d5ebe95a365120eb5aeb7f65469e44b30.tar.gz
wikme-a1cde11d5ebe95a365120eb5aeb7f65469e44b30.zip
Changes and stuff
I have done a bad job of documenting what I'm doing

- it builds now - run `make`
- it builds the pages in test/ and links them
- ... that's it
-rw-r--r--.gitignore2
-rw-r--r--Makefile26
-rw-r--r--main.scm8
-rw-r--r--test/lions.md8
-rw-r--r--wikme.scm13
-rw-r--r--wikme.sld79
-rw-r--r--wikme.ss (renamed from wikme-impl.scm)77
7 files changed, 173 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore index 637f6da..768cfe1 100644 --- a/.gitignore +++ b/.gitignore
@@ -1,3 +1,5 @@
1wikme 1wikme
2*.so 2*.so
3*.o 3*.o
4*.import.scm
5out/
diff --git a/Makefile b/Makefile index 506d366..1dd66d1 100644 --- a/Makefile +++ b/Makefile
@@ -1,20 +1,28 @@
1# wikme 1# wikme
2 2
3PREFIX = /usr/bin 3PREFIX = /usr/bin
4CSC = csc -I$(PWD) 4CSC = csc -R r7rs
5 5
6OBJ = wikme.scm.o 6NAME = wikme
7PROG = $(NAME).scm
8SOURCE = $(NAME).ss
9LIB = $(NAME).sld
10OBJ = $(NAME)-lib.o
7 11
8wikme: main.scm $(OBJ) 12$(NAME): $(PROG) $(OBJ)
9 $(CSC) -o $@ $(OBJ) -uses wikme main.scm 13 $(CSC) -o $@ $(OBJ) -uses $(NAME) $(PROG)
10 14
11$(OBJ): wikme.scm wikme-impl.scm 15$(OBJ): $(LIB)
12 $(CSC) -c -J wikme.scm -unit wikme -o $@ 16 $(CSC) -c -J $(LIB) -unit $(NAME) -o $@
13 17
14.PHONY: install clean 18$(LIB): $(SOURCE)
15 19
16install: wikme 20.PHONY: install test clean
17 install -Dt $(DESTDIR)$(PREFIX)/$@ $< 21
22install: $(NAME)
23 install -Dt $(DESTDIR)$(PREFIX)/$@ $(NAME)
24
25test: # TODO
18 26
19clean: 27clean:
20 rm -f *.import.scm *.so *.o 28 rm -f *.import.scm *.so *.o
diff --git a/main.scm b/main.scm deleted file mode 100644 index c3e4554..0000000 --- a/main.scm +++ /dev/null
@@ -1,8 +0,0 @@
1(import wikme
2 (chicken process-context))
3
4(define (main args)
5 (display (wikify-links "Hi from [[wikme]]!"))
6 (newline))
7
8(main (command-line-arguments))
diff --git a/test/lions.md b/test/lions.md new file mode 100644 index 0000000..ec465e7 --- /dev/null +++ b/test/lions.md
@@ -0,0 +1,8 @@
1# Lions!! RAWWR :3
2
3Lions are great big [[cats]] that like to pounce and play on things, or something.
4They live on this thing called the [[grassland|savannah]] and eat [[birds]].
5
6I assume they eat other stuff too, but I don't know what, lol.
7
8[A link to a lion](https://lions.org).
diff --git a/wikme.scm b/wikme.scm index 10b1a1a..a8b4755 100644 --- a/wikme.scm +++ b/wikme.scm
@@ -1,4 +1,9 @@
1(module wikme * 1(import wikme
2 (import scheme 2 (scheme)
3 (chicken base)) 3 (chicken process-context))
4 (include "wikme-impl.scm")) 4
5(define (main args)
6 (build-wiki "./test/"
7 destination: "./out/"))
8
9(main (command-line-arguments))
diff --git a/wikme.sld b/wikme.sld new file mode 100644 index 0000000..ca3ddd8 --- /dev/null +++ b/wikme.sld
@@ -0,0 +1,79 @@
1#+chicken-5
2(import (r7rs))
3
4(define-library wikme
5 (import (scheme))
6 (cond-expand
7 (chicken-5 (import (chicken base)
8 (chicken file)
9 (chicken file posix)
10 (chicken format)
11 (chicken io)
12 (chicken irregex)
13 (chicken pathname)
14 (chicken port)
15 (chicken process)
16 (chicken process-context)
17 (chicken string)
18 (chicken time posix)
19 (cmark)
20 (regex) ; XXX: deprecated upstream
21 (srfi-13)))
22 (else (error "Wikme doesn't support this R7RS scheme implementation yet.")))
23
24 ;; <wiki>
25 (export <wiki>
26 wiki-base-url
27 wiki-origin-dir
28 wiki-destination-dir
29 wiki-pages
30 wiki-defaults
31 wiki-default-ref
32 wiki-default-set!)
33
34 ;; <page>
35 (export <page>
36 page-source
37 page-body
38 page-origin
39 page-destination
40 page-template
41 page-source-transformers
42 page-path-transformers
43 page-wiki
44 page-meta
45 page-meta-ref
46 page-meta-set!)
47
48 ;; transformers
49 (export transform
50 transform-source!
51 transform-path!
52 page-cmark->html)
53
54 ;; templates
55 (export render-template
56 env->replacements
57 render)
58
59 ;; links
60 (export wiki-link-sre
61 wikify-links
62 linkify
63 slugify
64 string-capitalize
65 unslugify
66 path-relativize
67 wiki-page-origin-path
68 wiki-page-destination-path)
69
70 ;; page building
71 (export file->page
72 guess-title
73 basename
74 indexify
75 guess-last-updated
76 page->file
77 build-wiki)
78
79 (include "wikme.ss"))
diff --git a/wikme-impl.scm b/wikme.ss index 2097af7..cc7aac1 100644 --- a/wikme-impl.scm +++ b/wikme.ss
@@ -1,20 +1,5 @@
1;;; Wikme --- convert a directory of markdown files into a static wiki 1;;; Wikme --- convert a directory of markdown files into a static wiki
2 2
3(import (chicken file)
4 (chicken file posix)
5 (chicken format)
6 (chicken io)
7 (chicken irregex)
8 (chicken pathname)
9 (chicken port)
10 (chicken process)
11 (chicken process-context)
12 (chicken string)
13 (chicken time posix)
14 (cmark)
15 (regex) ; XXX: deprecated upstream
16 (srfi-13))
17
18;;; Records 3;;; Records
19 4
20(define-record-type <wiki> 5(define-record-type <wiki>
@@ -145,9 +130,11 @@
145 130
146(define wiki-link-sre 131(define wiki-link-sre
147 ;;; An SRE for [[wiki-style links|with optional titles]]. 132 ;;; An SRE for [[wiki-style links|with optional titles]].
133 ;; XXX
148 '(: "[[" 134 '(: "[["
149 (submatch-named pname (+ (~ "|"))) 135 (=> pname (*? (~ "|")))
150 (? (submatch "|" (submatch-named ptitle (*? nonl)))) 136 (? ($ "|" (=> ptitle
137 (*? (~ "]")))))
151 "]]")) 138 "]]"))
152 139
153(define (wikify-links text #!optional page) 140(define (wikify-links text #!optional page)
@@ -167,6 +154,7 @@
167 "")) 154 ""))
168 ptitle))))) 155 ptitle)))))
169 156
157;;; TODO: merge linkify and indexify ... they're almost the same thing.
170(define (linkify pagename base-url) 158(define (linkify pagename base-url)
171 ;;; Turn a page name into a link suitable for an <a> tag. 159 ;;; Turn a page name into a link suitable for an <a> tag.
172 (make-pathname (list base-url (slugify pagename)) 160 (make-pathname (list base-url (slugify pagename))
@@ -212,6 +200,18 @@
212 (string-trim (string-drop path (string-prefix-length path dir)) 200 (string-trim (string-drop path (string-prefix-length path dir))
213 (lambda (c) (char=? c #\/)))))) 201 (lambda (c) (char=? c #\/))))))
214 202
203(define (wiki-page-origin-path page #!optional wiki)
204 ;;; Return PAGE's origin path in WIKI.
205 (path-relativize (page-origin page)
206 (wiki-origin-dir (or wiki
207 (page-wiki page)))))
208
209(define (wiki-page-destination-path page #!optional wiki)
210 ;;; Return PAGE's destination path in WIKI.
211 (path-relativize (page-destination page)
212 (wiki-destination-dir (or wiki
213 (page-wiki page)))))
214
215;;; Build a page 215;;; Build a page
216 216
217(define (file->page file wiki 217(define (file->page file wiki
@@ -264,8 +264,7 @@
264(define (guess-last-updated page) 264(define (guess-last-updated page)
265 ;;; Guess when PAGE was last edited. 265 ;;; Guess when PAGE was last edited.
266 ;; Tries to use git, but falls back to mtime. 266 ;; Tries to use git, but falls back to mtime.
267 (let ((f (path-relativize (page-origin page) 267 (let ((f (wiki-page-origin-path page)))
268 (wiki-origin-dir (page-wiki page)))))
269 (time->string 268 (time->string
270 (seconds->local-time 269 (seconds->local-time
271 (or #; 270 (or #;
@@ -288,3 +287,43 @@
288 (lambda () 287 (lambda ()
289 (write-string (render page)))))) 288 (write-string (render page))))))
290 289
290(define (eprintf . args)
291 (apply fprintf (current-error-port) args))
292
293(define (build-wiki origin
294 #!key
295 (destination (make-pathname origin "out"))
296 (base-url "")
297 (base-template (make-pathname origin "template.html"))
298 (source-transformers (list page-cmark->html wikify-links))
299 (path-transformers (list indexify))
300 (source-extension "md"))
301 (define w (make-wiki
302 base-url
303 origin
304 destination
305 '()
306 `((template . ,base-template)
307 (source-transformers . ,source-transformers)
308 (path-transformers . ,path-transformers)
309 (source-extension . ,source-extension))))
310
311 (eprintf "\nBuilding pages...\n")
312 (for-each (lambda (f)
313 (let ((p (file->page f w)))
314 (eprintf "~a -> ~a\n" f (page-meta-ref p 'title))))
315 (glob (make-pathname origin
316 "*"
317 (wiki-default-ref w 'source-extension))))
318
319 (let ((dd (wiki-destination-dir w)))
320 (eprintf "\nCreating destination directory: ~a\n" dd)
321 (create-directory dd 'parents))
322
323 (eprintf "\nWriting pages...\n")
324 (for-each (lambda (p)
325 (eprintf "~a -> ~a\n"
326 (page-meta-ref p 'title)
327 (wiki-page-destination-path p))
328 (page->file p))
329 (wiki-pages w)))