Skip to content

Commit 3d8169b

Browse files
Mariia MarchenkovaMariia Marchenkova
authored andcommitted
feat: option to add web name into title
1 parent be7238c commit 3d8169b

File tree

11 files changed

+43
-3
lines changed

11 files changed

+43
-3
lines changed

example/__fixtures__/custom/Custom.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export default class Custom extends React.Component<{}> {
1616

1717
export const meta = {
1818
title: 'Custom 🎉',
19+
webTitle: 'Component Docs',
1920
description: 'Custom React Component',
2021
link: 'custom-component',
2122
};

example/__fixtures__/markdown/1.Home.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
---
22
link: index
3+
webTitle: Component Docs
4+
divider: ·
35
description: Simple documentation for your React components.
46
---
57

src/parsers/component.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ export default function component(
9292
return {
9393
filepath: path.relative(root, filepath),
9494
title: name,
95+
webTitle: info.webTitle,
96+
divider: info.divider,
9597
description: info.description,
9698
link: dashify(name),
9799
data: info,

src/parsers/custom.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ export default function custom(
1919
const meta = exported.meta || {};
2020

2121
const title = meta.title || name;
22+
const webTitle = meta.webTitle;
23+
const divider = meta.divider;
2224
const description = meta.description;
2325
const link = meta.link || dashify(name);
2426
const type = 'custom';
2527

2628
return {
2729
filepath: path.relative(root, filepath),
2830
title,
31+
webTitle,
32+
divider,
2933
description,
3034
type,
3135
link,
@@ -38,6 +42,8 @@ export default function custom(
3842
var m = e.meta || {};
3943
return {
4044
title: m.title || ${JSON.stringify(title)},
45+
webTitle: m.webTitle,
46+
divider: m.divider,
4147
link: m.link || ${JSON.stringify(link)},
4248
description: m.description,
4349
type: ${JSON.stringify(type)},

src/parsers/md.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export default function md(
3939
return {
4040
filepath: path.relative(root, filepath),
4141
title,
42+
webTitle: meta.webTitle || '',
43+
divider: meta.divider || ' ',
4244
description: meta.description || '',
4345
link: meta.link || dashify(title),
4446
data,

src/parsers/mdx.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,17 @@ export default function(
7373
component.displayName ||
7474
component.name ||
7575
getNameFromPath(filepath);
76+
const webTitle = meta.webTitle || '';
77+
const divider = meta.divider || ' ';
7678
const description = meta.description || '';
7779
const link = meta.link || dashify(title);
7880
const type = 'custom';
7981

8082
return {
8183
filepath: path.relative(root, filepath),
8284
title,
85+
webTitle,
86+
divider,
8387
description,
8488
type,
8589
link,
@@ -123,6 +127,8 @@ ${result};
123127
return {
124128
title: meta.title || ${JSON.stringify(title)},
125129
link: meta.link || ${JSON.stringify(link)},
130+
webTitle: meta.webTitle || ${JSON.stringify(webTitle)},
131+
divider: meta.divider || ${JSON.stringify(divider)},
126132
description: meta.description,
127133
type: ${JSON.stringify(type)},
128134
data: function MDXContent(props) {

src/templates/HTML.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,21 @@ import * as React from 'react';
55

66
type Props = {
77
title: string,
8+
webTitle: string,
9+
divider: string,
810
description: string,
911
body: string,
1012
sheets: string[],
1113
};
1214

13-
export default function HTML({ title, description, body, sheets }: Props) {
15+
export default function HTML({
16+
title,
17+
webTitle,
18+
divider = ' ',
19+
description,
20+
body,
21+
sheets,
22+
}: Props) {
1423
return (
1524
<html lang="en">
1625
<head>
@@ -30,9 +39,12 @@ export default function HTML({ title, description, body, sheets }: Props) {
3039

3140
<meta property="og:type" content="website" />
3241
<meta property="og:title" content={title} />
42+
<meta property="og:webTitle" content={webTitle} />
3343
<meta property="og:description" content={description} />
3444

35-
<title>{title}</title>
45+
<title>
46+
{title} {divider} {webTitle}
47+
</title>
3648

3749
{sheets.map(sheet => (
3850
<link key={sheet} type="text/css" rel="stylesheet" href={sheet} />

src/templates/Router.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ export default class Router extends Component<Props, State> {
4444
if (prevState.path !== this.state.path) {
4545
const route = this.props.routes.find(r => r.link === this.state.path);
4646
if (route) {
47+
const divider = route.divider ? route.divider : ' ';
4748
// eslint-disable-next-line no-undef
48-
document.title = route.title || '';
49+
document.title = route.webTitle
50+
? `${route.title} ${divider} ${route.webTitle}`
51+
: route.title || '';
4952
}
5053
}
5154
}

src/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export type Options = {
2828

2929
export type PageInfo = {
3030
title: string,
31+
webTitle: string,
32+
divider: string,
3133
description: string,
3234
link: string,
3335
filepath: string,

src/utils/build404.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ export default function build404({ data, sheets }: Options) {
2020
// eslint-disable-next-line react/jsx-pascal-case
2121
<HTML
2222
title="404"
23+
webTitle=""
24+
divider=""
2325
description="Page not found"
2426
body={body}
2527
sheets={sheets}

0 commit comments

Comments
 (0)