get('system.pages.theme'); $theme_path = 'themes://' . $current_theme . '/blueprints'; $locator->addPath('blueprints', '', [$theme_path]); return static::recurseFolder('blueprints://'); } public static function recurseFolder($path, $extensions = 'md|yaml') { $lint_errors = []; /** @var UniformResourceLocator $locator */ $locator = Grav::instance()['locator']; $flags = \RecursiveDirectoryIterator::SKIP_DOTS; if ($locator->isStream($path)) { $directory = $locator->getRecursiveIterator($path, $flags); } else { $directory = new \RecursiveDirectoryIterator($path, $flags); } $recursive = new \RecursiveIteratorIterator($directory, \RecursiveIteratorIterator::SELF_FIRST); $iterator = new \RegexIterator($recursive, '/^.+\.'.$extensions.'$/i'); /** @var \RecursiveDirectoryIterator $file */ foreach ($iterator as $filepath => $file) { try { Yaml::parse(static::extractYaml($filepath)); } catch (\Exception $e) { $lint_errors[str_replace(GRAV_ROOT, '', $filepath)] = $e->getMessage(); } } return $lint_errors; } protected static function extractYaml($path) { $extension = pathinfo($path, PATHINFO_EXTENSION); if ($extension === 'md') { $file = MarkdownFile::instance($path); $contents = $file->frontmatter(); } else { $contents = file_get_contents($path); } return $contents; } }