Skip to content

Commit

Permalink
Support both static/dynamic index pages
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarel committed Oct 4, 2013
1 parent 476e698 commit c883db6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
/audio/
/js/config.js
/index.php
/index.html
.DS_Store
31 changes: 31 additions & 0 deletions githooks/update-version-query-strings-dynamic
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env php
<?php
/**
* This script parses index.php and sets the version query string of each
* resource to be the MD5 hash of that resource. This script should be executed
* from the base directory of the repository.
*
* On the live web server, this script is set as the following git hooks:
* 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.php',
str_replace('<!-- newsid -->',
getNewsId(),
str_replace('<!-- news -->',
''.renderNews().'',
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
'replaceMatch',
file_get_contents('index.template.php'))))
);

0 comments on commit c883db6

Please sign in to comment.