Comparing version 1.0.4 to 1.0.5
{ | ||
"name": "nodepress", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Dynamic blog engine for node", | ||
@@ -5,0 +5,0 @@ "main": "nodepress.js", |
# NodePress | ||
Lightweight, dynamic blog engine for Node. | ||
NodePress is a blog engine for Node web servers. It's designed to be fast to use and attach to your existing project. | ||
NodePress is a blog engine for Node web servers. It's designed to be fast to use and attach to your existing project. It works like a bridge between your database and the client, making it simple to have users posting and fetching posts. | ||
## Technology | ||
NodePress uses Mongo for database and Express/Socketio for client-server communication. | ||
NodePress uses Mongo as database and Express/Socket.io for client-server communication. | ||
@@ -67,3 +67,3 @@ ## How to | ||
nodePress.on('post', (user, postData) => { | ||
// Check if we have all the information needed | ||
// Check if we have all the information we want | ||
if (!postData.title || !postData.author || !postData.body) | ||
@@ -82,6 +82,66 @@ // This will be emitted to the client through Socket.io | ||
**5.** Take a look at the client examples in the folder /example/client to setup Socket.io in the client. | ||
**5.** Initialize [Socket.io](https://www.npmjs.com/package/socket.io) in the client and listen for server events. | ||
```javascript | ||
const socket = io(); | ||
var page = 1; | ||
// Will request posts from page '1' | ||
socket.emit('getPage', page); | ||
socket.on('postsFromPage', function(data) { | ||
// In case of an infinite-scrolling blog, we would want | ||
// to increase the page number after getting posts | ||
page++; | ||
// Reverse posts list in case you want | ||
// to show them by latest -> earliest (top -> bottom) | ||
var posts = data.posts.reverse(); | ||
// last is true if that's the last page available | ||
var last = data.last; | ||
for (let i = 0; i < posts.length; i++) { | ||
// Append a new post box for every post at the current page | ||
var p = '<div class="post">\ | ||
<div class="top">\ | ||
<span class="title">'+posts[i].title+'</span>\ | ||
<span class="info">\ | ||
by <span class="author">'+posts[i].author+'</span><br>\ | ||
on <span class="date">'+getPostDate(posts[i].date)+'</span>\ | ||
</span>\ | ||
</div>\ | ||
<div class="body">\ | ||
<p>'+posts[i].body+'</p>\ | ||
</div>\ | ||
</div>'; | ||
$('.timeline').append(p); | ||
} | ||
// If there are more pages, show the "Load More" button | ||
if (!last) { | ||
$('.timeline').append('<div class="load-more">Load More</div>'); | ||
} | ||
}); | ||
``` | ||
**6.** To publish a post in the client is very simple. According to the above server socket listener 'post': | ||
```javascript | ||
var post = { | ||
title: 'My Title'. | ||
author: 'My Name', | ||
body: 'Hi there!' | ||
}; | ||
socket.emit('post', post); | ||
``` | ||
**7.** For a full Client example, please check the /example/client folder files. | ||
## License | ||
MIT License |
Sorry, the diff of this file is not supported yet
22828
146