コード例 #1
0
def init(path=None, force=False):
    """Create new website."""
    conf.generate(path, force)
    try:
        src = pathes.proto()
        existing = helpers.copydir(src, pathes.site(), force=force)
        if len(existing):
            message = "some existing files were overwritten" if force else \
                "some existing files were NOT overwritten (use --force " \
                "to overwrite)"
            logger.warn("%s\n- %s" % (message, '\n- '.join(existing)))
        logger.info('website created successfully, have fun!')
    except Exception as ex:
        logger.error('initialization failed: ' + str(ex))
        print(str(ex))
コード例 #2
0
ファイル: builders.py プロジェクト: dreikanter/public-static
def posts(cache):
    """Build blog posts and copy the latest post to the site root."""
    for source in cache.posts():
        logger.info(_to('post', source.rel_path(), source.rel_dest()))
        helpers.makedirs(source.dest_dir())
        try:
            data = _complement(source.data())
            templates.render_page(data, source.dest())
        except Exception as ex:
            logger.error('post building error: ' + str(ex))
            logger.debug(traceback.format_exc())

    if conf.get('post_at_root_url'):  # put the latest post at site root url
        last = cache.posts()[0]
        path = os.path.join(conf.get('build_path'), conf.get('index_page'))
        logger.info(_to('root', last.rel_dest(), conf.get('index_page')))
        if any(cache.pages(dest=conf.get('index_page'))):
            logger.warn('root page will be overwritten by the latest post')
        try:
            shutil.copyfile(last.dest(), path)
        except FileNotFoundError:
            logger.error("latest post was not generated and can't be copied")