-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
102 lines (92 loc) · 2.83 KB
/
Copy pathindex.js
File metadata and controls
102 lines (92 loc) · 2.83 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
99
100
101
102
import React from 'react';
import Head from '@docusaurus/Head';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';
const SITE_NAME = 'DHTMLX RichText Docs';
const PRODUCT_NAME = 'DHTMLX RichText';
const PRODUCT_URL = 'https://dhtmlx.com/docs/products/dhtmlxRichText/';
function resolveType(pathname) {
const path = (pathname || '').replace(/\/+$/, '');
if (path === '' || path === '/richtext') return 'SoftwareApplication';
if (/\/api(\/|$)/.test(path)) return 'APIReference';
return 'TechArticle';
}
function buildJsonLd({ type, title, description, url, image, siteUrl }) {
const base = {
'@context': 'https://schema.org',
headline: title,
name: title,
description,
url,
image,
inLanguage: 'en-US',
isPartOf: {
'@type': 'WebSite',
name: SITE_NAME,
url: siteUrl
}
};
if (type === 'SoftwareApplication') {
return {
'@context': 'https://schema.org',
'@type': 'SoftwareApplication',
name: PRODUCT_NAME,
description,
url,
image,
applicationCategory: 'DeveloperApplication',
operatingSystem: 'Cross-platform',
offers: {
'@type': 'Offer',
url: PRODUCT_URL,
priceCurrency: 'USD'
}
};
}
if (type === 'APIReference') {
return {
...base,
'@type': 'APIReference',
programmingModel: 'JavaScript',
about: {
'@type': 'SoftwareApplication',
name: PRODUCT_NAME,
applicationCategory: 'DeveloperApplication'
}
};
}
return {
...base,
'@type': 'TechArticle',
proficiencyLevel: 'Beginner',
dependencies: PRODUCT_NAME,
about: {
'@type': 'SoftwareApplication',
name: PRODUCT_NAME,
applicationCategory: 'DeveloperApplication'
}
};
}
export default function StructuredData({ title, description, pathname, image }) {
const { siteConfig } = useDocusaurusContext();
const { withBaseUrl } = useBaseUrlUtils();
const siteUrl = siteConfig.url + siteConfig.baseUrl.replace(/\/$/, '');
const url = siteConfig.url + withBaseUrl(pathname || '/');
const absoluteImage = image ? withBaseUrl(image, { absolute: true }) : undefined;
const type = resolveType(pathname);
const jsonLd = buildJsonLd({
type,
title,
description,
url,
image: absoluteImage,
siteUrl
});
return (
<Head>
<script type="application/ld+json">
{JSON.stringify(jsonLd)}
</script>
</Head>
);
}