Necessary Pigeonholing Mechanism

    @ninanfm/feed
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.0 • Public • Published

    @ninanfm/feed

    This package is still working in progress, take your own risk to use it.

    @ninanfm/feed is a feed generator with flexible APIs, it's designed to use with TypeORM.

    Table of Contents

    Supported Specifications

    Quick Start

    This package must to use with reflect-metadata, so you have to make sure that you have installed it.

    yarn add reflect-metadata @ninanfm/feed
    # or
    npm i reflect-metadata @ninanfm/feed

    Then add this line of code on the top of your entry file.

    import 'reflect-metadata';
    

    The next step is to define models to tell @ninanfm/feed how to generate your feed. Here, we suppose that your are using this package with TypeORM and want to generate a RSS feed for your blog.

    import { RSS2_0 as RSS, xml } from '@ninanfm/feed';
    import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
    
    @RSS.support
    @Entity()
    export class Post {
        @PrimaryGeneratedColumn()
        id: number;
    
        @Column()
        slug: string;
    
        @Column('text')
        @RSS.item.description
        content: string;
    
        @RSS.item.author
        authorName: string;
    
        @RSS.item.pubDate
        publishedAt: Date;
    
        @RSS.item.link
        @RSS.item.guid({isPermaLink: true})
        get url(): string {
            return 'https://domain/posts/' + this.slug; 
        }
    
        @ManyToOne(() => Blog, blog => blog.posts)
        blog: Blog;
    }
    
    @RSS.support
    @Entity()
    export class Blog {
        @PrimaryGeneratedColumn()
        id: number;
    
        @Column()
        @RSS.channel.title
        title: string;
    
        @Column('text')
        @RSS.channel.description
        description: string;
    
        @Column()
        slug: string;
    
        @RSS.channel.link
        readonly homePageUrl = 'https://domain';
    
        @OneToMany(() => Post, post => post.blog)
        posts: Post[];
    
        toRSS(): string {
            return xml.toString(this);
        }
    }

    That's it, now you can call #toRSS method on Blog instance to generate RSS feed.

    Predefined Models

    Currently, we only defined a Podcast model, you can see the codes for Podcast model to find out how to use the advanced features of this package.

    License

    MIT

    Install

    npm i @ninanfm/feed

    DownloadsWeekly Downloads

    2

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    76.5 kB

    Total Files

    46

    Last publish

    Collaborators

    • poying