mikuli.cz

:)
git clone https://git.sr.ht/~ashymad/mikuli.cz
Log | Files | Refs

commit d44419630aafca74a3bf5ca1aa15f03c6b979d38
parent 04e4ee59d94ba905b7f590be4c2263e8f071667f
Author: markseu <mark2011@mayberg.se>
Date:   Wed, 11 Mar 2020 14:05:01 +0100

Updated bundle extension, auto-versioning for CSS/JavaScript

Diffstat:
Msystem/extensions/bundle.php | 24++++++++++++++----------
Msystem/extensions/edit.php | 6+++---
2 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/system/extensions/bundle.php b/system/extensions/bundle.php @@ -4,7 +4,7 @@ // This file may be used and distributed under the terms of the public license. class YellowBundle { - const VERSION = "0.8.8"; + const VERSION = "0.8.9"; const TYPE = "feature"; public $yellow; //access to API @@ -48,7 +48,7 @@ class YellowBundle { // Normalise page head public function normaliseHead($text) { - $dataMeta = $dataLink = $dataCss = $dataScript = $dataOther = array(); + $dataMeta = $dataLink = $dataCss = $dataScriptDefer = $dataScriptNow = $dataOther = array(); foreach ($this->yellow->toolbox->getTextLines($text) as $line) { if (preg_match("/^<meta (.*?)>$/i", $line) || preg_match("/^<title>(.*?)<\/title>$/i", $line)) { array_push($dataMeta, $line); @@ -60,9 +60,9 @@ class YellowBundle { } } elseif (preg_match("/^<script (.*?)src=\"([^\"]+)\"(.*?)><\/script>$/i", $line, $matches)) { if (preg_match("/\"defer\"/i", $line)) { - if (is_null($dataScript[$matches[2]])) $dataScript[$matches[2]] = $line; + if (is_null($dataScriptDefer[$matches[2]])) $dataScriptDefer[$matches[2]] = $line; } else { - array_push($dataOther, $line); + if (is_null($dataScriptNow[$matches[2]])) $dataScriptNow[$matches[2]] = $line; } } else { array_push($dataOther, $line); @@ -70,14 +70,16 @@ class YellowBundle { } if (!defined("DEBUG") || DEBUG==0) { $dataCss = $this->processBundle($dataCss, "css"); - $dataScript = $this->processBundle($dataScript, "js"); + $dataScriptDefer = $this->processBundle($dataScriptDefer, "js", "defer"); + $dataScriptNow = $this->processBundle($dataScriptNow, "js"); } - $output = implode($dataMeta).implode($dataLink).implode($dataCss).implode($dataScript).implode($dataOther); + $output = implode($dataMeta).implode($dataLink).implode($dataCss). + implode($dataScriptDefer).implode($dataScriptNow).implode($dataOther); return $output; } // Process bundle, create file on demand - public function processBundle($data, $type) { + public function processBundle($data, $type, $attribute = "") { $fileNames = array(); $scheme = $this->yellow->system->get("coreServerScheme"); $address = $this->yellow->system->get("coreServerAddress"); @@ -95,13 +97,15 @@ class YellowBundle { } } if (!empty($fileNames)) { - $id = substru(md5(implode($fileNames).$base), 0, 10); - $fileNameBundle = $this->yellow->system->get("coreResourceDir")."bundle-$id.min.$type";; + $autoVersioning = intval($modified/(60*60*24)); + $id = substru(md5($autoVersioning.$base.implode($fileNames)), 0, 10); + $fileNameBundle = $this->yellow->system->get("coreResourceDir")."bundle-$id.min.$type"; $locationBundle = $base.$this->yellow->system->get("coreResourceLocation")."bundle-$id.min.$type"; + $rawDataAttribute = $attribute=="defer" ? "defer=\"defer\" " : ""; if ($type=="css") { $data[$locationBundle] = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"".htmlspecialchars($locationBundle)."\" />\n"; } else { - $data[$locationBundle] = "<script type=\"text/javascript\" defer=\"defer\" src=\"".htmlspecialchars($locationBundle)."\"></script>\n"; + $data[$locationBundle] = "<script type=\"text/javascript\" ${rawDataAttribute}src=\"".htmlspecialchars($locationBundle)."\"></script>\n"; } if ($this->yellow->toolbox->getFileModified($fileNameBundle)!=$modified) { foreach ($fileNames as $fileName) { diff --git a/system/extensions/edit.php b/system/extensions/edit.php @@ -4,7 +4,7 @@ // This file may be used and distributed under the terms of the public license. class YellowEdit { - const VERSION = "0.8.23"; + const VERSION = "0.8.24"; const TYPE = "feature"; public $yellow; //access to API public $response; //web response @@ -73,8 +73,8 @@ class YellowEdit { $output = null; if ($name=="header" && $this->response->isActive()) { $extensionLocation = $this->yellow->system->get("coreServerBase").$this->yellow->system->get("coreExtensionLocation"); - $output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" data-bundle=\"exclude\" href=\"{$extensionLocation}edit.css\" />\n"; - $output .= "<script type=\"text/javascript\" data-bundle=\"exclude\" src=\"{$extensionLocation}edit.js\"></script>\n"; + $output = "<link rel=\"stylesheet\" type=\"text/css\" media=\"all\" href=\"{$extensionLocation}edit.css\" />\n"; + $output .= "<script type=\"text/javascript\" src=\"{$extensionLocation}edit.js\"></script>\n"; $output .= "<script type=\"text/javascript\">\n"; $output .= "// <![CDATA[\n"; $output .= "yellow.page = ".json_encode($this->response->getPageData($page)).";\n";