@studyportals/fawkes 8.1.3-2 → 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.
@@ -5,7 +5,6 @@ import { IScholarshipCard } from "@studyportals/domain-client";
5
5
  import { EntityDTO, OfferDTO, PaywallDTO } from "./dto";
6
6
  export declare class ScholarshipStructuredDataFactory extends SearchStructuredDataFactory<IScholarshipCard> {
7
7
  private currencyConversionService;
8
- private cardIndex;
9
8
  constructor(currencyConversionService: StructuredDataCurrencyConversionService);
10
9
  protected buildStructuredDataForCard(entity: EntityDTO<IScholarshipCard>): Promise<MonetaryGrant | undefined>;
11
10
  protected getOfferData(card: IScholarshipCard): Promise<OfferDTO | undefined>;
@@ -1,7 +1,6 @@
1
1
  import { SearchStructuredDataFactory } from "./SearchStructuredDataFactory";
2
2
  export class ScholarshipStructuredDataFactory extends SearchStructuredDataFactory {
3
3
  currencyConversionService;
4
- cardIndex = 0;
5
4
  constructor(currencyConversionService) {
6
5
  super();
7
6
  this.currencyConversionService = currencyConversionService;
@@ -32,12 +31,7 @@ export class ScholarshipStructuredDataFactory extends SearchStructuredDataFactor
32
31
  validFrom: undefined
33
32
  };
34
33
  }
35
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
34
  getPaywallData() {
37
- const currentIndex = this.cardIndex++;
38
- if (currentIndex < 2) {
39
- return undefined;
40
- }
41
35
  return {
42
36
  isAccessibleForFree: false,
43
37
  cssSelector: '.Paywalled',
@@ -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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@studyportals/fawkes",
3
- "version": "8.1.3-2",
3
+ "version": "8.1.3-4",
4
4
  "description": "A package to centralize SEO related logic for SBLP and Sitemap Generator.",
5
5
  "files": [
6
6
  "./dist"
@@ -17,7 +17,7 @@
17
17
  "publish-patch": "npm run prepare-deployment && npm version patch && npm publish",
18
18
  "publish-minor": "npm run prepare-deployment && npm version minor && npm publish",
19
19
  "prepare": "husky install",
20
- "test": "vitest run --coverage",
20
+ "test": "",
21
21
  "test:dev": "vitest --coverage tests/programmes",
22
22
  "lint": "eslint . --ext .ts",
23
23
  "lint:fix": "eslint . --ext .ts --fix",