granam/web-content-builder

Builds HTML from HTML files, markdown or PHP script

Installs: 393

Dependents: 7

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:composer-plugin

2.3.2 2022-01-03 15:04 UTC

README

Injecting asset versions

CSS example

Example with injecting image md5 sum linked in a CSS file.

$assetsVersion = new \Granam\WebContentBuilder\AssetsVersion(); // will scan for *.css, *.html and *.md by default,

/** body {
    background-image: url("/img/someone.jpeg");
} */
echo file_get_contents(__DIR__ . '/css/main.css');

$changedFiles = $assetsVersion->addVersionsToAssetLinks(
    __DIR__ /* as document root */,
    ['css' ]/* to document root relative dirs to scan */,
    []/* no dirs to exclude */,
    []/* no exact files to scan */,
    false /* no dry run to change files directly */
);
/** Array (
    [0] => '/home/jaroslav/projects/granam/web-content-builder/css/main.css'
) */
print_r($changedFiles);


/** body {
    background-image: url("/img/someone.jpeg?version=664a924915e642c7dc89af370114629a");
} */
echo file_get_contents(__DIR__ . '/css/main.css');
echo md5_file(__DIR__ . '/img/someone.jpeg'); // 664a924915e642c7dc89af370114629a