Skip to content

Commit 77f8dbf

Browse files
committed
fix: preserve label of ItemURLs when using ItemBuilder.addUrl (#119)
1 parent 3601248 commit 77f8dbf

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/lib/builders.ts

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface ItemFieldOptions {
2424
recipe?: GeneratorRecipe;
2525
}
2626

27+
interface BuilderUrls {
28+
primaryUrl: string;
29+
itemUrls: ItemUrls[];
30+
}
31+
2732
export class ItemBuilder {
2833
/**
2934
* Empty Item under construction.
@@ -38,7 +43,7 @@ export class ItemBuilder {
3843
* @private
3944
*/
4045
private sections: Map<string, FullItemAllOfSections>;
41-
private urls: { [key: string]: any };
46+
private urls: BuilderUrls;
4247

4348
public constructor() {
4449
this.reset();
@@ -54,10 +59,10 @@ export class ItemBuilder {
5459

5560
this.item.sections = Array.from(this.sections.values());
5661

57-
this.item.urls = this.urls.hrefs.map((href) =>
62+
this.item.urls = this.urls.itemUrls.map(({ label, href }) =>
5863
this.urls.primaryUrl === href
59-
? ({ primary: true, href } as ItemUrls)
60-
: ({ href } as ItemUrls),
64+
? { primary: true, label, href }
65+
: { label, href },
6166
);
6267
const builtItem = cloneDeep(this.item);
6368
debug(
@@ -78,7 +83,7 @@ export class ItemBuilder {
7883
this.item.tags = [];
7984

8085
this.sections = new Map();
81-
this.urls = { primaryUrl: "", hrefs: [] };
86+
this.urls = { primaryUrl: "", itemUrls: [] };
8287
}
8388

8489
/**
@@ -182,8 +187,9 @@ export class ItemBuilder {
182187
* @returns {ItemBuilder}
183188
*/
184189
public addUrl(url: ItemUrls): ItemBuilder {
185-
if (url.primary) this.urls.primaryUrl = url.href;
186-
this.urls.hrefs.push(url.href);
190+
const { primary, label, href } = url;
191+
if (primary) this.urls.primaryUrl = href;
192+
this.urls.itemUrls.push({ label, href });
187193
return this;
188194
}
189195

0 commit comments

Comments
 (0)