@shipload/item-renderer 0.1.1 → 0.1.2
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/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/meta.ts +16 -0
- package/test/links-meta.test.ts +2 -2
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -14,7 +14,7 @@ export { renderByType, type RenderByTypeOpts } from './templates/index.ts'
|
|
|
14
14
|
|
|
15
15
|
// Links + meta
|
|
16
16
|
export { linkToItemPage, linkToItemImage } from './links.ts'
|
|
17
|
-
export { itemPageMeta } from './meta.ts'
|
|
17
|
+
export { itemPageMeta, svgDimensions } from './meta.ts'
|
|
18
18
|
export type { ItemPageMeta, ItemPageMetaOptions } from './meta.ts'
|
|
19
19
|
|
|
20
20
|
// Tokens (consumed by testmap tailwind.config)
|
package/src/meta.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ResolvedItem } from '@shipload/sdk'
|
|
2
2
|
import type { CargoItem } from './payload/codec.ts'
|
|
3
3
|
import { linkToItemImage } from './links.ts'
|
|
4
|
+
import { renderItem } from './render.ts'
|
|
4
5
|
|
|
5
6
|
function tierLabel(tier: string): string {
|
|
6
7
|
return tier.toUpperCase()
|
|
@@ -19,14 +20,25 @@ function describeItem(resolved: ResolvedItem): string {
|
|
|
19
20
|
return parts.join(' · ')
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
const DIMS_RE = /<svg[^>]*?\bwidth="(\d+)"[^>]*?\bheight="(\d+)"/
|
|
24
|
+
|
|
25
|
+
export function svgDimensions(svg: string): { width: number; height: number } {
|
|
26
|
+
const m = DIMS_RE.exec(svg)
|
|
27
|
+
if (!m) throw new Error('svgDimensions: could not locate width/height on root <svg>')
|
|
28
|
+
return { width: Number(m[1]), height: Number(m[2]) }
|
|
29
|
+
}
|
|
30
|
+
|
|
22
31
|
export interface ItemPageMeta {
|
|
23
32
|
title: string
|
|
24
33
|
description: string
|
|
25
34
|
ogImage: string
|
|
35
|
+
ogImageWidth: number
|
|
36
|
+
ogImageHeight: number
|
|
26
37
|
}
|
|
27
38
|
|
|
28
39
|
export interface ItemPageMetaOptions {
|
|
29
40
|
imageBaseUrl?: string
|
|
41
|
+
svg?: string
|
|
30
42
|
}
|
|
31
43
|
|
|
32
44
|
export function itemPageMeta(
|
|
@@ -34,9 +46,13 @@ export function itemPageMeta(
|
|
|
34
46
|
resolved: ResolvedItem,
|
|
35
47
|
opts?: ItemPageMetaOptions,
|
|
36
48
|
): ItemPageMeta {
|
|
49
|
+
const svg = opts?.svg ?? renderItem(item, resolved)
|
|
50
|
+
const { width, height } = svgDimensions(svg)
|
|
37
51
|
return {
|
|
38
52
|
title: `${resolved.name} · Shipload Guide`,
|
|
39
53
|
description: describeItem(resolved),
|
|
40
54
|
ogImage: linkToItemImage(item, 'png', opts?.imageBaseUrl),
|
|
55
|
+
ogImageWidth: width,
|
|
56
|
+
ogImageHeight: height,
|
|
41
57
|
}
|
|
42
58
|
}
|
package/test/links-meta.test.ts
CHANGED
|
@@ -16,7 +16,7 @@ test('linkToItemPage accepts a custom base URL', () => {
|
|
|
16
16
|
|
|
17
17
|
test('linkToItemImage builds a PNG URL', () => {
|
|
18
18
|
const url = linkToItemImage(FIXTURES.iron, 'png')
|
|
19
|
-
expect(url).toMatch(/^https:\/\/
|
|
19
|
+
expect(url).toMatch(/^https:\/\/item\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
|
|
20
20
|
})
|
|
21
21
|
|
|
22
22
|
test('linkToItemImage builds an SVG URL', () => {
|
|
@@ -30,5 +30,5 @@ test('itemPageMeta produces title, description, and ogImage', () => {
|
|
|
30
30
|
const meta = itemPageMeta(item, resolved)
|
|
31
31
|
expect(meta.title).toContain('Iron')
|
|
32
32
|
expect(meta.description.length).toBeGreaterThan(0)
|
|
33
|
-
expect(meta.ogImage).toMatch(/^https:\/\/
|
|
33
|
+
expect(meta.ogImage).toMatch(/^https:\/\/item\.shiploadgame\.com\/item\/[A-Za-z0-9_-]+\.png$/)
|
|
34
34
|
})
|