@learnpack/learnpack 5.0.357 → 5.0.358

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/ui/app.tar.gz CHANGED
Binary file
Binary file
@@ -0,0 +1,78 @@
1
+ /**
2
+ * Branding used by link previews (Open Graph / Twitter cards).
3
+ *
4
+ * Both the draft server and the publish pipeline need an absolute image URL for
5
+ * `og:image`, and drafts additionally need copy that says nothing about the
6
+ * course they belong to.
7
+ */
8
+
9
+ /**
10
+ * Where `learnpack serve` runs in production. It is only a fallback: the server
11
+ * itself already has the real origin in `process.env.HOST` (it uses it to build
12
+ * webhook URLs). The `publish` command, however, runs on the author's machine
13
+ * with no such variable, and still has to write an absolute `og:image` into the
14
+ * package it uploads.
15
+ */
16
+ export const PRODUCTION_PUBLIC_HOST = "https://app.learnpack.co"
17
+
18
+ /**
19
+ * Strips what `.env` files routinely smuggle in — a trailing comment, quotes,
20
+ * stray whitespace, a trailing slash — the same way `serve` sanitises `HOST`.
21
+ * @param raw - The raw environment value, if set.
22
+ * @returns The cleaned value, or an empty string.
23
+ */
24
+ function normalizeOrigin(raw?: string): string {
25
+ if (!raw) {
26
+ return ""
27
+ }
28
+
29
+ return raw
30
+ .trim()
31
+ .split(/\s+#/)[0]
32
+ .trim()
33
+ .replace(/["']/g, "")
34
+ .replace(/\/+$/, "")
35
+ }
36
+
37
+ /**
38
+ * Public origin of the app server, without a trailing slash.
39
+ *
40
+ * Only an absolute http(s) origin is accepted. `HOST` is also the conventional
41
+ * name for a bind address, so a deployment that sets it to `0.0.0.0` would
42
+ * otherwise yield a relative `og:image` — which no crawler can resolve, and
43
+ * which would be baked into every package published from that machine.
44
+ * @returns The origin to build absolute preview URLs from.
45
+ */
46
+ export function getPublicHost(): string {
47
+ for (const raw of [process.env.PUBLIC_HOST, process.env.HOST]) {
48
+ const cleaned = normalizeOrigin(raw)
49
+ if (/^https?:\/\/\S+$/.test(cleaned)) {
50
+ return cleaned
51
+ }
52
+ }
53
+
54
+ return PRODUCTION_PUBLIC_HOST
55
+ }
56
+
57
+ /**
58
+ * Neutral brand card, used as `og:image` when a course has no preview of its own.
59
+ *
60
+ * It has to be a raster image: no unfurl crawler renders SVG. The previous
61
+ * fallback pointed at `learnpack.svg` on raw.githubusercontent.com, which fails
62
+ * twice over — SVG is unsupported, and that host serves it as `text/plain` with
63
+ * `X-Content-Type-Options: nosniff`.
64
+ */
65
+ export function getFallbackPreviewUrl(): string {
66
+ return `${getPublicHost()}/og-image.png`
67
+ }
68
+
69
+ /**
70
+ * Copy for the link preview of a draft course.
71
+ *
72
+ * A draft is unlisted work in progress, so the card carries branding only: it
73
+ * must not disclose the title, the description or anything else about the
74
+ * course, and the pages that use it are served `noindex`.
75
+ */
76
+ export const DRAFT_PREVIEW_TITLE = "LearnPack — Draft course"
77
+ export const DRAFT_PREVIEW_DESCRIPTION =
78
+ "This course is still a draft and is not published yet."