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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
|
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
63
64
65
66
67
68
69
70
71
72
73
|
-
+
-
-
+
-
+
-
+
-
-
-
+
+
+
-
-
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
-
-
+
+
-
-
-
-
-
-
-
+
-
-
-
|
#lang at-exp racket/base
(require jdcom
(require jdcomls
punct/doc
punct/fetch
punct/render/html
racket/format
racket/match
racket/path
"tools.rkt"
html-printer
(only-in xml xexpr->string))
(only-in xml comment))
(provide display-html-page/dropin
display-html-page)
;; Render a Punct source file to HTML and display to the current output port.
(define (time-tag date-str)
@~a{<time datetime="@date-str">@(date-fmt date-str)</time>})
`(time [[datetime ,date-str]] ,(date-fmt date-str)))
(define (display-html-page/dropin html-xexprs metas)
(display-html-page (document metas
(xexpr->string `(article ,@html-xexprs))
'())
#:dropin-html? #t))
`(article ,@html-xexprs)
'())
#:dropin-html? #t))
(define (display-html-page src #:dropin-html? [dropin-html? #f])
(define doc (if (or (document? src) dropin-html?) src (get-doc src)))
(display @~a{
<!DOCTYPE html>
(display
(xexpr->html5
<html lang="en">
<head>
#:add-breaks? #t
<meta charset="UTF-8">
<title>@(or (meta-ref doc 'title) "Web page") — Joel Dueck dot com</title>
<link rel="alternate" type="application/atom+xml" href="http://joeldueck.com/feed.atom">
<meta http-equiv="Content-Security-Policy" content="default-src 'self' https://joeldueck.com data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' https://plausible.io; connect-src https://plausible.io https://api.weather.gov https://joeldueck.com;" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover">
<meta name="theme-color" content="hsl(var(--base-temp),50%,96%);">
<link rel="stylesheet" href="res/block.css" type="text/css">
<link rel="stylesheet" href="res/style.css?@(date-fmt #:format "d-MMM-y-hms")" type="text/css">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/site.webmanifest">
<script defer data-domain="joeldueck.com" src="https://plausible.io/js/script.js"></script>
</head>
<body>
<main>
<header class="small-caps">
<h1><a href="index.html">Joel Dueck</a>
`(html
@(match (meta-ref doc 'date)
[#f ""]
[[lang "en"]]
[(var d) @~a{· @(time-tag d)}]) </h1>
</header>
@(cond
[dropin-html? (document-body doc)]
[else
(parameterize ([current-directory (path->directory-path (path-only src))])
(doc->html doc jd-tags->html))])
(head
,(comment (string-append "Generated on " (date-fmt #:format "EEEE, d MMMM yyyy h:ma z")))
,(comment "Built with Racket + Punct + HTML5 Writer")
(meta [[charset "UTF-8"]])
(title ,(or (meta-ref doc 'title) "Web page") " — Joel Dueck dot com")
(meta [[name "viewport"]
[content "width=device-width, initial-scale=1.0, viewport-fit=cover"]])
(meta [[http-equiv "Content-Security-Policy"]
[content "default-src 'self' https://joeldueck.com data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' https://plausible.io; connect-src https://plausible.io https://api.weather.gov https://joeldueck.com;"]])
(meta [[name "theme-color"]
[content "hsl(var(--base-temp),50%,96%);"]])
(link [[rel "stylesheet"] [href "/res/block.css"]])
(link [[rel "stylesheet"] [href ,(format "/res/style.css?~a" (date-fmt #:format "d-MMM-y-hms"))]])
(link [[rel "apple-touch-icon"] [sizes "180x180"] [href "/apple-touch-icon.png"]])
(link [[rel "icon"] [type "image/png"] [sizes "32x32"] [href "/favicon-32x32.png"]])
(link [[rel "icon"] [type "image/png"] [sizes "16x16"] [href "/favicon-16x16.png"]])
(link [[rel "manifest"] [href "/site.webmanifest"]])
(script [[defer ""] [data-domain "joeldueck.com"] [src "https//plausible.io/js/script.js"]]))
(body
(main
(header [[class "small-caps"]]
(h1 (a [[href "/index.html"]] "Joel Dueck")
,@(if (meta-ref doc 'date) (list 'middot " " (time-tag (meta-ref doc 'date))) '())))
,(cond
[dropin-html? (document-body doc)]
[else
(parameterize ([current-directory (path->directory-path (path-only src))])
(doc->html-xexpr doc jd-tags->html))]))
</main>
<footer>
<div id="weather"><noscript>You don’t have javascript. How droll!</noscript></div>
<div id="tempslider">
<input type="range" min="-40" max="110" value="72" class="slider" id="myRange">
<button class="small-caps" onclick="updateWeatherDiv()" style="margin-left: 0.5rem;">Reset</button>
(footer
(div [[id "weather"]] (noscript "You don’t have javascript. How droll!"))
(div [[id "tempslider"]]
(input [[id "myRange"] [class "slider"] [type "range"] [min "-40"] [max "110"] [value "72"]])
(button [[class "small-caps"] [onclick "updateWeatherDiv()"] [style "margin-left: 0.5rem;"]]
</div>
<script src='res/windfinger.js'></script>
"Reset"))
(script [[src "res/windfinger.js"]]))
</footer>
<!--
Generated on @(date-fmt #:format "EEEE, d MMMM yyyy h:ma z")
Built with Punct: https://github.com/otherjoel/punct
Source: https://joeldueck.com/code/jdcom
-->
@(match (meta-ref doc 'web-script) [(? string? s) @~a{<script src="@s"></script>}] [_ ""])
,@(if (meta-ref doc 'web-script) `((script [[src ,(meta-ref doc 'web-script)]])) '()))))))
</body>
</html>
}))
(module+ main
(require racket/cmdline)
(define src (command-line #:args (filename) filename))
(display-html-page src))
|