* * This file is part of Kirby Library. * * Kirby Library is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation. * * Kirby Library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License along with Kirby Library. If not, see . */ Kirby::plugin( name: "hobbyhome/library", extends: [ "options" => [ "assets" => [ "css" => [ # 100 => Url::path(kirby()->url("media") . "/plugins/hobbyhome/library/css/example.css", true), ], ], ], "hooks" => [ /** * To add this hook to a plugin, change the option() call to use the plugins name. * * @version 1.0 */ "hobbyhome.getAssets" => function ($files = [], $type = "css") { foreach (option("hobbyhome.library.assets.{$type}", []) as $order => $file) { # Make sure no other file exists with the current sort order index. while (isset($files[$order])) { $order++; } $files[$order] = $file; } return $files; }, ], "siteMethods" => [ /** * Fetch and sort a list of asset filenames. * * @param string $type The type of asset filenames to fetch. * * @return Array of asset filenames, sorted by index. */ "getAssets" => function ($type = "css") { $hookFiles = kirby()->apply("hobbyhome.getAssets", ["files" => [], "type" => $type], "files"); $files = []; foreach ($hookFiles as $order => $file) { # If file exists, add MD5 query string to attempt to cache bust it. $md5 = F::exists(kirby()->root() . $file) ? md5_file(kirby()->root() . $file) : ""; $files[$order] = url($file, ["query" => ["md5" => $md5]]); } ksort($files, SORT_NUMERIC); return $files; }, ], ], info: [ "authors" => [[ "name" => "Dreytac", "email" => "dreytac@hobbyhome.net", "homepage" => "https://hobbyhome.net", ]], "license" => "AGPL-3.0-only", "version" => "0.0.0", ], );