Repository: garmeeh/next-seo (js)

Issue:
Include title Template
# Feature Request
Include title template which can be appended before or after every title if defined.
example config
```javascript
{
  title: "This is a test title.",
  titleTemplate: "Next SEO | %s"
}
```

and the output will be
```html
<title>Next SEO | This is a test title.</title>
```

`%s` will be replaced by the title, so depending on the position, that's where the title will be appended.

Pull request:
inlcude title template
fixes #5 
Include title template

Patch:
diff --git a/src/meta/buildTags.jsx b/src/meta/buildTags.jsx
index 4936d24..c3c3a1a 100644
--- a/src/meta/buildTags.jsx
+++ b/src/meta/buildTags.jsx
@@ -4,7 +4,11 @@ const buildTags = (config) => {
   const tagsToRender = [];
 
   if (config.title) {
-    tagsToRender.push(<title key="title">{config.title}</title>);
+    let updatedTitle = config.title;
+    if (config.titleTemplate) {
+      updatedTitle = config.titleTemplate.replace(/%s/g, () => updatedTitle);
+    }
+    tagsToRender.push(<title key="title">{updatedTitle}</title>);
   }
 
   if (!config.noindex) {


Test patch:
diff --git a/src/meta/__tests__/buildTags.test.jsx b/src/meta/__tests__/buildTags.test.jsx
index 0d9c214..98207db 100644
--- a/src/meta/__tests__/buildTags.test.jsx
+++ b/src/meta/__tests__/buildTags.test.jsx
@@ -141,3 +141,18 @@ it('correctly sets noindex, nofollow', () => {
   expect(Array.from(index).length).toBe(0);
   expect(Array.from(noindex).length).toBe(2);
 });
+
+it('displays title with titleTemplate integrated', () => {
+  const template = 'Next SEO';
+  const overrideProps = {
+    ...SEO,
+    titleTemplate: `${template} | %s`,
+  };
+  const tags = buildTags(overrideProps);
+  const { container } = render(tags);
+  const title = getByText(
+    container,
+    (content, element) => element.tagName.toLowerCase() === 'title' && content.startsWith(template),
+  );
+  expect(title.innerHTML).toMatch(`${template} | ${SEO.title}`);
+});