@casdl/ngx-rich-snippet
TypeScript icon, indicating that this package has built-in type declarations

0.2.1 • Public • Published

ngx-rich-snippet

This library exports frequently used rich snippet class according to schema.org. Also it provides some services. This libary is Angular Universal compatible.

Dependencies

Installation

To install this library, run:

$ npm install ngx-rich-snippet --save

Import

In your AppModule, import the RichSnippetModule with config and services.

import { NgModule } from '@angular/core';
import { 
  RichSnippetModule, 
  RichSnippetConfig, 
  Corporation,
  RsWebPageService,
  RsBreadcrumbService
} from '@casdl/ngx-rich-snippet';

const CORPORATION = new Corporation(... );

export function getRsWebPageDefaults() {
  return {
    author: CORPORATION,
    publisher: CORPORATION,
    copyrightHolder: CORPORATION
  }
}

const RICH_SNIPPET: RichSnippetConfig = {
  baseUrl: environment.baseUrl,
  defaults: {
    rsWebPage: getRsWebPageDefaults
  }
};

@NgModule({
  imports: [
    RichSnippetModule.forRoot(RICH_SNIPPET, [
      RsWebPageService,
      RsBreadcrumbService
    ])
  ],
})
export class AppModule { }

Once imported you can subscribe to the "webpage" and "breadcrumb" observables in your App component's HTML using ngx-json-ld.

app.component.ts

import { Component } from '@angular/core';

import { 
  RsWebPageService, 
  RsBreadcrumbService 
} from '@casdl/ngx-rich-snippet';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {

  rsBreadcrumb = this.rsWebPageService.current;
  rsWebPage = this.rsBreadcrumbService.current;

  constructor(
    private rsWebPageService: RsWebPageService,
    private rsBreadcrumbService: RsBreadcrumbService
  ) {}
}

app.component.html

<!-- You can now subscribe to the observables -->
<casdl-json-ld [json]="rsBreadcrumb"></casdl-json-ld>
<casdl-json-ld [json]="rsWebPage"></casdl-json-ld>

Services

  • BreadcrumbService - This handles the BreadcrumbList rich snippet on route change.
  • WebPageService - This handles the WebPage rich snippet on route change.

Config

License

MIT © Cassius de Leeuwe - Jan IT

Readme

Keywords

Package Sidebar

Install

npm i @casdl/ngx-rich-snippet

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

149 kB

Total Files

46

Last publish

Collaborators

  • casdl