/
api.clj
98 lines (81 loc) · 4.64 KB
/
api.clj
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
85
86
87
88
89
90
91
92
93
94
95
96
97
(ns page-renderer.api
(:gen-class)
(:require [page-renderer.core :as core]
[page-renderer.service-worker-generator :as swg]
[page-renderer.cachebusting :as fu])
(:import (java.util Map)))
(def cache-bust fu/cache-bust)
(defn render-page
"Renders a page with a modern meta set.
^Map renderable:
Main parameters
^Vector :body - a vector for Hiccup to render into HTML of the document's body
^String :title - content for title tag
^String :favicon - favicon's url
^String :script - script name, will be loaded asynchronously
^String :stylesheet - stylesheet filename, will be plugged into the head, will cause
browser waiting for download.
Assets
^String :stylesheet-async - stylesheet filename, will be loaded asynchronously by script.
^String :garden-css - data structure for Garden CSS
^String :script-sync - script name, will be loaded synchronously
^String :js-module - entry point for JS modules. If you prefer your scripts to be served as modules
^Boolean :skip-cachebusting? - will skip automatic cachebusting if set. Defaults to false.
^String :on-dom-interactive-js - a js snippet to run once DOM is interactive or ready.
^String/Collection<String> :stylesheet-inline - stylesheet filename, will be inlined into the head.
PWA related
^String :link-image-src - url to image-src
^String :link-apple-icon - url to image used for apple-touch-icon link
^String :link-apple-startup-image - url to image used for apple-touch-startup-image link
^String :theme-color - theme color for PWA (defaults to white)
^String/Boolean :manifest - truthy value will add a manifest link
If a string is passed – it'll be treated as a manifest url. Otherwise '/manifest.json'
will be specified.
^String/Boolean :service-worker - service worker url, defaults to /service-worker.js
^String :sw-default-url – application default url.
Must be an absolute path like '/app'. Defaults to '/'. Will be used in a regexp.
^List<String> :sw-add-assets - a collection of additional
assets you want to precache, like [\"/fonts/icon-font.woff\" \"/logo.png\"]
More meta
^String :lang - when provided will render a meta tag and a document attribute for page language.
^String :meta-title - content for the title tag (preferred)
^String :meta-keywords - content for the keywords tag
^String :meta-description - meta description
^Map :meta-props – meta which must be rendered as props {'fb:app_id' 123}
^String :head-tags - data structure to render into HTML of the document's head
Open Graph meta (@link https://ogp.me)
^String :og-title - OpenGraph title
^String :og-description - OpenGraph description
^String :og-image - absolute url to image for OpenGraph
^String :og-type - OpenGraph object type
^String :og-url - OpenGraph page permalink
Twitter meta (@link https://developer.twitter.com/en/docs/tweets/optimize-with-cards/guides/getting-started)
^String :twitter-site - Twitter @username. Required for all Twitter meta to render
^String :twitter-creator - Twitter @username.
^Keyword :twitter-card-type - Twitter card type one of #{:summary :summary_large_image :app :player}
^String :twitter-description - Twitter card description
^String :twitter-image - Twitter image link. Twitter images are useu
^String :twitter-image-alt - Twitter image alt"
^String [^Map renderable]
(core/render-page renderable))
(defn respond-page
"Renders a page and returns basic Ring response map
See render-page for docs on renderable."
^Map [^Map renderable]
(core/respond-page renderable))
(defn generate-service-worker
"Generates a service worker script that will precache all the assets from renderable.
^Map renderable:
^String/Boolean :service-worker - service worker url, defaults to /service-worker.js
^String :sw-default-url – application default url.
Must be an absolute path like '/app'. Defaults to '/'. Will be used in a regexp.
^List<String> :sw-add-assets - a collection of additional
assets you want to precache, like [\"/fonts/icon-font.woff\" \"/logo.png\"]
See render-page for docs on renderable."
^String [^Map renderable]
(swg/generate-script renderable))
(defn respond-service-worker
"Generates a Ring response map containing a service worker script as a body.
See generate-service-worker for more docs"
^Map [^Map renderable]
(swg/generate-ring-response renderable))