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
2 changes: 2 additions & 0 deletions preview/fakeVM.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const mockComponentHistory: ComponentHistory[] = [

// Mock data for Index VM (main registry page)
export const mockIndexVM: IndexVm = {
robots: true,
availableDependencies: [
{
core: true,
Expand Down Expand Up @@ -407,6 +408,7 @@ export const mockIndexVM: IndexVm = {

// Mock data for Info VM (component detail page)
export const mockInfoVM: InfoVm = {
robots: true,
parsedAuthor: {
name: 'Jane Smith',
email: 'jane.smith@company.com',
Expand Down
8 changes: 7 additions & 1 deletion src/registry/domain/options-sanitiser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface RegistryOptions<T = any>
experimental?: boolean;
api?: boolean;
validate?: boolean;
robots?: boolean;
}
| boolean;
/**
Expand Down Expand Up @@ -85,6 +86,10 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
typeof options.discovery === 'boolean'
? options.discovery
: (options.discovery?.ui ?? true);
const showRobots =
typeof options.discovery === 'boolean'
? true
: (options.discovery?.robots ?? true);
const showExperimental = !showApi
? false
: typeof options.discovery === 'boolean'
Expand All @@ -102,7 +107,8 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
ui: showUI,
experimental: showExperimental,
api: showApi,
validate: showValidation
validate: showValidation,
robots: showRobots
};

if (typeof options.pollingInterval === 'undefined') {
Expand Down
3 changes: 2 additions & 1 deletion src/registry/routes/component-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ function componentInfo(
repositoryUrl,
sandBoxDefaultQs: urlBuilder.queryString(params),
title: 'Component Info',
theme
theme,
robots: res.conf.discovery.robots
})
);
});
Expand Down
1 change: 1 addition & 0 deletions src/registry/routes/component-preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function componentPreview(
if (isHtmlRequest) {
res.send(
previewView({
robots: res.conf.discovery.robots,
component,
importmap: getOcConfig(res.conf.path)?.development?.importmap,
fallbackClient: res.conf.fallbackClient
Expand Down
8 changes: 7 additions & 1 deletion src/registry/views/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ export default function indexView(vm: VM) {
${indexJS}</script>`;

return (
<Layout scripts={scripts} href={vm.href} title={vm.title} theme={vm.theme}>
<Layout
scripts={scripts}
href={vm.href}
title={vm.title}
theme={vm.theme}
robots={vm.robots}
>
<section class="hero">
<h1>OpenComponents Registry</h1>

Expand Down
9 changes: 8 additions & 1 deletion src/registry/views/info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface Vm {
title: string;
theme: 'light' | 'dark';
repositoryUrl: string | null;
robots: boolean;
}

function formatDate(date: Date | string) {
Expand Down Expand Up @@ -224,7 +225,13 @@ export default function Info(vm: Vm) {
`;

return (
<Layout scripts={scripts} href={href} title={vm.title} theme={vm.theme}>
<Layout
scripts={scripts}
href={href}
title={vm.title}
theme={vm.theme}
robots={vm.robots}
>
<section class="hero">
<nav class="breadcrumb">
<a href={href}>← All components</a>
Expand Down
15 changes: 13 additions & 2 deletions src/registry/views/partials/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,18 @@ interface LayoutProps {
children: JSX.Element | JSX.Element[];
scripts: string;
theme: 'light' | 'dark';
robots: boolean;
}

// const imgSrc = '/logo.png';
const Layout = ({ title, href, children, scripts, theme }: LayoutProps) => {
const Layout = ({
title,
href,
children,
scripts,
theme,
robots
}: LayoutProps) => {
const normalizedHref = href
.replace('http://', '//')
.replace('https://', '//');
Expand All @@ -25,7 +33,10 @@ const Layout = ({ title, href, children, scripts, theme }: LayoutProps) => {
<head>
<title safe>{title}</title>
<meta charset="UTF-8" />
<meta name="robots" content="index, follow" />
<meta
name="robots"
content={robots ? 'index, follow' : 'noindex, nofollow'}
/>
<meta name="language" content="EN" />
<meta name="distribution" content="global" />
<meta
Expand Down
3 changes: 2 additions & 1 deletion src/registry/views/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default function preview(vm: {
qs: string;
liveReload: string;
templates: TemplateInfo[];
robots: boolean;
importmap?: {
imports?: Record<string, string>;
};
Expand Down Expand Up @@ -167,7 +168,7 @@ export default function preview(vm: {
color: #cfe3ff;
}
</style>
<meta name="robots" content="index, follow" />
<meta name="robots" content="${vm.robots ? 'index, follow' : 'noindex, nofollow'}" />
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
${
Expand Down
7 changes: 7 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export interface VM {
title: string;
theme: 'light' | 'dark';
type: 'oc-registry' | 'oc-registry-local';
robots: boolean;
}

export type Authentication<T = any> = {
Expand Down Expand Up @@ -206,6 +207,12 @@ export interface Config<T = any> {
* Configuration object to enable/disable the HTML discovery page and the API
*/
discovery: {
/**
* Appends a <meta name="robots" content="index, follow" /> to the HTML head
* False to append a <meta name="robots" content="noindex, nofollow" />
* @default true
*/
robots: boolean;
/**
* Enables API discovery endpoints
* @default true
Expand Down