Repository: garmeeh/next-seo
Pull request #631 (2021-01-29 08:27:18)

docs: add trevorblades as a contributor
Adds @trevorblades as a contributor for doc, code, test.

This was requested by garmeeh [in this comment](https://github.com/garmeeh/next-seo/pull/598#issuecomment-769656922)


Patch:
diff --git a/.all-contributorsrc b/.all-contributorsrc
index 72e46f5..294d4f1 100644
--- a/.all-contributorsrc
+++ b/.all-contributorsrc
@@ -391,6 +391,17 @@
       "contributions": [
         "doc"
       ]
+    },
+    {
+      "login": "trevorblades",
+      "name": "Trevor Blades",
+      "avatar_url": "https://avatars.githubusercontent.com/u/1216917?v=4",
+      "profile": "https://trevorblades.com",
+      "contributions": [
+        "doc",
+        "code",
+        "test"
+      ]
     }
   ],
   "contributorsPerLine": 7,
diff --git a/README.md b/README.md
index 3c9c24c..2acc4d1 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,7 @@ looking for inspiration on what to add.
   - [Default SEO Configuration](#default-seo-configuration)
   - [NextSeo Options](#nextseo-options)
     - [Title Template](#title-template)
+    - [Default Title](#default-title)
     - [No Index](#no-index)
     - [dangerouslySetAllPagesToNoIndex](#dangerouslysetallpagestonoindex)
     - [No Follow](#no-follow)
@@ -246,6 +247,7 @@ From now on all of your pages will have the defaults above applied.
 | ---------------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
 | `titleTemplate`                    | string                  | Allows you to set default title template that will be added to your title [More Info](#title-template)                                                                               |
 | `title`                            | string                  | Set the meta title of the page                                                                                                                                                       |
+| `defaultTitle`                     | string                  | If no title is set on a page, this string will be used instead of an empty `titleTemplate` [More Info](#default-title)                                                               |
 | `noindex`                          | boolean (default false) | Sets whether page should be indexed or not [More Info](#no-index)                                                                                                                    |
 | `nofollow`                         | boolean (default false) | Sets whether page should be followed or not [More Info](#no-follow)                                                                                                                  |
 | `description`                      | string                  | Set the page meta description                                                                                                                                                        |
@@ -297,6 +299,15 @@ titleTemplate = '%s | Next SEO';
 // outputs: This is my title | Next SEO
 ```
 
+#### Default Title
+
+```js
+title = undefined;
+titleTemplate = 'Next SEO | %s';
+defaultTitle = 'Next SEO';
+// outputs: Next SEO
+```
+
 #### No Index
 
 Setting this to `true` will set `noindex,follow` (to set `nofollow`, please refer to [`nofollow`](#noFollow)). This works on a page by page basis. This property works in tandem with the `nofollow` property and together they populate the `robots` and `googlebot` meta tags.
@@ -2243,6 +2254,7 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
     <td align="center"><a href="http://rodzy.vercel.app"><img src="https://avatars2.githubusercontent.com/u/49137701?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Isaac Rodríguez</b></sub></a><br /><a href="https://github.com/garmeeh/next-seo/commits?author=rodzy" title="Code">💻</a> <a href="https://github.com/garmeeh/next-seo/commits?author=rodzy" title="Documentation">📖</a> <a href="https://github.com/garmeeh/next-seo/commits?author=rodzy" title="Tests">⚠️</a></td>
     <td align="center"><a href="https://iainmchugh.github.io/portfolio/"><img src="https://avatars.githubusercontent.com/u/46798029?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Iain McHugh</b></sub></a><br /><a href="https://github.com/garmeeh/next-seo/commits?author=IainMcHugh" title="Documentation">📖</a></td>
     <td align="center"><a href="https://www.wiedergruen.com"><img src="https://avatars.githubusercontent.com/u/5861026?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Simon</b></sub></a><br /><a href="https://github.com/garmeeh/next-seo/commits?author=simonschllng" title="Documentation">📖</a></td>
+    <td align="center"><a href="https://trevorblades.com"><img src="https://avatars.githubusercontent.com/u/1216917?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Trevor Blades</b></sub></a><br /><a href="https://github.com/garmeeh/next-seo/commits?author=trevorblades" title="Documentation">📖</a> <a href="https://github.com/garmeeh/next-seo/commits?author=trevorblades" title="Code">💻</a> <a href="https://github.com/garmeeh/next-seo/commits?author=trevorblades" title="Tests">⚠️</a></td>
   </tr>
 </table>
 
diff --git a/src/meta/buildTags.tsx b/src/meta/buildTags.tsx
index 7b508d8..712389c 100644
--- a/src/meta/buildTags.tsx
+++ b/src/meta/buildTags.tsx
@@ -24,6 +24,11 @@ const buildTags = (config: BuildTagsParams) => {
     if (defaults.templateTitle) {
       updatedTitle = defaults.templateTitle.replace(/%s/g, () => updatedTitle);
     }
+  } else if (config.defaultTitle) {
+    updatedTitle = config.defaultTitle;
+  }
+  
+  if (updatedTitle) {
     tagsToRender.push(<title key="title">{updatedTitle}</title>);
   }
 
diff --git a/src/types.ts b/src/types.ts
index 2d2bf87..c5ad1e9 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -152,6 +152,7 @@ export type MetaTag = HTML5MetaTag | RDFaMetaTag | HTTPEquivMetaTag;
 export interface NextSeoProps {
   title?: string;
   titleTemplate?: string;
+  defaultTitle?: string;
   noindex?: boolean;
   nofollow?: boolean;
   description?: string;


Test patch:
diff --git a/src/meta/__tests__/buildTags.spec.tsx b/src/meta/__tests__/buildTags.spec.tsx
index c6c6074..8f616ca 100644
--- a/src/meta/__tests__/buildTags.spec.tsx
+++ b/src/meta/__tests__/buildTags.spec.tsx
@@ -292,6 +292,22 @@ it('displays title with titleTemplate integrated', () => {
   expect(title.innerHTML).toMatch(`${template} | ${SEO.title}`);
 });
 
+it('displays defaultTitle when no title is provided', () => {
+  const defaultTitle = 'Next SEO';
+  const props = {
+    titleTemplate: `${defaultTitle} | %s`,
+    defaultTitle,
+  };
+  const tags = buildTags(props);
+  const { container } = render(<>{React.Children.toArray(tags)}</>);
+  const title = getByText(
+    container,
+    (content, element) =>
+      element.tagName.toLowerCase() === 'title' && content.startsWith(defaultTitle),
+  );
+  expect(title.innerHTML).toMatch(defaultTitle);
+});
+
 const ArticleSEO = {
   title: 'Article Page Title',
   description: 'Description of article page',