Variable | const createPageTitle = ({ slug, afterSlugText, pageNumber, siteName }) => {
const title = [slug, afterSlugText, pageNumber > 1 && `Page ${pageNumber}`]
.filter(Boolean)
.join(' - ');
return `${title} | ${siteName}`;
}
createPageTitle({ slug: 'slug', afterSlugText: 'test', pageNumber: 2, siteName: 'test'})
| ready |
Clean chain | const createPageTitle = ({ slug, afterSlugText, pageNumber, siteName }) =>
[slug, afterSlugText, pageNumber > 1 && `Page ${pageNumber}`]
.filter(Boolean)
.join(' - ')
.split()
.concat(siteName)
.join(' | ');
createPageTitle({ slug: 'slug', afterSlugText: 'test', pageNumber: 2, siteName: 'test'})
| ready |
Avoid split | const createPageTitle = ({ slug, afterSlugText, pageNumber, siteName }) =>
[
[slug, afterSlugText, pageNumber > 1 && `Page ${pageNumber}`].filter(Boolean).join(' - '),
siteName,
].join(' | ');
createPageTitle({ slug: 'slug', afterSlugText: 'test', pageNumber: 2, siteName: 'test'})
| ready |
Straight to backtics | const createPageTitle = ({ slug, afterSlugText, pageNumber, siteName }) =>
`${[slug, afterSlugText, pageNumber > 1 && `Page ${pageNumber}`]
.filter(Boolean)
.join(' - ')} | ${siteName}`;
createPageTitle({ slug: 'slug', afterSlugText: 'test', pageNumber: 2, siteName: 'test'})
| ready |