@techninja/clearstack 0.3.45 → 0.3.47
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/lib/og-image-template.js
CHANGED
|
@@ -79,12 +79,16 @@ export function buildContext(config, itemData, site) {
|
|
|
79
79
|
const emoji = /** @type {string} */ (item.emoji || itemData.emoji || '');
|
|
80
80
|
const tags = /** @type {string[]} */ (item.tags || itemData.tags || []);
|
|
81
81
|
const tagsHtml = tags.map((t) => `<div class="tag">#${t}</div>`).join('');
|
|
82
|
-
const postTitle = item.title || item.caption || item.name || '';
|
|
83
|
-
const
|
|
82
|
+
const postTitle = /** @type {string} */ (item.title || item.caption || item.name || '');
|
|
83
|
+
const logo = /** @type {{wordmark?: string, mark?: string}} */ (item.logo || {});
|
|
84
|
+
const logoSrc = logo.wordmark || logo.mark || '';
|
|
84
85
|
const itemLogoHtml = logoSrc ? `<img src="${logoSrc}" alt="${postTitle}">` : '';
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
86
|
+
const rawDate = /** @type {string|number} */ (item.date || '');
|
|
87
|
+
const dateFormatted = rawDate ? new Date(rawDate).toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' }) : '';
|
|
88
|
+
const files = /** @type {string[]} */ (item.files || []);
|
|
89
|
+
const mediaUrl = resolvedImage || (files[0] ? `https://data.tn42.com/assets-media/${files[0]}` : '');
|
|
90
|
+
const isVideo = item.type === 'video' || (files[0] || '').endsWith('.mp4');
|
|
91
|
+
const price = /** @type {number} */ (item.price || 0);
|
|
88
92
|
|
|
89
93
|
return {
|
|
90
94
|
...itemData, ...item,
|
|
@@ -105,7 +109,7 @@ export function buildContext(config, itemData, site) {
|
|
|
105
109
|
: mediaUrl ? `<img src="${mediaUrl}" style="position:absolute;inset:0;width:100%;height:100%;object-fit:cover">` : '',
|
|
106
110
|
variantsFormatted: formatNum(item.expected_variants),
|
|
107
111
|
uniqueFormatted: formatNum(item.estimated_unique_variants),
|
|
108
|
-
priceFormatted:
|
|
112
|
+
priceFormatted: price ? `$${(price / 100).toFixed(2)}` : '',
|
|
109
113
|
imageHtml: resolvedImage ? `<img class="hero" src="${resolvedImage}">` : '',
|
|
110
114
|
cardClass: resolvedImage ? 'card-with-image' : '',
|
|
111
115
|
siteLogo: site.logo ? `<img class="logo" src="${site.logo}">` : '',
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import express from 'express';
|
|
7
|
+
import { watch } from 'node:fs';
|
|
7
8
|
import { entityRouter } from './api/entities.js';
|
|
8
9
|
import { eventsRouter } from './api/events.js';
|
|
9
10
|
|
|
@@ -14,6 +15,20 @@ app.use(express.json());
|
|
|
14
15
|
app.use('/api', eventsRouter);
|
|
15
16
|
app.use('/api', entityRouter);
|
|
16
17
|
|
|
18
|
+
/** @type {Set<import('node:http').ServerResponse>} */
|
|
19
|
+
const reloadClients = new Set();
|
|
20
|
+
|
|
21
|
+
app.get('/_reload', (req, res) => {
|
|
22
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
|
|
23
|
+
res.write(': connected\n\n');
|
|
24
|
+
reloadClients.add(res);
|
|
25
|
+
req.on('close', () => reloadClients.delete(res));
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
watch('src', { recursive: true }, () => {
|
|
29
|
+
for (const res of reloadClients) res.write('event: reload\ndata: {}\n\n');
|
|
30
|
+
});
|
|
31
|
+
|
|
17
32
|
app.use(express.static('src'));
|
|
18
33
|
|
|
19
34
|
// SPA fallback
|
|
@@ -38,6 +38,12 @@
|
|
|
38
38
|
<app-router></app-router>
|
|
39
39
|
<script type="module" src="/router/index.js"></script>
|
|
40
40
|
<script>
|
|
41
|
+
// Hot reload
|
|
42
|
+
(function () {
|
|
43
|
+
const es = new EventSource('/_reload');
|
|
44
|
+
es.addEventListener('reload', () => location.reload());
|
|
45
|
+
es.onerror = () => { es.close(); setTimeout(() => location.reload(), 500); };
|
|
46
|
+
})();
|
|
41
47
|
// Global error boundary — catches unhandled promise rejections and JS errors
|
|
42
48
|
window.addEventListener('unhandledrejection', (e) => {
|
|
43
49
|
console.error('[app] Unhandled rejection:', e.reason);
|
|
@@ -4,10 +4,25 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import express from 'express';
|
|
7
|
+
import { watch } from 'node:fs';
|
|
7
8
|
|
|
8
9
|
/** @type {any} */
|
|
9
10
|
const app = express();
|
|
10
11
|
|
|
12
|
+
/** @type {Set<import('node:http').ServerResponse>} */
|
|
13
|
+
const reloadClients = new Set();
|
|
14
|
+
|
|
15
|
+
app.get('/_reload', (req, res) => {
|
|
16
|
+
res.writeHead(200, { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache', Connection: 'keep-alive' });
|
|
17
|
+
res.write(': connected\n\n');
|
|
18
|
+
reloadClients.add(res);
|
|
19
|
+
req.on('close', () => reloadClients.delete(res));
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
watch('src', { recursive: true }, () => {
|
|
23
|
+
for (const res of reloadClients) res.write('event: reload\ndata: {}\n\n');
|
|
24
|
+
});
|
|
25
|
+
|
|
11
26
|
app.use(express.static('src'));
|
|
12
27
|
|
|
13
28
|
app.use((req, res, next) => {
|