make-html.scm 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. # -*- scheme -*-
  3. exec guile --debug -s $0 "$@"
  4. !#
  5. (use-modules (texinfo reflection)
  6. (texinfo html)
  7. (sxml simple)
  8. (sxml transform)
  9. ((srfi srfi-13) :select (string-join)))
  10. (define (makedirs path)
  11. (let loop ((path ".") (components (string-split path #\/)))
  12. (if (not (null? components))
  13. (let ((sub-path (string-append path "/" (car components))))
  14. (if (or (not (file-exists? sub-path))
  15. (not (file-is-directory? sub-path)))
  16. (mkdir sub-path))
  17. (loop sub-path (cdr components))))))
  18. (define (wrap-html title root-path scm-url body)
  19. `(html (@ (xmlns "http://www.w3.org/1999/xhtml"))
  20. (head
  21. (title ,title)
  22. (meta (@ (name "Generator")
  23. (content "The Guile SXML Toolkit")))
  24. (style (@ (type "text/css") (media "screen"))
  25. "@import url("
  26. ,(string-append root-path "base.css")
  27. ");"))
  28. (body
  29. (div (@ (id "rap"))
  30. (h1 (@ (id "header"))
  31. (a (@ (href ,root-path)) ,*name*))
  32. (div (@ (id "content"))
  33. (h2 (@ (class "centered")) ,title)
  34. ,@body)
  35. (div (@ (id "footer"))
  36. "powered by sxml")))))
  37. (define xhtml-doctype
  38. (string-append
  39. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
  40. "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n\n"))
  41. (define (module->str scm)
  42. (call-with-output-string (lambda (p) (display scm p))))
  43. (define (module->ustr scm)
  44. (string-append (string-join (map symbol->string scm) ".") "/"))
  45. (define (make-html-index)
  46. (with-output-to-file "html/index.html"
  47. (lambda ()
  48. (display xhtml-doctype)
  49. (sxml->xml
  50. (pre-post-order
  51. (stexi->shtml
  52. `(texinfo
  53. (% (title "unused"))
  54. ,@(cdr
  55. (package-stexi-standard-copying
  56. *name* *version* *updated* *years* *copyright-holder*
  57. *permissions*))
  58. (table
  59. (% (formatter (bold)))
  60. ,@(map
  61. (lambda (module description)
  62. `(entry
  63. (% (heading
  64. (uref (% (url ,(module->ustr module))
  65. (title ,(module->str module))))))
  66. ,@description))
  67. (map car *modules*) (map cdr *modules*)))))
  68. `((html . ,(lambda (tag attrs head body)
  69. (wrap-html
  70. *name*
  71. *html-relative-root-path*
  72. "index.scm"
  73. (cdr body)))) ;; cdr past the 'body tag
  74. (*text* . ,(lambda (tag text) text))
  75. (*default* . ,(lambda args args))))))))
  76. (define (make-html-module-pages)
  77. (for-each
  78. (lambda (module)
  79. (let* ((ustr (string-append "./html/" (module->ustr module)))
  80. (port (begin
  81. (makedirs ustr)
  82. (open-output-file (string-append ustr "index.html")))))
  83. (display xhtml-doctype port)
  84. (sxml->xml
  85. (pre-post-order
  86. (stexi->shtml (module-stexi-documentation module))
  87. `((html . ,(lambda (tag attrs head body)
  88. (wrap-html
  89. (module->str module)
  90. (string-append "../" *html-relative-root-path*)
  91. "../index.scm"
  92. (cdr body)))) ;; cdr past the 'body tag
  93. (*text* . ,(lambda (tag text) text))
  94. (*default* . ,(lambda args args))))
  95. port)))
  96. (map car *modules*)))
  97. (define (main config-scm)
  98. (load config-scm)
  99. (makedirs "./html")
  100. (make-html-index)
  101. (make-html-module-pages))
  102. (apply main (cdr (command-line)))