Skip to content

Commit 690eb97

Browse files
authored
Made pageTitle optional (#11)
1 parent a75c962 commit 690eb97

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ export default PageLayout;
6262
| Property | Type | Required | Notes |
6363
| ----------------- | -------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
6464
| **render** | React.ReactNode | **Yes** | Unfortunately `react-helmet` and `next/head` are strict with how they accept meta tags. `react-helmet` doesn't support nesting. Whereas Next.JS only supports some children and not all, therefore a render function is required. |
65-
| **pageTitle** | string | **Yes** | Every page should have a unique title that describes the page, such as 'Home', 'About' etc. |
66-
| **siteTitle** | string | **Yes** | Title of the site, usually the organization / brand name. |
65+
| **pageTitle** | string | **No** | Unique page title that describes the page, such as `Home`, `About` etc. etc. |
66+
| **siteTitle** | string | **Yes** | Title of the site, usually the organization / brand name. If `pageTitle` and `siteTitle` are the same, only this shows. |
6767
| **titleTemplate** | string | **No** | Title template used to display `pageTitle` and `siteTitle` in a template, displays the values using corresponding `[pageTitle]` and `[siteTitle]`. Example template: "[pageTitle] | [siteTitle]". |
6868
| **description** | string | **Yes** | A one to two sentence description of your webpage. Keep it within 160 characters, and write it to catch the user's attention. |
6969
| **baseSiteUrl** | string | **Yes** | Base site URL, excluding trailing slash. |

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@phntms/react-share",
33
"description": "An all-in-one React library to implement custom Sharing Meta and Social Media Sharing Buttons.",
4-
"version": "0.0.3",
4+
"version": "0.0.4",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",
77
"homepage": "https://github.com/phantomstudios/react-share#readme",
@@ -71,4 +71,4 @@
7171
"dependencies": {
7272
"is-absolute-url": "^3.0.3"
7373
}
74-
}
74+
}

src/components/MetaHeadEmbed.tsx

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export interface MetaEmbedProps {
5050
render: (meta: React.ReactNode) => JSX.Element;
5151

5252
/** Unique page title that describes the page, such as `Home`, `About` etc. */
53-
pageTitle: string;
53+
pageTitle?: string;
5454

5555
/** Title of the site, usually the organization / brand name. */
5656
siteTitle: string;
@@ -117,13 +117,12 @@ const MetaHeadEmbed = ({
117117
locale = "en_US",
118118
twitter,
119119
}: MetaEmbedProps) => {
120-
const title = titleTemplate
121-
? pageTitle === siteTitle
122-
? pageTitle
123-
: titleTemplate
124-
.replace("[pageTitle]", pageTitle)
125-
.replace("[siteTitle]", siteTitle)
126-
: pageTitle;
120+
let title = siteTitle;
121+
if (titleTemplate && pageTitle && pageTitle !== siteTitle) {
122+
title = titleTemplate
123+
.replace("[pageTitle]", pageTitle)
124+
.replace("[siteTitle]", siteTitle);
125+
}
127126

128127
const canonical =
129128
canonicalUrl &&

0 commit comments

Comments
 (0)