From daaa6f3bfdc87067f20eeef85c1933a16f718e43 Mon Sep 17 00:00:00 2001 From: Guangcong Luo Date: Fri, 20 Sep 2013 16:48:24 -0500 Subject: [PATCH] Embed news into HTML for faster loading --- .gitignore | 2 +- githooks/update-version-query-strings | 16 +++++++++--- index.template.html => index.template.php | 31 ++++++++++++++++++++--- js/client-mainmenu.js | 23 +++++++---------- js/client.js | 8 ++++-- robots.txt | 3 +++ 6 files changed, 59 insertions(+), 24 deletions(-) rename index.template.html => index.template.php (80%) diff --git a/.gitignore b/.gitignore index de567b133..11229a42f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /sprites/ /audio/ /js/config.js -/index.html +/index.php .DS_Store diff --git a/githooks/update-version-query-strings b/githooks/update-version-query-strings index 3235d0b92..6671d7bdf 100755 --- a/githooks/update-version-query-strings +++ b/githooks/update-version-query-strings @@ -9,15 +9,23 @@ * post-commit, post-checkout, post-merge, post-rewrite */ +date_default_timezone_set('America/Los_Angeles'); + +include __DIR__.'/../../pokemonshowdown.com/news/include.php'; + function replaceMatch($m) { $filename = str_replace('/play.pokemonshowdown.com/', '', $m[2]); $hash = substr(md5_file($filename), 0, 8); return "${m[1]}=\"/${m[2]}?${hash}\""; } -file_put_contents('index.html', - preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/', - 'replaceMatch', - file_get_contents('index.template.html')) +file_put_contents('index.php', + str_replace('', + getNewsId(), + str_replace('', + ''.renderNews().'', + preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/', + 'replaceMatch', + file_get_contents('index.template.php')))) ); diff --git a/index.template.html b/index.template.php similarity index 80% rename from index.template.html rename to index.template.php index 051348d6d..bb407f04b 100644 --- a/index.template.html +++ b/index.template.php @@ -67,9 +67,34 @@ -
-
Initializing...
-
+ diff --git a/js/client-mainmenu.js b/js/client-mainmenu.js index 816956bec..15ccef913 100644 --- a/js/client-mainmenu.js +++ b/js/client-mainmenu.js @@ -17,13 +17,11 @@ initialize: function() { this.$el.addClass('scrollable'); - var buf = ''; + this.$('.mainmenu').html(buf); // right menu if (!app.down) { - buf += '
'; + this.$('.rightmenu').html(''); } // footer - buf += ''; - - buf += ''; - this.$el.html(buf); + // (created during page load) this.$activityMenu = this.$('.activitymenu'); this.$pmBox = this.$activityMenu.find('.pmbox'); @@ -69,9 +65,6 @@ this.updateFormats(); app.user.on('saveteams', this.updateTeams, this); - - app.on('init:loadprefs', this.addNews, this); - if (app.prefsLoaded) this.addNews(); }, // news @@ -188,7 +181,9 @@ // not a true PM; just close the window $pmWindow = $(e.currentTarget).closest('.pm-window'); var newsId = $pmWindow.data('newsid'); - if (newsId) Tools.prefs('readnews', ''+newsId); + if (newsId) { + $.cookie('showdown_readnews', ''+newsId, {expires: 365}); + } $pmWindow.remove(); return; } diff --git a/js/client.js b/js/client.js index ef3bfdf0b..4397a039d 100644 --- a/js/client.js +++ b/js/client.js @@ -209,7 +209,6 @@ focused: true, initialize: function() { window.app = this; - $('#main').html(''); this.initializeRooms(); this.initializePopups(); @@ -1098,7 +1097,12 @@ } } - var el = $('').appendTo('body'); + var el; + if (!id) { + el = $('#mainmenu'); + } else { + el = $('').appendTo('body'); + } var typeName = ''; if (typeof type === 'string') { typeName = type; diff --git a/robots.txt b/robots.txt index 060ef2e27..c56922cbb 100644 --- a/robots.txt +++ b/robots.txt @@ -1,3 +1,6 @@ +User-agent: Mediapartners-Google +Disallow: + User-agent: * Disallow: /