i created a page extending "ContentPageMetaResolver" that implements PageRobotsResolver
export class MyContentPageMetaResolver extends ContentPageMetaResolver implements
PageRobotsResolver {
pageType = PageType.CONTENT_PAGE;
pageTemplate = 'StaticContentPageTemplate';
resolveRobots(): Observable<PageRobotsMeta[]> {
return of(new Array(PageRobotsMeta.NOFOLLOW, PageRobotsMeta.NOINDEX));
}
}
As a result this is adding the the following entry to the head element of the page:
<meta name="robots" content="NOFOLLOW, NOINDEX">
Now i need to do the same thing for keywords. Any idea how to create a custom resolver implementation ?
The PageRobotsResolver interface is provided out of the box in page.resolvers.d.ts file:
/**
* Resolves the robot information for the page. This is used by
* search engines to understand whether the page and subsequential links
* should be indexed.
*
*/
export interface PageRobotsResolver {
/**
* Resolves the robots for the page.
*
* @deprecated since version 1.3
* Use `resolveRobots()` instead.
*/
resolveRobots(...args: any[]): Observable<PageRobotsMeta[]>;
/**
* Resolves the robots for the page.
*/
resolveRobots(): Observable<PageRobotsMeta[]>;
}
And added the following to my providers list of my module :
@NgModule({
providers: [
{ provide: ContentPageMetaResolver, useExisting: MyContentPageMetaResolver }
]
})
PageMetaResolver
are used by the PageMetaService
to generate page meta data. Specific meta data can be added in a specific resolver (i.e. in your MyContentPageMetaResolver
), or you could extend the PageMetaResolver
to gather additional metadata for all resolvers.
By default, Spartacus iterates (from feature flag 1.3
) over various resolvers, and - if the resolver is implemented – adds the resolved data to the page meta model. This is done in the PageMetaService
, and you could (but should not ;), see below) extend the list of resolverMethods
in that service so that your custom method is called.
An alternative (but less flexible) approach would be to provide a custom SeoMetaService
, and override the meta
setter. Also, the SeoMetaService
is limited to page meta data, while the PageMetaService
can contribute to other areas of the application, such as structural data.
Whether the use of keywords in 2020 is still a good idea, I'd recommend to read up on this, as crawlers seem to stop worrying for this a long time ago. This is the reason why we haven't added a default resolver in Spartacus, but if you come up with good arguments to do so, I'm eager to learn!