diff --git a/CHANGELOG.md b/CHANGELOG.md index 81ccf07..3f3b6d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/). +## [1.2.0] - 2020-02-03 + +### Added + +- Added the ability to handle array values and auto templates. Thanks [@iv-agatha](https://github.com/iv-agatha) + ## [1.1.1] - 2019-02-20 ### Changed diff --git a/README.md b/README.md index c856e06..a19e85c 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,18 @@ The `mix()` helper function reads the `mix-manifest.json` file and returns the r + + ``` diff --git a/index.php b/index.php index d690a83..e57d152 100644 --- a/index.php +++ b/index.php @@ -15,10 +15,23 @@ */ function mix($path) { + // Handle arrays + if (is_array($path)) { + $assets = []; + + foreach($path as $p) { + $assets[] = mix($p); + } + + return implode(PHP_EOL, $assets) . PHP_EOL; + } + static $manifest = []; + $isAuto = Str::contains($path, '@auto'); + // Get the correct $path - if (!Str::startsWith($path, '/')) { + if (!Str::startsWith($path, '/') && !$isAuto) { $path = "/{$path}"; } @@ -36,7 +49,7 @@ function mix($path) if (!$manifest) { if (! F::exists($manifestPath)) { if (option('debug')) { - throw new Exception('The Mix manifest does not exists.'); + throw new Exception('The Mix manifest does not exist.'); } else { return false; } @@ -45,9 +58,26 @@ function mix($path) $manifest = json_decode(F::read($manifestPath), 'json'); } + // Get auto templates + if ($isAuto) { + if ($path == '@autocss') { + $type = 'css'; + } else if($path == '@autojs') { + $type = 'js'; + } else { + if(option('debug')) { + throw new Exception("File type not recognized"); + } else { + return false; + } + } + + $path = '/'.$type.'/templates/'.kirby()->site()->page()->intendedTemplate().'.'.$type; + } + // Check if the manifest contains the given $path - if (! array_key_exists($path, $manifest)) { - if (option('debug')) { + if (!array_key_exists($path, $manifest)) { + if (option('debug') && !$isAuto) { throw new Exception("Unable to locate Mix file: {$path}."); } else { return false; diff --git a/package.json b/package.json index ccea178..b039776 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "laravel-mix-kirby", "description": "Laravel Mix helper for the Kirby CMS", "author": "Robert Cordes ", - "version": "1.0.0", + "version": "1.2.0", "type": "kirby-plugin", "license": "MIT" }