Updated source files to work with Guile instead
    
    
      
        Getty Ritter
        10 years ago
      
    
    
  
  
  | 1 | (declare (uses libs)) | |
| 2 | (declare (uses telml)) | |
| 3 | ( | |
| 1 | (load "telml.scm") | |
| 2 | (load "libs.scm") | |
| 3 | (use-modules (ice-9 match)) | |
| 4 | 4 | |
| 5 | ; (load "libs.scm") | |
| 6 | ; (load "telml.scm") | |
| 7 | ; this is just Oleg's pattern matcher | |
| 8 | ; (load "match-case-simple.scm") | |
| 9 | ||
| 10 | ;(define (pairs lst) | |
| 11 | ; (match-case-simple lst | |
| 12 | ; [(,x . (,y . ,xs)) () (cons (list x y) (pairs xs))] | |
| 13 |  | |
| 5 | (define (pairs lst) | |
| 6 | (match lst | |
| 7 | ((x . (y . xs)) (cons (list x y) (pairs xs))) | |
| 8 | (__ '()))) | |
| 14 | 9 | |
| 15 | 10 | ;; template-ey things and style things | 
| 16 | 11 | |
| 35 | 30 | (define stylesheet | 
| 36 | 31 | '((body | 
| 37 | 32 | (font-family "Palatino, \"Palatino Linotype\", \"Palatino LT STD\", \"Book Antiqua\", Georgia, serif") | 
| 38 | ; (font-family "fira, \"Arial\", \"Helvetica\", sans-serif") | |
| 39 | 33 | (font-size 15pt) | 
| 40 | 34 | (background-color "#eeeeee") | 
| 41 | 35 | (counter-reset sidenote-counter)) | 
| 136 | 130 | (h1 "what happens when computer")) | 
| 137 | 131 | (div (@ (class "nav")) ,menu) | 
| 138 | 132 | (div (@ (class "main")) ,content) | 
| 139 | (div (@ (class "footer")) " | |
| 133 | (div (@ (class "footer")) "© 2015 getty ritter")))) | |
| 140 | 134 | |
| 141 | 135 | (define (archive) | 
| 142 | 136 | (let* ((metadata (read-file "site.scm"))) | 
| 151 | 145 | (let* ((page-source (translate-file file)) | 
| 152 | 146 | (telml (cdr page-source)) | 
| 153 | 147 | (meta (car page-source)) | 
| 154 | (title (if meta (cadr meta) pg))) | |
| 155 | (display (serialize-sxml (page title telml))))) | |
| 148 | (title (if (not (null? meta)) (cadr meta) pg)) | |
| 149 | (display (serialize-sxml (page title telml)))) | |
| 150 | (format #t "~a\n" display))) | |
| 156 | 151 | |
| 157 | 152 | (define (dispatch pg files) | 
| 158 | 153 | (cond ((equal? pg "index") | 
| 171 | 166 | (with-output-to-file "output/about/index.html" | 
| 172 | 167 | (lambda () (main "about" "pages/about.telml")))))) | 
| 173 | 168 | |
| 174 | (define args (c | |
| 169 | (define args (cdr (command-line))) | |
| 175 | 170 | (cond ((= (length args) 0) | 
| 176 | (format #t "Usage: generate [page] [files] | |
| 171 | (format #t "Usage: generate [page] [files]\n")) | |
| 177 | 172 | (else (dispatch (car args) (cdr args)))) | 
| 1 | 1 | ;; some library stuff | 
| 2 | 2 | |
| 3 | (define (++ . args) | |
| 4 | (define (go ls) | |
| 5 | (if (null? ls) "" | |
| 6 | (string-append (car ls) (go (cdr ls))))) | |
| 7 |  | |
| 3 | (define (++ . args) (apply string-append args)) | |
| 4 | ||
| 5 | (define (as-string s) | |
| 6 | (if (symbol? s) (symbol->string s) s)) | |
| 8 | 7 | |
| 9 | 8 | (define (intercalate x xs) | 
| 10 | 9 | (define (go ls) | 
| 34 | 33 | (intercalate "," (map mk-selector (cdr selector)))) | 
| 35 | 34 | (else "..."))) | 
| 36 | 35 | (define (mk-line line) | 
| 37 | (++ ( | |
| 36 | (++ (as-string (car line)) ": " (as-string (cadr line)) "; ")) | |
| 38 | 37 | (define (mk-clause clause) | 
| 39 | 38 | (++ | 
| 40 | 39 | (mk-selector (car clause)) | 
| 51 | 50 | |
| 52 | 51 | (define (serialize-sxml sxml) | 
| 53 | 52 | (define (mk-prop prop) | 
| 54 | (let ((key (car prop)) (val (cadr prop))) | |
| 55 | (++ " " | |
| 56 | key | |
| 57 | "=" | |
| 58 |  | |
| 53 | (let ((key (as-string (car prop))) (val (as-string (cadr prop)))) | |
| 54 | (++ " " key "=" | |
| 55 | (if (string? val) (++ "\"" val "\"") (as-string val))))) | |
| 59 | 56 | (cond ((null? sxml) "") | 
| 60 | 57 | ((string? sxml) sxml) | 
| 61 | 58 | ((symbol? sxml) (symbol->string sxml)) | 
| 62 | 59 | ((not (symbol? (car sxml))) | 
| 63 | 60 | (apply string-append (map serialize-sxml sxml))) | 
| 64 | 61 | (else | 
| 65 | (let ((tag ( | |
| 62 | (let ((tag (symbol->string (car sxml))) | |
| 66 | 63 | (props (if (and (cadr? sxml) (eq? (caadr sxml) '@)) | 
| 67 | 64 | (cdadr sxml) '())) | 
| 68 | 65 | (vals (if (and (cadr? sxml) (eq? (caadr sxml) '@)) | 
| 1 | (import (owl io)) | |
| 2 | (import (owl string)) | |
| 3 | ( | |
| 1 | (use-modules (ice-9 rdelim)) | |
| 2 | (use-modules (ice-9 regex)) | |
| 4 | 3 | |
| 5 | 4 | (define (mk-stream s) | 
| 6 | 5 | (let ((lst (string->list s))) | 
| 115 | 114 | `(a (@ (href ,(apply string-append url))) ,name))) | 
| 116 | 115 | (cons 'sidenote (lambda (arg) `(span (@ (class sidenote)) ,arg))) | 
| 117 | 116 | (cons 'ref (lambda (name) | 
| 118 | `(label (@ (for , | |
| 117 | `(label (@ (for ,(car name)) (class "sidenote-number")))))))) | |
| 119 | 118 | |
| 120 | 119 | (define (partition doc lst) | 
| 121 | 120 | (cond ((null? doc) (reverse lst)) | 
| 129 | 128 | |
| 130 | 129 | (define (string-drop str i) | 
| 131 | 130 | (let ((l (string-length str))) | 
| 132 | (substring str i | |
| 131 | (substring str i l))) | |
| 133 | 132 | |
| 134 | 133 | (define (gather-para document) | 
| 135 | 134 | (define (split-string text) | 
| 136 | (let ((i (string-ref text "\n\n"))) | |
| 137 | (if (not i) (list text) | |
| 138 | (cons (string-take text i) | |
| 139 | (cons #f (split-string (string-drop text (+ i 2)))))))) | |
| 135 | (let ((m (string-match "\n\n" text))) | |
| 136 | (if (not m) (list text) | |
| 137 | (let ((i (match:start m))) | |
| 138 | (cons (string-take text i) | |
| 139 | (cons #f (split-string (string-drop text (+ i 2))))))))) | |
| 140 | 140 | (define (go doc) | 
| 141 | 141 | (cond ((null? doc) '()) | 
| 142 | 142 | ((not (string? (car doc))) | 
| 167 | 167 | (eq? (caar telml) 'meta)) | 
| 168 | 168 | (cdr telml) | 
| 169 | 169 | telml))) | 
| 170 | (cons (if | |
| 170 | (cons (if #f (string->sexp meta) '()) | |
| 171 | 171 | (map (lambda (x) | 
| 172 | 172 | (cons 'p (rec x))) | 
| 173 | 173 | (gather-para body))))) | 
| 174 | 174 | |
| 175 | 175 | (define (translate-file filename) | 
| 176 | ( | |
| 176 | (let ((body (with-input-from-file filename read-string))) | |
| 177 | (telml->sxml (parse body) basic-tag-list))) | |