text(trim(file_get_contents($path))); } public static function exists($template) { return is_readable(static::getFullPath($template)); } protected static function isMarkdown($nameOrPath) { return strlen($nameOrPath) > 3 && substr($nameOrPath, -3) == '.md'; } protected static function getFullPath($template) { if ($template && $template[0] == '/') { return $template; } if (static::isMarkdown($template)) { return ROOT_DIR . '/posts/' . $template; } return ROOT_DIR . '/view/template/' . $template . '.php'; } public static function imagePath($image) { return '/img/' . $image; } public static function parseMarkdown($template) { $path = static::getFullPath($template); list($ignored, $frontMatter, $markdown) = explode('---', file_get_contents($path), 3); $metadata = Spyc::YAMLLoadString(trim($frontMatter)); $html = ParsedownExtra::instance()->text(trim($markdown)); return [$metadata, $html]; } public static function compileCss() { $scssCompiler = new \Leafo\ScssPhp\Compiler(); $scssCompiler->setImportPaths([ROOT_DIR.'/web/scss']); $compress = true; if ($compress) { $scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Crunched'); } else { $scssCompiler->setFormatter('Leafo\ScssPhp\Formatter\Expanded'); $scssCompiler->setLineNumberStyle(Leafo\ScssPhp\Compiler::LINE_COMMENTS); } $css = $scssCompiler->compile(file_get_contents(ROOT_DIR.'/web/scss/all.scss')); file_put_contents(ROOT_DIR.'/web/css/all.css', $css); } protected static function interpolateTokens($html) { return preg_replace_callback('/{{[\w\.]+}}/is', function($m) { return i18n::translate(trim($m[0], '}{')); }, $html); } }