mirror of
https://github.com/oekazuma/svelte-meta-tags.git
synced 2025-12-11 20:15:14 +01:00
feat: add titleTemplate property
This commit is contained in:
parent
4686ada791
commit
3a252e5783
17
README.md
17
README.md
@ -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
|
||||
|
||||
@ -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
1
src/lib/types.d.ts
vendored
@ -138,6 +138,7 @@ export interface LinkTag {
|
||||
|
||||
export interface MetaTagsProps {
|
||||
title?: string;
|
||||
titleTemplate?: string;
|
||||
noindex?: boolean;
|
||||
nofollow?: boolean;
|
||||
robotsProps?: AdditionalRobotsProps;
|
||||
|
||||
@ -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={{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user