Skip to content
This repository has been archived by the owner on Dec 11, 2023. It is now read-only.

Commit

Permalink
Posts list working
Browse files Browse the repository at this point in the history
Issue #2
Steem module can now display a list of posts. Still need to limit it by
tag, and the default theme needs some style work done on it. Plus more
of the data could be incorporated.
  • Loading branch information
toniwidmo committed Dec 13, 2017
1 parent 6669543 commit b107ffb
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 9 deletions.
6 changes: 5 additions & 1 deletion module/steem/steem-posts.html
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
X,
<div class="steem_post steem_post_{steem_post_tag}" id="steem_post_{steem_post_permlink}">
<h2>{steem_post_title}</h2>
<img src="{steem_post_img}">
{steem_post_preview}
</div>
36 changes: 28 additions & 8 deletions module/steem/steem.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ function steem_display(content) {
}
function steem_load(args) {
console.log("Inside steem_load.");
console.log('args: '+args);
args = JSON.parse(args.replace(/&quot;/g,'"'));
console.log(args);
console.log('args JSON parsed: '+args);
console.log(args.show);

switch(args.show) {
Expand All @@ -25,7 +26,7 @@ function steem_load(args) {
getSteemProfile(args.user);
break;
case "posts":
getSteemPosts(args.users,args.tag);
getSteemPosts(args.user,args.tag);
console.log("Get posts for: user(s): "+args.user+", tag(s): "+args.tag);
break;
case "post":
Expand All @@ -38,23 +39,42 @@ function steem_load(args) {
function displaySteemPosts(posts_template) {
// Template should be stored in global steem_posts
var template = posts_template;
var content = '';
var json_metadata, post_obj, body, content = '';

var converter = new showdown.Converter();

// Loop through posts, populate the template and append it to contentArea
var post, postsLength = steem_posts.length;
for (var i = 0; i < postsLength; i++) {
console.log("Post "+i+": "+steem_posts[i]);
post_obj = steem_posts[i];
json_metadata = JSON.parse(post_obj.json_metadata);

console.log("Post "+i+": "+JSON.stringify(post_obj));
console.log("metadata "+i+": "+JSON.stringify(json_metadata));

// Insert post values for this post
template = template.replace('{steem_post_tag}',post_obj.category);
template = template.replace('{steem_post_title}',post_obj.title);
template = template.replace('{steem_post_permlink}',post_obj.permlink);
template = template.replace('{steem_post_img}',json_metadata.image);

// Full body
body = converter.makeHtml(post_obj.body);
template = template.replace('{steem_post_body}',body);

// Body preview
body = body.replace(/<(?:.|\n)*?>/gm, ''); //strip html
if(body.length > 250) body = body.substring(0,247)+'...';
template = template.replace('{steem_post_preview}',body);

// Append post to content string if it has a matching tag
content += template;
//Reset template
var template = steem_posts;
var template = posts_template;
}

// Append content to contentArea
$('#contentArea').html(content);
$('#contentArea').append(content);
}
function getSteemPostsTemplate(err,posts) {
// Save profile in global variable
Expand All @@ -75,8 +95,8 @@ function getSteemPosts(usernames,tags) {
$('#contentArea').html('');

steem_tags = tags;

steem.api.getDiscussionsByAuthorBeforeDate(usernames, '', '', 50, function(err, result){getSteemPostsTemplate(err, result)});
console.log('usernames: '+usernames);
steem.api.getDiscussionsByAuthorBeforeDate(usernames, '', '2100-01-01T00:00:00', 10, function(err, result){getSteemPostsTemplate(err, result)});
//displaySteemPosts(['AAA']);
}

Expand Down

0 comments on commit b107ffb

Please sign in to comment.