pokemon-showdown-client/githooks/update-version-query-strings
2013-01-26 13:56:41 -07:00

23 lines
642 B
PHP
Executable File

#!/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
*/
function replaceMatch($m) {
$hash = substr(md5_file($m[2]), 0, 8);
return "${m[1]}=\"/${m[2]}?${hash}\"";
}
file_put_contents('index.php',
preg_replace_callback('/(src|href)="\/(.*?)\?[a-z0-9]*?"/',
'replaceMatch',
file_get_contents('index.php.template.txt'))
);