}); // generate sitemap le_add_workflow('generate_sitemap', function () use($context) { $fp = fopen($context->dir . '_target/sitemap.xml', 'wb'); if (!$fp) { le_fatal('can not write sitemap.xml'); } $base = isset($context->data['url']) ? rtrim($context->data['url'], '/') : '/'; fwrite($fp, '<?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">'); foreach ($context->sitemap as $url => $priority) { $priority = number_format($priority, 2, '.', ''); $url = $base . '/' . ltrim($url, '/'); fwrite($fp, "\n <url>\n <loc>{$url}</loc>\n <changefreq>daily</changefreq>\n <priority>{$priority}</priority>\n </url>"); } fwrite($fp, ' </urlset>'); fclose($fp); }); // compile le_add_workflow('compile', function () use($context) { le_do_workflow('compile_index'); le_do_workflow('compile_metas'); le_do_workflow('compile_posts'); le_do_workflow('generate_feeds'); le_do_workflow('generate_sitemap'); });
$sum = ''; foreach ($context->config['blocks'] as $type => $block) { if (!isset($block['source']) || !is_string($block['source'])) { continue; } $source = trim($block['source'], '/'); $source = empty($source) ? '/' : '/' . $source . '/'; $sources[] = preg_quote($source, '/'); } if (!empty($sources)) { $regex = "/^" . preg_quote(rtrim($context->dir, '/')) . "(" . implode('|', $sources) . ")/"; $files = le_get_all_files($context->dir); foreach ($files as $file => $path) { if (!preg_match($regex, $path) || $file[0] == '.') { continue; } $sum .= md5_file($path); } $sum = md5($sum . md5_file($context->dir . 'config.yaml')); if ($lastSum != $sum) { exec($context->cmd . ' build ' . $context->dir); $lastSum = $sum; } } sleep(1); } }); // import le_add_workflow('import', function () use($context) { le_do_workflow('import.init'); });
le_add_workflow('filter_post', function ($post, $categoriesConfig) { $text = (isset($post['description']) ? $post['description'] : '') . (isset($post['mt_text_more']) ? "\n\n<!--more-->\n\n" . $post['mt_text_more'] : ''); $text = preg_replace("/<\\/p>\\s*<\\/p>/is", "</p>", $text); $text = preg_replace_callback("/<pre[^>]*><code[^>]*>(.+?)<\\/code><\\/pre>/is", function ($matches) { return '<pre>' . $matches[1] . '</pre>'; }, $text); $text = preg_replace_callback("/<code[^>]*>(.+?)<\\/code>/is", function ($matches) { if (false !== strpos($matches[1], "\n")) { return '<pre>' . $matches[1] . '</pre>'; } return '<code>' . $matches[1] . '</code>'; }, $text); $text = preg_replace("/<a[^>]+(href=\"[^\"]+\")[^>]*>/is", "<a \\1>", $text); $text = preg_replace("/<img[^>]+(src=\"[^\"]+\")[^>]*\\/?>/is", "<img \\1>", $text); $parser = new \Markdownify\ConverterExtra(); $content = "\n" . $post['title'] . "\n" . str_repeat('=', strlen($post['title'])) . "\n\n" . $parser->parseString($text); $date = $post['dateCreated']; if (!empty($post['mt_keywords'])) { $content = "@tag:{$post['mt_keywords']}\n" . $content; } if (!empty($post['categories'])) { $categories = []; foreach ($post['categories'] as $category) { $found = array_search($category, $categoriesConfig); if (false !== $found) { $categories[] = $found; } } if (!empty($categories)) { $content = "@category:" . implode(',', $categories) . "\n" . $content; } } $content = "@date:{$date->year}-{$date->month}-{$date->day} {$date->hour}:{$date->minute}:{$date->second}\n" . $content; $content = "@slug:{$post['wp_slug']}\n" . $content; return $content; });