@studyportals/fawkes 8.1.3-3 → 8.1.3-4
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.
|
@@ -6,7 +6,8 @@ import { FAQItemDto } from './dto/FAQItemDto';
|
|
|
6
6
|
import { BreadcrumbDTO } from './dto/BreadcrumbDTO';
|
|
7
7
|
import { PaywallDTO } from './dto/PaywallDTO';
|
|
8
8
|
export declare abstract class SearchStructuredDataFactory<TCard> {
|
|
9
|
-
buildStructuredData(title: string, description: string, cards: TCard[], faqItems?: FAQItemDto[], breadcrumbs?: BreadcrumbDTO[]): Promise<WithContext<SearchResultsPage>>;
|
|
9
|
+
buildStructuredData(title: string, description: string, cards: TCard[], faqItems?: FAQItemDto[], breadcrumbs?: BreadcrumbDTO[], listItemStructure?: boolean): Promise<WithContext<SearchResultsPage>>;
|
|
10
|
+
private generateMainEntities;
|
|
10
11
|
protected abstract buildStructuredDataForCard(entity: EntityDTO<TCard>): Promise<Thing | undefined> | Thing | undefined;
|
|
11
12
|
/**
|
|
12
13
|
* Get the rating for a card.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export class SearchStructuredDataFactory {
|
|
2
|
-
async buildStructuredData(title, description, cards, faqItems = [], breadcrumbs = []) {
|
|
2
|
+
async buildStructuredData(title, description, cards, faqItems = [], breadcrumbs = [], listItemStructure) {
|
|
3
3
|
const entities = [];
|
|
4
4
|
const ratings = [];
|
|
5
5
|
const offersData = [];
|
|
@@ -12,13 +12,7 @@ export class SearchStructuredDataFactory {
|
|
|
12
12
|
offersData.push(offer);
|
|
13
13
|
entities.push({ card, offer, reviewRating });
|
|
14
14
|
}
|
|
15
|
-
const mainEntities =
|
|
16
|
-
for (const entity of entities) {
|
|
17
|
-
const structuredData = await this.buildStructuredDataForCard(entity);
|
|
18
|
-
if (!structuredData)
|
|
19
|
-
continue;
|
|
20
|
-
mainEntities.push(structuredData);
|
|
21
|
-
}
|
|
15
|
+
const mainEntities = await this.generateMainEntities(entities, listItemStructure);
|
|
22
16
|
const data = {
|
|
23
17
|
'@context': 'https://schema.org',
|
|
24
18
|
'@type': 'SearchResultsPage',
|
|
@@ -35,6 +29,28 @@ export class SearchStructuredDataFactory {
|
|
|
35
29
|
}
|
|
36
30
|
return data;
|
|
37
31
|
}
|
|
32
|
+
async generateMainEntities(entities, listItemStructure) {
|
|
33
|
+
const mainEntities = [];
|
|
34
|
+
for (const entity of entities) {
|
|
35
|
+
const structuredData = await this.buildStructuredDataForCard(entity);
|
|
36
|
+
if (!structuredData)
|
|
37
|
+
continue;
|
|
38
|
+
mainEntities.push(structuredData);
|
|
39
|
+
}
|
|
40
|
+
if (listItemStructure) {
|
|
41
|
+
const listItems = mainEntities.map((entity, index) => ({
|
|
42
|
+
'@type': 'ListItem',
|
|
43
|
+
'position': index + 1,
|
|
44
|
+
'item': entity
|
|
45
|
+
}));
|
|
46
|
+
return [{
|
|
47
|
+
'@type': 'ItemList',
|
|
48
|
+
'numberOfItems': mainEntities.length,
|
|
49
|
+
'itemListElement': listItems
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
return mainEntities;
|
|
53
|
+
}
|
|
38
54
|
/**
|
|
39
55
|
* Get the rating for a card.
|
|
40
56
|
* This method should be overridden by subclasses to provide the specific rating logic.
|