1.0.3 • Published 3 years ago

nestjs-metatags-generator v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

NestJS meta tags generator

NPM version npm download

Meta tags generator for NestJS MVC. Should be nice for SEO purposes.

In general, generator can make ~10k records per seconds and use ~80Mb memory for this. That's mean meta tags generation not be bottleneck with up to 10k RPS.

Installation

npm install nestjs-metatags-generator

How to use

In module file

import { MetaTagsGeneratorModule } from 'nestjs-metatags-generator';

@Module({
  imports: [MetaTagsGeneratorModule.register()]
})
export class AppModule {}

In controller

import { MetaTagsGeneratorService, OpengraphTypes } from 'nestjs-metatags-generator';

@Controller('/')
export class MVCController {
  constructor(private readonly generator: MetaTagsGeneratorService) {}

  @Get('')
  @Render('index-page')
  public async indexPage() {
    const fragments = this.generator.prepare({
      robots: 'index, follow',
      backgroundColor: '#962d2d',
      handheld: 'https://m.example.world',
      canonical: 'https://example.world',
      primaryColor: '#2a797c',
      siteName: 'Example',
      pageType: OpengraphTypes.article,
      description: 'Example site',
      title: 'Example site | Some motivation phrase',
      url: 'https://example.world',
      keywords: 'nestjs, typescript, nodejs, SEO'
    });
    return {
      headFragment: fragments.head
    };
  }
}

Finally, you need place HTML output to template, like this:

<!DOCTYPE html>
<html lang="en" prefix="og: http://ogp.me/ns#">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    {{@headFragment}}
  </head>
</html>

Licence

MIT