コード例 #1
0
ファイル: main.php プロジェクト: joyqi/logecho
            exit;
        }
    }
    $dir = __DIR__ . '/../sample';
    $offset = strlen($dir);
    $files = le_get_all_files($dir);
    foreach ($files as $file => $path) {
        if ($file[0] == '.') {
            continue;
        }
        $original = substr($path, $offset);
        $target = $context->dir . $original;
        $dir = dirname($target);
        if (!is_dir($dir)) {
            if (!mkdir($dir, 0755, true)) {
                le_fatal('can not make directory %s, permission denied', $dir);
            }
        }
        copy($path, $target);
    }
});
// serve
le_add_workflow('serve', function () use($context) {
    $target = $context->dir . '_target';
    if (!is_dir($target)) {
        le_console('info', 'building target files, please wait ...');
        exec($context->cmd . ' build ' . $context->dir);
    }
    $proc = proc_open($context->cmd . ' watch ' . $context->dir, [0 => ['pipe', 'r'], 1 => ['pipe', 'w'], 2 => ['file', sys_get_temp_dir() . '/logecho-error.log', 'a']], $pipes, getcwd());
    stream_set_blocking($pipes[0], 0);
    stream_set_blocking($pipes[1], 0);
コード例 #2
0
ファイル: functions.php プロジェクト: joyqi/logecho
/**
 * @param $name
 * @return mixed
 */
function le_do_workflow($name)
{
    global $workflow, $context;
    $args = func_get_args();
    array_shift($args);
    $parts = explode('.', $name, 2);
    if (2 == count($parts)) {
        list($ns) = $parts;
    } else {
        $ns = le_get_current_namespace();
        $name = $ns . '.' . $name;
    }
    require_once __DIR__ . '/../workflow/' . $ns . '.php';
    if (!isset($workflow[$name])) {
        le_fatal('can not find workflow "%s"', $name);
    }
    $desc = implode(', ', array_map(function ($arg) {
        return is_string($arg) ? mb_strimwidth(str_replace(["\r", "\n"], '', $arg), 0, 10, '...', 'UTF-8') : '...';
    }, $args));
    le_console('debug', '%s%s', $name, empty($desc) ? '' : ': ' . $desc);
    return call_user_func_array($workflow[$name], $args);
}
コード例 #3
0
ファイル: compile.php プロジェクト: joyqi/logecho
        $feeds->addItem($item);
    }
    $target = $context->dir . '_target/' . $config['target'];
    $targetDir = dirname($target);
    if (!is_dir($targetDir)) {
        if (!mkdir($targetDir, 0755, true)) {
            le_fatal('feeds directory is not exists "%s"', $targetDir);
        }
    }
    file_put_contents($target, $feeds->generate());
});
// 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>');
コード例 #4
0
ファイル: import.php プロジェクト: joyqi/logecho
     foreach ($categories as $category) {
         $key = explode('.', basename(rtrim($category['htmlUrl'], '/')))[0];
         $context->config['blocks']['category']['source'][$key] = $category['categoryName'];
     }
 }
 if (!file_put_contents($context->dir . 'config.yaml', Spyc::YAMLDump($context->config, 4))) {
     le_fatal('can not write to config file: %sconfig.yaml', $context->dir);
 }
 if (in_array('metaWeblog.getRecentPosts', $methods)) {
     le_console('info', 'fetching posts');
     $posts = $xmlrpc->query('metaWeblog.getRecentPosts', $blogId, $username, $password, 1000);
     $source = $context->dir . $context->config['blocks']['post']['source'];
     $target = rtrim($context->config['globals']['url'], '/') . '/' . trim(isset($context->config['blocks']['post']['target']) ? $context->config['blocks']['post']['target'] : 'post', '/') . '/%s.' . (isset($context->config['blocks']['post']['ext']) ? $context->config['blocks']['post']['ext'] : 'html');
     if (!is_dir($source)) {
         if (!mkdir($source, 0755, true)) {
             le_fatal('can not make post target directory: %s', $source);
         }
     }
     foreach ($posts as $post) {
         if ('publish' != $post['post_status']) {
             continue;
         }
         le_console('info', 'add %s', $post['wp_slug']);
         $content = le_do_workflow('filter_post', $post, $context->config['blocks']['category']['source']);
         file_put_contents($source . '/' . $post['wp_slug'] . '.md', $content);
         if (in_array('wp.getComments', $methods)) {
             $offset = 0;
             le_console('info', 'fetching comments: %s', $post['postid']);
             do {
                 $comments = $xmlrpc->query('wp.getComments', $blogId, $username, $password, ['post_id' => $post['postid'], 'number' => 100, 'offset' => $offset]);
                 foreach ($comments as $c) {