Skip to content

An easy-to-use interface for making requests to the Blogger Feeds API. Search and paginate your posts, comments and pages in few steps.

License

Notifications You must be signed in to change notification settings

yoimerdr/feeddy

Repository files navigation

feeddy

An easy-to-use interface for making requests to the Blogger Feeds API.

Install

Download the feeddy script and include it in your project.

<script src="./path-to/feeddy.js"></script>

or you can use

<script src="https://yoimerdr.github.io/feeddy/dist/v1.2.1/feeddy.min.js"></script>

How to

Paginate entries

If you want to get the paginated entries and do something with them dynamically, you could do something like this

// you can also use .comments or .pages instead .posts.
feeddy.posts({
  feed: {
    // For tests only you can use the 'https://cors-anywhere.herokuapp.com/' + your blog url.
    // Allow temporary access on https://cors-anywhere.herokuapp.com/corsdemo 
    blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
    params: feeddy.search.params()
      .limit(12)
      .build()
  }
}).then(handler => handler.page(1))
  .then(result => {
    console.log(result.entries); // .posts was deprecated an removed since 1.2
  })

Search posts

You could also paginate the entries by combining with some search parameters.

feeddy.posts({
  feed: {
    blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
    params: feeddy.search.params()
      .limit(12)
      .query(
        feeddy.search.query()
          .terms('term') // The term for search, for terms with spaces use .exact() before .terms()
          .build()
      )
      .build()
  }
}).then(handler => handler.page(1))
  .then(result => {
    console.log(result.entries);
  })

Paginate entries (SSR)

If you don't want to load the entries dynamically, but have the blogger generator itself return the entries (like cards at home), you could do the following to get the valid URLs for it.

feeddy.posts.ssr({
  feed: {
    blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
    params: feeddy.search.params()
      .limit(12)
      .build()
  },
  ssr: 'default2' // the ssr mode, the default value is 'default'.
}).then(handler => handler.page(2))
  .then(result => {
    console.log(result.url);
  })

Posts with the given categories only

If you want to search for entries related to some categories, you may use:

feeddy.posts.withCategories({
  feed: {
    blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
    params: feeddy.search.params()
      .limit(12)
      .build()
  },
  categories: ['category', 'name'],
  
})
  .then(result => {
    console.log(result.posts);
  })

Interact with the feeds only

Mapped feed

feeddy.feed({
  blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
  type: "posts", // since 1.2 the type (posts, pages, comments) is mandatory. This condition was removed in 1.2.1, default is posts.
  params: feeddy.search.params()
    .limit(12)
    .build()
}).then(console.log)

Raw feed

feeddy.feed.raw({
  blogUrl: '', // The blog url, or nothing if the current origin is the blogger blog. 
  type: "posts", // since 1.2 the type (posts, pages, comments) is mandatory. This condition was removed in 1.2.1, default is posts.
  params: feeddy.search.params()
    .limit(12)
    .build()
}).then(console.log)

Docs

You can read about the methods available and how responses are structured here.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Build your own

Clone the repository

git clone https://github.com/yoimerdr/feeddy.git

Install dependencies

Creates the lib folder

mkdir lib

Moves into

cd lib

Clones the jstls dependency

git clone https://github.com/yoimerdr/jstls.git

And edit the project as you wish.