@terrafirmagreg-team/recipe 1.2.20 → 1.2.21

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/src/lib/og.ts +22 -44
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@terrafirmagreg-team/recipe",
3
- "version": "1.2.20",
3
+ "version": "1.2.21",
4
4
  "type": "module",
5
5
  "description": "Recipe viewer and calculator",
6
6
  "license": "LGPL-3.0-only",
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@terrafirmagreg-team/data": "^1.2.10",
27
- "@terrafirmagreg-team/dump": "^1.2.14",
28
- "@terrafirmagreg-team/game": "^1.2.8",
27
+ "@terrafirmagreg-team/dump": "^1.2.15",
28
+ "@terrafirmagreg-team/game": "^1.2.9",
29
29
  "@terrafirmagreg-team/kit": "^1.2.22",
30
30
  "@terrafirmagreg-team/mdx": "^1.2.11",
31
- "@terrafirmagreg-team/preview": "^1.2.5",
31
+ "@terrafirmagreg-team/preview": "^1.2.6",
32
32
  "@terrafirmagreg-team/sites": "^1.2.3",
33
33
  "@terrafirmagreg-team/translate": "^1.2.11",
34
34
  "@terrafirmagreg-team/ui": "^1.2.16",
package/src/lib/og.ts CHANGED
@@ -2,14 +2,13 @@ import type { DatasetRef } from '@terrafirmagreg-team/sites/location';
2
2
  import type { Lang } from '@terrafirmagreg-team/translate/types/locale';
3
3
  import { clientDumpLang } from '@terrafirmagreg-team/dump/lib/dump/client/dump';
4
4
  import { loadClientTagMembers } from '@terrafirmagreg-team/dump/lib/dump/client/tags';
5
- import type { ReferenceKind } from '@terrafirmagreg-team/dump/lib/dump/contract/ref';
6
5
  import { stripMcFormat } from '@terrafirmagreg-team/dump/lib/dump/assets/lang/names';
7
6
  import {
8
7
  ogLocalized,
9
- ogRefSprite,
10
8
  ogStackName,
11
9
  } from '@terrafirmagreg-team/dump/lib/dump/assets/og';
12
10
  import {
11
+ ogImageQuery,
13
12
  ogName,
14
13
  registerOgResolver,
15
14
  type OgContext,
@@ -25,25 +24,23 @@ async function recipeOgContext(
25
24
  ): Promise<OgContext> {
26
25
  const tool = search.get('tool');
27
26
  if (tool) {
28
- return {
29
- entity: { kind: 'tool', name: recipeToolName(tool, lang) },
30
- imageQuery: `tool=${encodeURIComponent(tool)}`,
31
- };
27
+ const entity = { kind: 'tool', name: recipeToolName(tool, lang) };
28
+ return { entity, imageQuery: ogImageQuery(entity, tool) };
32
29
  }
33
30
  const item = search.get('item');
34
31
  const fluid = search.get('fluid');
35
32
  if (item || fluid) {
36
33
  const kind = fluid ? 'fluid' : 'item';
37
34
  const id = (item ?? fluid)!;
35
+ const entity = {
36
+ kind,
37
+ name: await ogStackName(dataset, id, kind, lang),
38
+ id,
39
+ };
38
40
  return {
39
- entity: {
40
- kind,
41
- name: await ogStackName(dataset, id, kind, lang),
42
- id,
43
- },
44
- icon: () => ogRefSprite(dataset, { kind, id }),
41
+ entity,
45
42
  description: id,
46
- imageQuery: `${kind}=${encodeURIComponent(id)}`,
43
+ imageQuery: ogImageQuery(entity, id),
47
44
  };
48
45
  }
49
46
  const type = search.get('type');
@@ -57,22 +54,12 @@ async function recipeOgContext(
57
54
  const tagId = rest.length ? `${ns}:${tagPath}` : ns;
58
55
  const members = await loadClientTagMembers(dataset, tagKind);
59
56
  const list = tagId ? members?.[`#${tagId}`] : undefined;
60
- const first = list?.[0];
61
- return {
62
- entity: { kind: 'tag', name: `#${tagId || id}`, id },
63
- icon: first
64
- ? () =>
65
- ogRefSprite(dataset, {
66
- kind: tagKind as ReferenceKind,
67
- id: first,
68
- })
69
- : undefined,
70
- description:
71
- list != null
72
- ? `${list.length} member${list.length === 1 ? '' : 's'}`
73
- : `${tagKind} tag`,
74
- imageQuery: `type=emi:tag&id=${encodeURIComponent(id)}`,
75
- };
57
+ const entity = { kind: 'tag', name: `#${tagId || id}`, id };
58
+ const description =
59
+ list != null
60
+ ? `${list.length} member${list.length === 1 ? '' : 's'}`
61
+ : `${tagKind} tag`;
62
+ return { entity, description, imageQuery: ogImageQuery(entity, description) };
76
63
  }
77
64
  if (id) {
78
65
  const recipe = await loadClientRecipe(dataset, id);
@@ -96,18 +83,9 @@ async function recipeOgContext(
96
83
  lang,
97
84
  ).catch(() => recipe.id)
98
85
  : recipe.id;
99
- return {
100
- entity: { kind: 'recipe', name, id: recipe.id },
101
- icon: out
102
- ? () =>
103
- ogRefSprite(dataset, {
104
- kind: out.kind === 'tag' ? 'itemTag' : out.kind,
105
- id: out.id,
106
- })
107
- : undefined,
108
- description: catName ?? recipe.id,
109
- imageQuery: `id=${encodeURIComponent(id)}`,
110
- };
86
+ const entity = { kind: 'recipe', name, id: recipe.id };
87
+ const description = catName ?? recipe.id;
88
+ return { entity, description, imageQuery: ogImageQuery(entity, description) };
111
89
  }
112
90
  if (!type || type === 'all') return {};
113
91
  const [categories, map] = await Promise.all([
@@ -118,11 +96,11 @@ async function recipeOgContext(
118
96
  if (!category) return {};
119
97
  const localized =
120
98
  ogLocalized(map, category.display?.name) ?? category.id;
99
+ const entity = { kind: 'category', ...ogName(localized), id: category.id };
121
100
  return {
122
- entity: { kind: 'category', ...ogName(localized), id: category.id },
123
- icon: () => ogRefSprite(dataset, category.icon),
101
+ entity,
124
102
  description: category.id,
125
- imageQuery: `type=${encodeURIComponent(type)}`,
103
+ imageQuery: ogImageQuery(entity, category.id),
126
104
  };
127
105
  }
128
106