-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathadd-to-head.rkt
38 lines (31 loc) · 1022 Bytes
/
add-to-head.rkt
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
#lang racket
;; Realm of kludge:
;;
;; AFIK no way via Scribble to put something into the <head> section.
;;
;; This reads all HTML files and injects some stuff immediately before the
;; </head> closing tag.
(define (meta k v)
(format "<meta name=\"~a\" content=\"~a\">" k v))
(define metas
(string-append
(meta "keywords" "Racket, macros, Scheme")
(meta "description" "Practical Racket macros")
(meta "author" "Greg Hendershott")
(meta "charset" "utf-8")))
(define </head> "</head>")
(define all (string-append metas </head>))
(define subst (regexp-replace* "\n" all "")) ;minify
(define (do-file path)
(define old (file->string path))
(define new (regexp-replace </head> old subst))
(with-output-to-file path
(lambda () (display new))
#:mode 'text
#:exists 'replace))
(require racket/runtime-path)
(define-runtime-path here ".")
(for ([path (find-files (lambda (path)
(regexp-match? #rx"\\.html" path))
here)])
(do-file path))