Skip to content

Commit de6e75c

Browse files
Merge pull request #1461 from opencomponents/no-robots-option
add no robots option
2 parents 0af3023 + b2cccf6 commit de6e75c

File tree

9 files changed

+49
-7
lines changed

9 files changed

+49
-7
lines changed

preview/fakeVM.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const mockComponentHistory: ComponentHistory[] = [
7979

8080
// Mock data for Index VM (main registry page)
8181
export const mockIndexVM: IndexVm = {
82+
robots: true,
8283
availableDependencies: [
8384
{
8485
core: true,
@@ -407,6 +408,7 @@ export const mockIndexVM: IndexVm = {
407408

408409
// Mock data for Info VM (component detail page)
409410
export const mockInfoVM: InfoVm = {
411+
robots: true,
410412
parsedAuthor: {
411413
name: 'Jane Smith',
412414

src/registry/domain/options-sanitiser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface RegistryOptions<T = any>
2424
experimental?: boolean;
2525
api?: boolean;
2626
validate?: boolean;
27+
robots?: boolean;
2728
}
2829
| boolean;
2930
/**
@@ -85,6 +86,10 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
8586
typeof options.discovery === 'boolean'
8687
? options.discovery
8788
: (options.discovery?.ui ?? true);
89+
const showRobots =
90+
typeof options.discovery === 'boolean'
91+
? true
92+
: (options.discovery?.robots ?? true);
8893
const showExperimental = !showApi
8994
? false
9095
: typeof options.discovery === 'boolean'
@@ -102,7 +107,8 @@ export default function optionsSanitiser(input: RegistryOptions): Config {
102107
ui: showUI,
103108
experimental: showExperimental,
104109
api: showApi,
105-
validate: showValidation
110+
validate: showValidation,
111+
robots: showRobots
106112
};
107113

108114
if (typeof options.pollingInterval === 'undefined') {

src/registry/routes/component-info.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ function componentInfo(
8585
repositoryUrl,
8686
sandBoxDefaultQs: urlBuilder.queryString(params),
8787
title: 'Component Info',
88-
theme
88+
theme,
89+
robots: res.conf.discovery.robots
8990
})
9091
);
9192
});

src/registry/routes/component-preview.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function componentPreview(
3232
if (isHtmlRequest) {
3333
res.send(
3434
previewView({
35+
robots: res.conf.discovery.robots,
3536
component,
3637
importmap: getOcConfig(res.conf.path)?.development?.importmap,
3738
fallbackClient: res.conf.fallbackClient

src/registry/views/index.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ export default function indexView(vm: VM) {
1919
${indexJS}</script>`;
2020

2121
return (
22-
<Layout scripts={scripts} href={vm.href} title={vm.title} theme={vm.theme}>
22+
<Layout
23+
scripts={scripts}
24+
href={vm.href}
25+
title={vm.title}
26+
theme={vm.theme}
27+
robots={vm.robots}
28+
>
2329
<section class="hero">
2430
<h1>OpenComponents Registry</h1>
2531

src/registry/views/info.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface Vm {
1818
title: string;
1919
theme: 'light' | 'dark';
2020
repositoryUrl: string | null;
21+
robots: boolean;
2122
}
2223

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

226227
return (
227-
<Layout scripts={scripts} href={href} title={vm.title} theme={vm.theme}>
228+
<Layout
229+
scripts={scripts}
230+
href={href}
231+
title={vm.title}
232+
theme={vm.theme}
233+
robots={vm.robots}
234+
>
228235
<section class="hero">
229236
<nav class="breadcrumb">
230237
<a href={href}>← All components</a>

src/registry/views/partials/layout.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,18 @@ interface LayoutProps {
77
children: JSX.Element | JSX.Element[];
88
scripts: string;
99
theme: 'light' | 'dark';
10+
robots: boolean;
1011
}
1112

1213
// const imgSrc = '/logo.png';
13-
const Layout = ({ title, href, children, scripts, theme }: LayoutProps) => {
14+
const Layout = ({
15+
title,
16+
href,
17+
children,
18+
scripts,
19+
theme,
20+
robots
21+
}: LayoutProps) => {
1422
const normalizedHref = href
1523
.replace('http://', '//')
1624
.replace('https://', '//');
@@ -25,7 +33,10 @@ const Layout = ({ title, href, children, scripts, theme }: LayoutProps) => {
2533
<head>
2634
<title safe>{title}</title>
2735
<meta charset="UTF-8" />
28-
<meta name="robots" content="index, follow" />
36+
<meta
37+
name="robots"
38+
content={robots ? 'index, follow' : 'noindex, nofollow'}
39+
/>
2940
<meta name="language" content="EN" />
3041
<meta name="distribution" content="global" />
3142
<meta

src/registry/views/preview.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default function preview(vm: {
77
qs: string;
88
liveReload: string;
99
templates: TemplateInfo[];
10+
robots: boolean;
1011
importmap?: {
1112
imports?: Record<string, string>;
1213
};
@@ -167,7 +168,7 @@ export default function preview(vm: {
167168
color: #cfe3ff;
168169
}
169170
</style>
170-
<meta name="robots" content="index, follow" />
171+
<meta name="robots" content="${vm.robots ? 'index, follow' : 'noindex, nofollow'}" />
171172
<meta charset="utf-8" />
172173
<meta name="viewport" content="width=device-width, initial-scale=1" />
173174
${

src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export interface VM {
129129
title: string;
130130
theme: 'light' | 'dark';
131131
type: 'oc-registry' | 'oc-registry-local';
132+
robots: boolean;
132133
}
133134

134135
export type Authentication<T = any> = {
@@ -206,6 +207,12 @@ export interface Config<T = any> {
206207
* Configuration object to enable/disable the HTML discovery page and the API
207208
*/
208209
discovery: {
210+
/**
211+
* Appends a <meta name="robots" content="index, follow" /> to the HTML head
212+
* False to append a <meta name="robots" content="noindex, nofollow" />
213+
* @default true
214+
*/
215+
robots: boolean;
209216
/**
210217
* Enables API discovery endpoints
211218
* @default true

0 commit comments

Comments
 (0)