@shipload/item-renderer 0.1.4 → 0.1.5
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/links.ts +5 -0
- package/src/meta.ts +2 -2
- package/test/links-meta.test.ts +8 -3
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -13,7 +13,7 @@ export { renderItem, renderFromPayload, type RenderOptions } from './render.ts'
|
|
|
13
13
|
export { renderByType, type RenderByTypeOpts } from './templates/index.ts'
|
|
14
14
|
|
|
15
15
|
// Links + meta
|
|
16
|
-
export { linkToItemPage, linkToItemImage } from './links.ts'
|
|
16
|
+
export { linkToItemPage, linkToItemImage, linkToItemSocial } from './links.ts'
|
|
17
17
|
export { itemPageMeta, svgDimensions } from './meta.ts'
|
|
18
18
|
export type { ItemPageMeta, ItemPageMetaOptions } from './meta.ts'
|
|
19
19
|
|
package/src/links.ts
CHANGED
|
@@ -17,3 +17,8 @@ export function linkToItemImage(
|
|
|
17
17
|
const payload = encodePayload(item)
|
|
18
18
|
return `${baseUrl}/item/${payload}.${ext}`
|
|
19
19
|
}
|
|
20
|
+
|
|
21
|
+
export function linkToItemSocial(item: CargoItem, baseUrl = DEFAULT_IMAGE_BASE): string {
|
|
22
|
+
const payload = encodePayload(item)
|
|
23
|
+
return `${baseUrl}/social/${payload}.png`
|
|
24
|
+
}
|
package/src/meta.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ResolvedItem } from '@shipload/sdk'
|
|
2
2
|
import type { CargoItem } from './payload/codec.ts'
|
|
3
|
-
import {
|
|
3
|
+
import { linkToItemSocial } from './links.ts'
|
|
4
4
|
import { SOCIAL_CARD_WIDTH, SOCIAL_CARD_HEIGHT } from './templates/social-card.ts'
|
|
5
5
|
|
|
6
6
|
function tierLabel(tier: string): string {
|
|
@@ -48,7 +48,7 @@ export function itemPageMeta(
|
|
|
48
48
|
return {
|
|
49
49
|
title: `${resolved.name} · Shipload Guide`,
|
|
50
50
|
description: describeItem(resolved),
|
|
51
|
-
ogImage:
|
|
51
|
+
ogImage: linkToItemSocial(item, opts?.imageBaseUrl),
|
|
52
52
|
ogImageWidth: SOCIAL_CARD_WIDTH,
|
|
53
53
|
ogImageHeight: SOCIAL_CARD_HEIGHT,
|
|
54
54
|
}
|
package/test/links-meta.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { expect, test } from 'bun:test'
|
|
2
2
|
import { resolveItem } from '@shipload/sdk'
|
|
3
|
-
import { linkToItemImage, linkToItemPage } from '../src/links.ts'
|
|
3
|
+
import { linkToItemImage, linkToItemPage, linkToItemSocial } from '../src/links.ts'
|
|
4
4
|
import { itemPageMeta } from '../src/meta.ts'
|
|
5
5
|
import { FIXTURES } from './fixtures/cargo-items.ts'
|
|
6
6
|
|
|
@@ -24,13 +24,18 @@ test('linkToItemImage builds an SVG URL', () => {
|
|
|
24
24
|
expect(url).toMatch(/\.svg$/)
|
|
25
25
|
})
|
|
26
26
|
|
|
27
|
-
test('
|
|
27
|
+
test('linkToItemSocial builds a social card URL', () => {
|
|
28
|
+
const url = linkToItemSocial(FIXTURES.iron)
|
|
29
|
+
expect(url).toMatch(/^https:\/\/item\.shiploadgame\.com\/social\/[A-Za-z0-9_-]+\.png$/)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
test('itemPageMeta produces title, description, and ogImage (social card)', () => {
|
|
28
33
|
const item = FIXTURES.iron
|
|
29
34
|
const resolved = resolveItem(item.item_id, item.stats, item.modules)
|
|
30
35
|
const meta = itemPageMeta(item, resolved)
|
|
31
36
|
expect(meta.title).toContain('Iron')
|
|
32
37
|
expect(meta.description.length).toBeGreaterThan(0)
|
|
33
|
-
expect(meta.ogImage).toMatch(/^https:\/\/item\.shiploadgame\.com\/
|
|
38
|
+
expect(meta.ogImage).toMatch(/^https:\/\/item\.shiploadgame\.com\/social\/[A-Za-z0-9_-]+\.png$/)
|
|
34
39
|
expect(meta.ogImageWidth).toBe(1200)
|
|
35
40
|
expect(meta.ogImageHeight).toBe(630)
|
|
36
41
|
})
|