def pages(cache): """Build site pages.""" for source in cache.pages(): logger.info(_to('page', source.rel_path(), source.rel_dest())) helpers.makedirs(source.dest_dir()) try: data = _complement(source.data(), index=cache.index()) templates.render_page(data, source.dest()) except Exception as ex: logger.error('page building error: ' + str(ex)) logger.debug(traceback.format_exc())
def humans(cache): """Build humans.txt.""" for source in cache.assets(basename='humans.txt'): logger.info('processing ' + source.rel_path()) helpers.makedirs(source.dest_dir()) try: data = _complement({}) templates.render_file(source.path(), data, source.dest()) except Exception as ex: logger.error('humans.txt processing failed: ' + str(ex)) logger.debug(traceback.format_exc()) finally: source.processed(True)
def deploy(path=None): """Deploy generated website to the remote web server.""" conf.load(path) helpers.check_build(conf.get('build_path')) logger.info('deploying website...') if not conf.get('deploy_cmd'): raise Exception('deploy command is not defined') cmd = conf.get('deploy_cmd').format(build_path=conf.get('build_path')) try: output = subprocess.check_output(cmd, shell=True) logger.debug("Command output:\n%s" % output.decode('utf-8')) logger.info('done') except subprocess.CalledProcessError as e: logger.error(e) logger.debug("Command output:\n%s" % e.output.decode('utf-8'))
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")