aboutsummaryrefslogtreecommitdiff
path: root/org/blog/generate-phlog.scm
blob: 8d7445ba78c332d80fb1545b92b230f0b93781d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#! /usr/bin/guile \
-e main -s
!#

(use-modules (sxml simple))

(define (format-article-filename file)
  (let ((file-length (string-length file)))
    (string-append (substring file
                              0
                              (- file-length 4))
                   ".txt")))

(define (get-gophermap-item article)
  (let ((title (cadr (list-ref article 0)))
        (pub-date (cadr (list-ref article 4)))
        (file (cadr (list-ref article 6))))
    (string-append "0" pub-date " - " title "\t"
                   (format-article-filename file))))

(define (make-gophermap articles)
  (call-with-output-file "gophermap"
    (lambda (fp)
      (for-each
       (lambda (article)
         (if (list? article)
             (display (get-gophermap-item (cddr article)) fp)
             (newline fp)))
       (cdr (cadr articles))))))

(define (make-blog-file article)
  (let ((file (cadr (list-ref article 6))))
    (system
     (string-append "html2text " file " > "
                    (format-article-filename file)))))

(define (make-blogs articles)
  (for-each
   (lambda (article)
     (if (list? article)
         (make-blog-file (cddr article))))
   (cdr (cadr articles))))

(define (generate-phlog)
  (call-with-input-file "articles.xml"
    (lambda (fp)
      (let ((articles (xml->sxml fp)))
        (make-gophermap articles)
        (make-blogs articles)))))

(define (main args)
  (generate-phlog))