-
Notifications
You must be signed in to change notification settings - Fork 353
Expand file tree
/
Copy pathstructured-data.service.ts
More file actions
98 lines (90 loc) · 2.86 KB
/
structured-data.service.ts
File metadata and controls
98 lines (90 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { ArticleStructuredDataModel } from "@/features/seo/models/article-structured-data.model";
import { ArticleMetadataModel } from "@/features/seo/models/article-metadata.model";
import { HowToStructuredDataModel } from "@/features/seo/models/how-to-structured-data.model";
import { HowToMetadataModel } from "@/features/seo/models/how-to-metadata.model";
import { HowToStep, ListItem, Question } from "schema-dts";
import { BreadcrumbMetadataModel } from "@/features/seo/models/breadcrumb-metadata.model";
import { BreadcrumbStructuredDataModel } from "@/features/seo/models/breadcrumb-structured-data.model";
import { FaqMetadataModel } from "@/features/seo/models/faq-metadata.model";
import { FaqStructuredDataModel } from "@/features/seo/models/faq-structured-data.model";
import { siteTree } from "@/features/seo/site-tree";
import { createUrlPath } from "@/libs/utils/path.utils";
export const generateArticleStructuredData = (
article: ArticleMetadataModel,
): ArticleStructuredDataModel => {
return {
"@context": "https://schema.org",
"@type": "TechArticle",
headline: article.title,
name: article.title,
description: article.description,
author: article.authors.map((author) => {
return {
"@type": "Person",
name: author.name,
url: author.url,
};
}),
image: article.images,
datePublished: article.datePublished,
dateModified: article.dateModified,
};
};
export const generateHowToStructuredData = (
howTo: HowToMetadataModel,
): HowToStructuredDataModel => {
const steps: HowToStep[] = howTo.steps.map((step) => {
return {
"@type": "HowToStep",
name: step.title,
text: step.description,
};
});
return {
"@context": "https://schema.org",
"@type": "HowTo",
name: howTo.title,
totalTime: howTo.totalTime,
description: howTo.description,
step: steps,
};
};
export const createBreadcrumbListItem = (segments: string[]) => {
return siteTree.originUrl + createUrlPath(segments);
};
export const generateBreadcrumbStructuredData = (
metadata: BreadcrumbMetadataModel,
): BreadcrumbStructuredDataModel => {
const itemList: ListItem[] = metadata.itemList.map((listItem) => {
return {
"@type": "ListItem",
position: listItem.position,
name: listItem.name,
item: listItem.item,
};
});
return {
"@context": "https://schema.org",
"@type": "BreadcrumbList",
itemListElement: itemList,
};
};
export const generateFaqStructuredData = (
faq: FaqMetadataModel,
): FaqStructuredDataModel => {
const mainEntity: Question[] = faq.items.map((item) => {
return {
"@type": "Question",
name: item.question,
acceptedAnswer: {
"@type": "Answer",
text: item.answer,
},
};
});
return {
"@context": "https://schema.org",
"@type": "FAQPage",
mainEntity: mainEntity,
};
};