Commit 557aeb70 authored by Erick Hitter's avatar Erick Hitter

Insert render latest post into document

parent 1fc35843
......@@ -25,11 +25,12 @@ app.get( '/', function( req, res ) {
res.render( 'index', { data: { domains: domains } } );
} );
// Get some data
// API requests require a domain
app.get( '/api', function( req, res ) {
res.status( 400 ).json( { error: 'Must specify a domain!' } );
} );
// Render the domain's latest post
app.get( '/api/:domain', function( req, res ) {
// For convenience
var domain = req.params.domain;
......@@ -61,6 +62,9 @@ app.get( '/api/:domain', function( req, res ) {
} );
} );
// Allow access to scripts
app.use( express.static( 'public' ) );
// Listen on some random, unused port
// App is meant to be fronted by nginx
app.listen( 5060, function() {
......
.sharedaddy{ display: none; }
( function( $ ) {
$( 'div.site-container' ).each( function( i, site ) {
var container = $( this ),
domain = container.data( 'domain' );
$.get( {
url: '/api/' + domain,
success: function( data, status ) {
$( '.latest-post', container ).html( data );
}
} );
} );
} ) ( jQuery );
<h3><a href="{{data.post.link}}">{{data.post.title.rendered}}</a></h3>
<h3><a href="{{data.post.link}}">{{{data.post.title.rendered}}}</a></h3>
{{{data.post.excerpt.rendered}}}
<p><a href="{{data.post.link}}">Read at {{data.domain}}&rarr;</a></p>
<p><a href="{{data.post.link}}">Read at {{data.domain}} &rarr;</a></p>
{{#each data.domains}}
<div class="site-container" id="site-{{@key}}">
<div class="site-container" id="site-{{@key}}" data-domain="{{@key}}">
<h2><a href="{{this}}">{{this}}</a></h2>
<span class="latest-post">Loading&hellip;</span>
</div>
......
......@@ -2,6 +2,10 @@
<html>
<head>
<title>erick t. hitter's latest posts</title>
<script src="https://s2.e15r.co/wp-includes/js/jquery/jquery.js"></script>
<link rel="stylesheet" href="css/main.css" />
</head>
<body>
{{{body}}}
......@@ -10,6 +14,8 @@
{{> sites}}
</div>
<script src="js/main.js"></script>
{{> analytics}}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment