Verified Commit 557aeb70 authored by Erick Hitter's avatar Erick Hitter
Browse files

Insert render latest post into document

parent 1fc35843
...@@ -25,11 +25,12 @@ app.get( '/', function( req, res ) { ...@@ -25,11 +25,12 @@ app.get( '/', function( req, res ) {
res.render( 'index', { data: { domains: domains } } ); res.render( 'index', { data: { domains: domains } } );
} ); } );
// Get some data // API requests require a domain
app.get( '/api', function( req, res ) { app.get( '/api', function( req, res ) {
res.status( 400 ).json( { error: 'Must specify a domain!' } ); res.status( 400 ).json( { error: 'Must specify a domain!' } );
} ); } );
// Render the domain's latest post
app.get( '/api/:domain', function( req, res ) { app.get( '/api/:domain', function( req, res ) {
// For convenience // For convenience
var domain = req.params.domain; var domain = req.params.domain;
...@@ -61,6 +62,9 @@ app.get( '/api/:domain', function( req, res ) { ...@@ -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 // Listen on some random, unused port
// App is meant to be fronted by nginx // App is meant to be fronted by nginx
app.listen( 5060, function() { 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}}} {{{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}} {{#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> <h2><a href="{{this}}">{{this}}</a></h2>
<span class="latest-post">Loading&hellip;</span> <span class="latest-post">Loading&hellip;</span>
</div> </div>
......
...@@ -2,6 +2,10 @@ ...@@ -2,6 +2,10 @@
<html> <html>
<head> <head>
<title>erick t. hitter's latest posts</title> <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> </head>
<body> <body>
{{{body}}} {{{body}}}
...@@ -10,6 +14,8 @@ ...@@ -10,6 +14,8 @@
{{> sites}} {{> sites}}
</div> </div>
<script src="js/main.js"></script>
{{> analytics}} {{> analytics}}
</body> </body>
</html> </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