feat: add titleTemplate property

This commit is contained in:
oe.kazuma 2022-03-20 06:41:58 +09:00
parent 4686ada791
commit 3a252e5783
4 changed files with 25 additions and 1 deletions

View File

@ -129,6 +129,7 @@ pnpm add -D svelte-meta-tags
| Property | Type | Description |
| ---------------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `title` | string | Sets the page meta title. |
| `titleTemplate` | string | Allows you to set default title template that will be added to your title [More Info](#title-template) |
| `noindex` | boolean (default false) | Sets whether page should be indexed or not |
| `nofollow` | boolean (default false) | Sets whether page should be followed or not |
| `additionRobotsProps` | Object | Set the more meta information for the `X-Robots-Tag` [More Info](#robotsprops) |
@ -170,6 +171,22 @@ pnpm add -D svelte-meta-tags
| `openGraph.article.section` | string | A high-level section name. E.g. Technology |
| `openGraph.article.tags` | string[] | Tag words associated with this article. |
#### Title Template
Replaces `%s` with your title string
```js
title = 'This is my title';
titleTemplate = 'Svelte Meta Tags | %s';
// outputs: Svelte Meta Tags | This is my title
```
```js
title = 'This is my title';
titleTemplate = '%s | Svelte Meta Tags';
// outputs: This is my title | Svelte Meta Tags
```
#### Twitter
```js

View File

@ -1,5 +1,6 @@
<script>
export let title = '';
export let titleTemplate = '';
export let noindex = false;
export let nofollow = false;
export let robotsProps = undefined;
@ -13,6 +14,10 @@
export let additionalMetaTags = undefined;
export let additionalLinkTags = undefined;
if (titleTemplate) {
title = titleTemplate.replace(/%s/g, title);
}
let robotsParams = '';
if (robotsProps) {
const {

1
src/lib/types.d.ts vendored
View File

@ -138,6 +138,7 @@ export interface LinkTag {
export interface MetaTagsProps {
title?: string;
titleTemplate?: string;
noindex?: boolean;
nofollow?: boolean;
robotsProps?: AdditionalRobotsProps;

View File

@ -3,7 +3,8 @@
</script>
<MetaTags
title="Normal | Svelte Meta Tags"
title="Normal"
titleTemplate="%s | Svelte Meta Tags"
description="Description"
canonical="https://www.canonical.ie/"
openGraph={{