A github api wrapper exposing endpoints for a blog
github-blog-api
?
What is the This API wrapper enables you to run a blog using the GitHub API.
It uses github issues
as posts
and issue labels
as tags
and GitHub comments
as comments
very conviently.
You can easily make a fully client-side blog using this API, but I made this
as a helper library for a gitpushblog
(static github blog generator),
so some API endpoints might seem a bit odd but it should work fine for a fully client-side blog.
Installation
Install github-api-wrapper using npm, it works same on both node and the browser
$ npm install --save github-blog-api
Usage
Basic Usage
// ES5: var blog = require('github-blog-api');; let lazyblog = ; // set custom per_page, default is 10lazyblog; // get blogposts with per_page set to 5// subsequent calls to fetchBlogPosts will result in next pageslazyblog ;// OUTPUTS: 5 posts of page 1 lazyblog ;// OUTPUTS: 5 posts of page 2 if exists else prints [] // fetching comments with issueIdlazyblog ;
Calling fetchBlogPosts multiple times
// manually setting last_reached to false to do another fetchBlogPosts call// you need to do this only if you need to do a new fetchBlogPosts after or inbetween// calling the last fetchBlogPosts // NOTE: setPost method is synchronous so use it with caution when using with fetchBlogPosts lazyblog; lazyblog ;
The methods and properties inside the blog object are as follows:
blog.settings
: this is the state container of the blogsetPost
andsetComment
: to update theposts
andcomments
objects insideblog.settings
fetchAllLabels
: fetch all labels in the blog - does not contain the issue count [Need help]fetchBlogPosts
: fetches blog posts based on theposts
object, takeslabels[]
as argumentfetchBlogPost
: fetches a single blog post, takesissueId/postId
as argumentfetchBlogPostComments
: fetches comments based on thecomments
object, takesissueId/postId
as argument
fetchBlogPosts
usage:
Note on If fetchBlogPosts
does not return all results in one page/response, repeated calls to fetchBlogPosts
will be returning
next results, once all results are done blog.settings.posts.last_reached
will be set to true
and an empty[] will
be resolved by the promise.
library user should manually update blog.settings.posts.last_reached
to false
with setPost({last_reached:false, next_page_url:''})
if fetchBlogPosts
has to be called again after once being called completely.
The same idea applies for fetchBlogPostComments
. please see code to know how it is implemented.
it does not have a last_reached
so, just specifying other postId
is enough.
Contribute
- run
npm run build
to babelify the src files into lib
Todo
- to add comment wrapper: auth + firebase setup