Socket
Book a DemoInstallSign in
Socket

nest-sitemap

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nest-sitemap

Packet for generating sitemap of your resource

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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',
            }),
        ];
    },
});

FAQs

Package last updated on 06 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts