24 lines
640 B
Plaintext
24 lines
640 B
Plaintext
|
#!/usr/bin/php
|
||
|
<?php
|
||
|
|
||
|
// Embed content into HTML file
|
||
|
function embed($filename, $mode, $find, $sourcefile) {
|
||
|
$html_content = file_get_contents($filename);
|
||
|
$modes = [
|
||
|
'js' => ['script', 'script'],
|
||
|
'css' => ['link', 'style'],
|
||
|
];
|
||
|
|
||
|
$html_content = preg_replace_callback(
|
||
|
'~<'. $modes[$mode][0] .'[^>]+'.$find.'[^>]*>~',
|
||
|
function() use ($modes, $mode, $sourcefile) {
|
||
|
return '<'. $modes[$mode][1] . '>'.file_get_contents($sourcefile).'</'. $modes[$mode][1] .'>';
|
||
|
},
|
||
|
$html_content
|
||
|
);
|
||
|
|
||
|
file_put_contents($filename, $html_content);
|
||
|
}
|
||
|
|
||
|
embed($_SERVER['argv'][1], $_SERVER['argv'][2], $_SERVER['argv'][3], $_SERVER['argv'][4]);
|