forked from otherjoel/thenotepad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil-template.rkt
62 lines (52 loc) · 2.13 KB
/
util-template.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#lang racket/base
(require racket/string
racket/path
pollen/core
net/uri-codec
"util-date.rkt"
txexpr)
(provide (all-defined-out))
(define (pdfable? file-path)
(string-contains? file-path ".poly"))
(define (pdfname page) (string-replace (path->string (file-name-from-path page))
"poly.pm" "pdf"))
(define (source-listing p)
(regexp-replace #px"(\\.html$)" (symbol->string p) ".pollen.html"))
(define (post-header post metas)
(define updated (select-from-metas 'updated metas))
(define updated-xexpr
(cond [updated `((em "Updated " (time [[datetime ,updated]] ,(pubdate->english updated))) nbsp middot nbsp)]
[else '("")]))
(define timestamp-raw (select-from-metas 'published metas))
(define timestamp
(cond [timestamp-raw
`("Scribbled "
(time [[datetime ,timestamp-raw]]
,(pubdate->english timestamp-raw))
nbsp middot nbsp)]
[else '("")]))
(define pdflink
(cond [(string-prefix? (symbol->string post) "posts")
`((a [[class "pdf"]
[href ,(string-append "/posts/" (pdfname (select-from-metas 'here-path metas)))]]
"PDF") nbsp middot nbsp)]
[else '("")]))
`(header
(h1 (a [[href ,(string-append "/" (symbol->string post))]] ,(select-from-metas 'title metas)))
(p ,@timestamp
,@updated-xexpr
,@pdflink
(a [[class "source-link"] [href ,(string-append "/" (source-listing post))]]
loz "Pollen" nbsp "source"))))
(define (split-body-comments post-doc)
(define (is-comment? tx)
(and (txexpr? tx)
(eq? (get-tag tx) 'section)
(attrs-have-key? tx 'class)
(string=? (attr-ref tx 'class) "comments")))
(splitf-txexpr post-doc is-comment?))
(define meta-favicons
"<link rel=\"apple-touch-icon-precomposed\" href=\"/css/favicon/goose.svg\" />
<link rel=\"icon\" href=\"/css/favicon/goose.svg\" />
<meta name=\"application-name\" content=\" \"/>
<meta name=\"msapplication-TileColor\" content=\"#FFFFFF\" /> ")