Learn about our RFC process, Open RFC meetings & more.Join in the discussion! »

nest-sitemap

0.1.1 • Public • Published

How to use

Register module:

import { SitemapModule } from 'nest-sitemap';
 
@Module({
    // ...
    imports: [
        SitemapModule.forRootAsync({
            imports: [UtilsModule],
            inject: [ConfigService],
            useFactory: async (configService: ConfigService) => {
                return {
                    hostname: configService.get('MEDIA_ORIGIN'),
                };
            },
        }),
    ]
    // ...
})
export class AppModule {}

Apply decorator to typeorm entity:

import { TypeormSitemapResource } from 'nest-sitemap';
 
@TypeormSitemapResource({
    getUrl: page => {
        return `/ru/article/${(page as ArticleEntity).slug}`;
    },
})
@Entity({
    name: 'articles',
})
export class ArticleEntity extends BaseSeoEntity {
    @Column()
    public title: string;
}

Access to sitemap xml from some controller:

@Controller()
export class MainController {
    public constructor(private readonly sitemap_service: SitemapService) {}
    
    @Header('Content-Type', 'application/xml')
    @Get('sitemap')
    public getSitemap() {
        return this.sitemap_service.getSitemapXml();
    }
}

If you want to add additional items to registry you can to do like this:

import { registerSource, SitemapItem } from 'nest-sitemap';
 
registerSource({
    getItems() {
        return [
            new SitemapItem({
                url: '/my_superpage',
            }),
        ];
    },
});
 

Keywords

none

Install

npm i nest-sitemap

DownloadsWeekly Downloads

4

Version

0.1.1

License

MIT

Unpacked Size

46.3 kB

Total Files

46

Last publish

Collaborators

  • avatar