Skip to content
Merged

Next #107

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ module.exports = {
}
},
themeConfig: {
image: 'img/og-default-suite.png',
metadata: [
{ property: 'og:type', content: 'website' },
{ property: 'og:site_name', content: 'DHTMLX Suite Docs' },
{ property: 'og:locale', content: 'en_US' },
{ name: 'twitter:card', content: 'summary_large_image' },
{ name: 'twitter:site', content: '@dhtmlx' }
],
algolia: {
// This is a read-only, search-only key served directly by the front-end, managed by Algolia via their
// free DocSearch program. The key is not sensitive. See https://docsearch.algolia.com/ for more details.
Expand Down
102 changes: 102 additions & 0 deletions src/components/StructuredData/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import React from 'react';
import Head from '@docusaurus/Head';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import { useBaseUrlUtils } from '@docusaurus/useBaseUrl';

const SITE_NAME = 'DHTMLX Suite Docs';
const PRODUCT_NAME = 'DHTMLX Suite';
const PRODUCT_URL = 'https://dhtmlx.com/docs/products/dhtmlxSuite/';

function resolveType(pathname) {
const path = (pathname || '').replace(/\/+$/, '');
if (path === '' || path === '/suite') 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>
);
}
31 changes: 31 additions & 0 deletions src/theme/DocItem/Metadata/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';
import Head from '@docusaurus/Head';
import { useLocation } from '@docusaurus/router';
import DocItemMetadata from '@theme-original/DocItem/Metadata';
import { useDoc } from '@docusaurus/plugin-content-docs/client';
import StructuredData from '@site/src/components/StructuredData';

export default function DocItemMetadataWrapper(props) {
const { metadata, frontMatter, assets } = useDoc();
const { pathname } = useLocation();

const title = metadata.title;
const description = metadata.description;
const image = assets.image ?? frontMatter.image;

return (
<>
<DocItemMetadata {...props} />
<Head>
{title && <meta name="twitter:title" content={title} />}
{description && <meta name="twitter:description" content={description} />}
</Head>
<StructuredData
title={title}
description={description}
pathname={pathname}
image={image}
/>
</>
);
}
Binary file added static/img/og-default-suite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading