Last active
August 17, 2016 13:26
-
-
Save max2320/a0e9d580b9455f3728a6b97004dee33c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>teste</title> | |
<script src="https://code.jquery.com/jquery-1.12.3.min.js"></script> | |
</head> | |
<body> | |
<script> | |
function newDOM(tag){ | |
return document.createElement(tag); | |
} | |
function $DOM(tag, attr, prop){ | |
if(attr == undefined){ | |
attr = {} | |
} | |
if(prop == undefined){ | |
prop = {} | |
} | |
return $(newDOM(tag)).attr(attr).prop(prop); | |
} | |
var url = "https://gvces-cms-api.herokuapp.com//?filter[site_id]=132&filter[page_size]=100" | |
var items = []; | |
function addItem(item){ | |
var line = $DOM('item'); | |
var pub_date = new Date(item.date_published); | |
line.append("\n\t"); | |
var title = $DOM('title').append(item.title); | |
line.append(title); | |
line.append("\n\t"); | |
var link = $DOM('link').append(); | |
line.append(link); | |
line.append("\n\t"); | |
var pubDate = $DOM('pubDate').append(pub_date.toUTCString().replace('.', " +0")); | |
line.append(pubDate); | |
line.append("\n\t"); | |
var dc_creator = $DOM('dc:creator').html('tracersoft'); | |
line.append(dc_creator); | |
line.append("\n\t"); | |
var guid = $DOM('guid', { | |
'isPermaLink':"false" | |
}); | |
line.append(guid); | |
line.append("\n\t"); | |
var description = $DOM('description'); | |
line.append(description); | |
line.append("\n\t"); | |
var content_encoded = $DOM('content:encoded').html('[:pt]'+ item.content +'[:]'); | |
line.append(content_encoded); | |
line.append("\n\t"); | |
var excerpt_encoded = $DOM('excerpt:encoded').html('[:pt]'+ item.resume +'[:]'); | |
line.append(excerpt_encoded); | |
line.append("\n\t"); | |
var wp_post_id = $DOM('wp:post_id').append(); | |
line.append(wp_post_id); | |
line.append("\n\t"); | |
var wp_post_date = $DOM('wp:post_date').append(pub_date.toISOString().replace('Z', "").replace('T', " ")); | |
line.append(wp_post_date); | |
line.append("\n\t"); | |
var wp_post_date_gmt = $DOM('wp:post_date_gmt').append(pub_date.toISOString().replace('Z', "").replace('T', " ")); | |
line.append(wp_post_date_gmt); | |
line.append("\n\t"); | |
var wp_comment_status = $DOM('wp:comment_status').append('open'); | |
line.append(wp_comment_status); | |
line.append("\n\t"); | |
var wp_ping_status = $DOM('wp:ping_status').append('open'); | |
line.append(wp_ping_status); | |
line.append("\n\t"); | |
var wp_post_name = $DOM('wp:post_name').append(item.slug); | |
line.append(wp_post_name); | |
line.append("\n\t"); | |
var wp_status = $DOM('wp:status').append('publish'); | |
line.append(wp_status); | |
line.append("\n\t"); | |
var wp_post_parent = $DOM('wp:post_parent').append('0'); | |
line.append(wp_post_parent); | |
line.append("\n\t"); | |
var wp_menu_order = $DOM('wp:menu_order').append('0'); | |
line.append(wp_menu_order); | |
line.append("\n\t"); | |
var wp_post_type = $DOM('wp:post_type').append('post'); | |
line.append(wp_post_type); | |
line.append("\n\t"); | |
var wp_post_password = $DOM('wp:post_password').append(); | |
line.append(wp_post_password); | |
line.append("\n\t"); | |
var wp_is_sticky = $DOM('wp:is_sticky').append('0'); | |
line.append(wp_is_sticky); | |
line.append("\n\t"); | |
item.categories.forEach(function(cat){ | |
var category = '<category domain="category" nicename="' + cat.slug + '"><![CDATA[' + cat.title + ']]></category>'; | |
line.append(category); | |
line.append("\n\t"); | |
}) | |
var source = ""; | |
if(item.source == null){ | |
source = item.source_old; | |
}else{ | |
source = item.source.content; | |
} | |
var wp_postmeta = $DOM('wp:postmeta') | |
wp_postmeta.append($DOM('wp:meta_key').append('fonte')); | |
wp_postmeta.append($DOM('wp:meta_value').html('<!--:pt-->' + source + '<!--:-->')); | |
line.append(wp_postmeta); | |
line.append("\n"); | |
items.push(line); | |
} | |
function renderPage(i, maxPages){ | |
$.get(url + "&filter[page]="+i, function(data){ | |
data.categories.forEach(function(item){ | |
addItem(item); | |
}); | |
items.forEach(function(item){ | |
$('#ct').append(item); | |
$('#ct').append("\n"); | |
}); | |
if(i <= maxPages){ | |
renderPage(i + 1, maxPages) | |
} | |
}); | |
} | |
$.get(url, function(fst){ | |
renderPage(1, fst.meta.pages); | |
}); | |
</script> | |
<pre id="ct"></pre> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment