1/** the graph that builds and serves the site, for steps that run when a request asks, with `graph.lazy` */
2export let graph: incremental.Graph;
3
4/** set before the backend loads */
5export function setGraph(next: incremental.Graph) {
6 graph = next;
7}
8
9export type ScriptId = string;
10
11export interface ViewExports {
12 default: Marko.Component;
13 meta: Meta | ((props: { ssr: true }) => Promise<Meta> | Meta);
14 theme?: css.Theme;
15}
16
17/**
18 * A filesystem object associated with some ID,
19 * such as a page's route to it's source file.
20 */
21export interface FileItem {
22 id: string;
23 file: string;
24}
25export interface Section {
26 root: string;
27 base?: string;
28}
29export interface Font {
30 name: string;
31 /**
32 * Specify either font name, file path, or URL to fetch it.
33 * Private fonts do not have a URL and will fail to build if missing.
34 */
35 sources: string[];
36 subsets: Array<{
37 vars?: Record<string, FontVariableAxis>;
38 layoutFeatures?: string[];
39 unicodes: FontRange | FontRange[];
40 /** example: `/myfont.[ext]` */
41 asset: string;
42 }>;
43}
44export type FontVars = Record<string, FontVariableAxis>;
45export type FontVariableAxis = number | [min: number, max: number];
46export type FontRange = string | number | { start: number; end: number };
47
48// I have this so I can see if the blog is actually seen by people. And for
49// understanding where paperclover.net gets its load for. When I need to scale
50// large enough, analytics will determine the location of the second web
51// hosting node.
52export const analytics = `<script async src="https://plausible.paperclover.net/js/pa-GuSR8GegXbBWz72PEzlTR.js"></script>
53<script>window.plausible=window.plausible||function(){(plausible.q=plausible.q||[]).push(arguments)},plausible.init=plausible.init||function(i){plausible.o=i||{}};plausible.init()</script> `;
54
55export function wrapDocument({
56 body,
57 head,
58 inlineCss,
59 scripts,
60}: {
61 head: string;
62 body: string;
63 inlineCss: string;
64 scripts: string;
65}) {
66 return `<!doctype html><html lang=en><head><meta charset=utf8>${head}${
67 inlineCss ? `<style>${inlineCss}</style>` : ""
68 }${analytics}</head><body>${body}${scripts ? `<script>${scripts}</script>` : ""}</body></html>`;
69}
70
71export function joinScripts(scriptSources: string[]) {
72 const { length } = scriptSources;
73 if (scriptSources[0] == null) return "";
74 if (length === 1) return UNWRAP(scriptSources[0]);
75 return "[" + scriptSources.map((source) => `()=>{${source}}`).join(",")
76 + "].map(e=>e())";
77}
78
79export { default as CloverScriptInclude } from "./add-script.marko";
80
81import { UNWRAP } from "@clo/lib/assert";
82import type * as incremental from "@clo/lib/incremental";
83import type { Meta } from "@clo/lib/meta";
84import type * as css from "../css.ts";