Skip to content

Commit

Permalink
Load initial entries server-side rather than via AJAX for SEO benefit
Browse files Browse the repository at this point in the history
  • Loading branch information
mjangda committed Jun 6, 2012
1 parent 8ff4206 commit cb778e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions js/liveblog.js
Expand Up @@ -3,6 +3,8 @@ var liveblog = {};
( function( $ ) {

liveblog.init = function() {
liveblog.set_timestamp( liveblog_settings.last_timestamp );

liveblog.$container = $( '#liveblog-entries' );

// Damn you wp_localize_script
Expand All @@ -11,7 +13,7 @@ var liveblog = {};
liveblog_settings.delay_threshold = parseInt( liveblog_settings.delay_threshold );
liveblog_settings.delay_multiplier = parseFloat( liveblog_settings.delay_multiplier );

liveblog.get_recent_entries();
liveblog.reset_timer();
}

liveblog.kill_timer = function() {
Expand Down Expand Up @@ -151,7 +153,7 @@ var liveblog = {};
// If the entry is already there, update it
var $entry = $( '#liveblog-entry-' + entry.ID );
if ( $entry.length ) {
$entry.html( entry.content )
$entry.replaceWith( entry.content )
.addClass( 'liveblog-updated' )
.one( 'mouseover', function() {
$( this ).removeClass( 'liveblog-updated' );
Expand Down
18 changes: 13 additions & 5 deletions liveblog.php
Expand Up @@ -14,7 +14,6 @@
TODO (future):
-- Manual refresh button
-- Allow marking of liveblog as ended
-- SEO consideration (output entries server-side on initial load)
-- Allow comment modifications; need to store modified date as comment_meta
-- Drag-and-drop image uploading support
Expand Down Expand Up @@ -134,7 +133,7 @@ function ajax_get_recent_entries( $timestamp = 0 ) {
foreach( $entries as $entry ) {
$filtered_entry = new stdClass;
$filtered_entry->ID = $entry->comment_ID;
$filtered_entry->content = self::entry_output( $entry, array(), false );
$filtered_entry->content = self::entry_output( $entry, false );
array_push( $filtered_entries, $filtered_entry );
}

Expand All @@ -144,7 +143,7 @@ function ajax_get_recent_entries( $timestamp = 0 ) {
self::json_return( true, '', array( 'entries' => $filtered_entries, 'timestamp' => $last_timestamp ) );
}

function entry_output( $entry, $args = array(), $echo = true ) {
function entry_output( $entry, $echo = true ) {
$entry_id = $entry->comment_ID;
$post_id = $entry->comment_post_ID;
$output = '';
Expand All @@ -154,7 +153,7 @@ function entry_output( $entry, $args = array(), $echo = true ) {
if ( $output )
return $output;

$args = wp_parse_args( $args, array(
$args = apply_filters( 'liveblog_entry_output_args', array(
'avatar_size' => 30,
) );

Expand Down Expand Up @@ -232,6 +231,7 @@ function enqueue_scripts() {
'nonce_key' => self::nonce_key,
'permalink' => get_permalink(),
'post_id' => get_the_ID(),
'last_timestamp' => self::get_last_entry_timestamp(),

'refresh_interval' => self::refresh_interval,
'max_retries' => self::max_retries,
Expand All @@ -249,9 +249,17 @@ function enqueue_scripts() {
}

function add_liveblog_to_content( $content ) {
$post_id = get_the_ID();
$entries = self::get_entries_since( $post_id );

$liveblog_output = '';
$liveblog_output .= self::get_entry_editor_output();
$liveblog_output .= '<div id="liveblog-entries" class="liveblog-container"></div>';
$liveblog_output .= '<div id="liveblog-entries" class="liveblog-container">';
foreach ( (array) $entries as $entry ) {
$liveblog_output .= self::entry_output( $entry, false );
}

$liveblog_output .= '</div>';

return $content . $liveblog_output;
}
Expand Down

0 comments on commit cb778e4

Please sign in to comment.