Gathering detailed insights and metrics for @ngxuniversaltools/seo
Gathering detailed insights and metrics for @ngxuniversaltools/seo
npm install @ngxuniversaltools/seo
Typescript
Module System
Node Version
NPM Version
53.8
Supply Chain
96.2
Quality
78.8
Maintenance
100
Vulnerability
98.9
License
TypeScript (100%)
Total Downloads
968
Last Day
1
Last Week
4
Last Month
15
Last Year
447
59 Commits
1 Watching
5 Branches
2 Contributors
Minified
Minified + Gzipped
Latest Version
2.1.0
Package Id
@ngxuniversaltools/seo@2.1.0
Unpacked Size
54.75 kB
Size
13.85 kB
File Count
23
NPM Version
10.5.0
Node Version
18.20.2
Publised On
13 Sept 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
300%
4
Compared to previous week
Last month
275%
15
Compared to previous month
Last year
-14.2%
447
Compared to previous year
1
2
Provides helper functions to manipulate meta tags, titles and JsonLD microdata. Much of the code is based on the ngx-seo package.
1npm install @ngxuniversaltools/seo
Add the following to your app.module.ts
:
1import {SeoModule} from '@ngxuniversaltools/seo'; 2 3imports: [ 4 SeoModule 5]
In Standalone projects you can simply use SeoService
without importing the module.
Add the directive to every instance of <router-outlet>
in your application:
<router-outlet seoOutlet></router-outlet>
The SeoService
provides methods to set different properties:
setTitle(title: string)
- Sets the title of the pagesetJsonLd(jsonLd: JsonLd[])
- Sets the JsonLD microdata.setMeta(name: string, content: string)
- Sets a meta tag with the given name and content. Overwrites existing meta
tags with the same name if present.setMetas(values: { [ key: string ]: string })
- Allows settings multiple meta tags at onceThis opinionated part of the library can be used to allow components to easily provide metadata for the page. The
component
declared in your route should extend the PageAbstract
class and override properties when applicable. Finally you can
use @ngrx/effects
to subscribe to the page$
observable and set the title and meta tags.
Example:
{
path: "category",
component: CategoryComponent,
}
Your component should look like this:
1import {PageAbstract} from '@ngxuniversaltools/seo'; 2import {of} from 'rxjs'; 3 4@Component({ 5 selector: 'app-category', 6 templateUrl: './category.component.html', 7 styleUrls: ['./category.component.scss'] 8}) 9export class CategoryComponent extends PageAbstract { 10 title = of('Category'); // Simple static title 11 description = this.translate.get("category.description"); // Translated description 12}
You must create subscribers to actually set the title and meta tags. If you use @ngrx/effects
this can be easily
achieved:
1export class PageEffects { 2 title$ = createEffect(() => this.seo.page$.pipe( 3 switchMap(page => page?.title || of("")), 4 map(title => title ? [title, "My cool website"].join(" | ") : "My cool website"), 5 tap(({title}) => this.seo.setTitle(title)) 6 ), {dispatch: false}); 7 8 constructor (private seo: SeoService) { 9 } 10}
You may need additional properties to be controlled by the page component. This can be achieved by creating your own PageAbstract class:
export class MyAppPageAbstract extends PageAbstract {
image = of("https://example.com/image.png");
}
export class CategoryComponent extends MyAppPageAbstract {
title = of('Category'); // Simple static title
description = this.translate.get("category.description"); // Translated description
image = this.api.getFirstPost().pipe(map => map.image); // Dynamic image
}
Finally add an effect to set og:image meta tags:
1export class PageEffects { 2image$ = createEffect(() => this.seo.page$.pipe( 3 switchMap(page => page?.image || of("")), 4 tap(image => this.seo.setMetas({ 5 "og:image": image?.url || null, 6 "og:image:alt": image?.alt || null, 7 "og:image:width": image?.width ? image.width.toString() : null, 8 "og:image:height": image?.height ? image.height.toString() : null, 9 })) 10), {dispatch: false}); 11 12constructor (private seo: SeoService<MyAppPageAbstract>) { 13} 14}
Pay attention to the constructor of the effect. You must provide the type of your custom PageAbstract class when importing SeoService.
No vulnerabilities found.
No security vulnerabilities found.