Skip to content
Merged
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
12 changes: 3 additions & 9 deletions packages/documentation/lib/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
KindRouter,
type Models,
type NavigationElement,
PageEvent,
ParameterType,
type ProjectReflection,
RendererEvent,
Expand Down Expand Up @@ -162,15 +163,6 @@ export const load = (app: Application) => {
};
});

// Need the Meta Tags to be inserted first, or it causes issues with the navigation sidebar
app.renderer.hooks.on('head.begin', () => (
<>
<script>
<JSX.Raw html={`(${insertMetaTags.toString()})();`} />
</script>
</>
));

app.renderer.hooks.on('head.end', (event) => (
<>
<script>
Expand Down Expand Up @@ -305,6 +297,8 @@ export const load = (app: Application) => {
cpSync(darkModeJs.from, darkModeJs.to);
});

app.renderer.on(PageEvent.END, insertMetaTags);

app.renderer.defineRouter('kebab', KebabRouter);

app.converter.on(Converter.EVENT_CREATE_DECLARATION, insertCustomComments);
Expand Down
41 changes: 32 additions & 9 deletions packages/documentation/lib/insertMetaTags.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
export const insertMetaTags = () => {
const head = document.getElementsByTagName('head')[0];
if (head) {
head.innerHTML += `
<meta name="color-scheme" content="light dark">
<meta name="theme-color" content="light">
<meta name="docsSiteUrl" content="https://docs.coveo.com">
<meta name="docsSiteBaseUrl" content="/en">
`;
import {DocumentReflection, type PageEvent} from 'typedoc';

export const insertMetaTags = (page: PageEvent) => {
if (!page.contents) return;

const metaTags = [
'<meta name="color-scheme" content="light dark">',
'<meta name="theme-color" content="light">',
'<meta name="docsSiteUrl" content="https://docs.coveo.com">',
'<meta name="docsSiteBaseUrl" content="/en">',
];

const isHandwrittenDoc = page.model instanceof DocumentReflection;

if (!isHandwrittenDoc) {
const titleMatch = page.contents.match(/<title>\s*([^<]*)<\/title>/i);
if (titleMatch) {
const originalTitle = titleMatch[1];
const formattedName = originalTitle
.split(' | ')[0]
.replace(/([a-z0-9])([A-Z])/g, '$1 $2')
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1 $2')
.toLowerCase();
metaTags.push(
`<meta name="docsSiteMeta" content="${formattedName} reference" />`
);
}
}

page.contents = page.contents.replace(
/<\/head>/,
`${metaTags.join('\n')}\n</head>`
);
};
1 change: 1 addition & 0 deletions packages/headless/typedoc.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "Coveo Headless",
"highlightLanguages": [
"typescript",
"javascript",
Expand Down
Loading