def post(path=None, name=None, force=False, edit=False): """Create new post.""" conf.load(path) path = source.PostSource.create(name, force) logger.info('post created: ' + path) if edit: helpers.execute(conf.get('editor_cmd'), path)
def page(path=None, name=None, force=False, edit=False): """Create new page.""" conf.load(path) try: path = source.PageSource.create(name, force) except source.PageExistsException: logger.error('page already exists, use -f to overwrite') return logger.info('page created: ' + path) if edit: helpers.execute(conf.get('editor_cmd'), path)
def js(cache): """Minify JavaScript files to the build path.""" for source in cache.assets(ext='.js'): helpers.makedirs(source.dest_dir()) command = conf.get('min_js_cmd') if conf.get('min_js') and command: logger.info('minifying JavaScript: ' + source.rel_path()) helpers.execute(command, source.path(), source.dest()) else: logger.info('copying: ' + source.rel_path()) shutil.copyfile(source.path(), source.dest()) helpers.utime(source.dest(), source.updated()) source.processed(True)
def less(cache): """Compile and minify less files.""" for source in cache.assets(ext='.less'): helpers.makedirs(source.dest_dir()) logger.info('compiling LESS: ' + source.rel_path()) if conf.get('min_css') and conf.get('min_css_cmd'): tmp_file = os.path.join(source.dest_dir(), '_' + source.basename()) helpers.execute(conf.get('less_cmd'), source.path(), tmp_file) logger.info('minifying CSS: ' + source.rel_path()) helpers.execute(conf.get('min_css_cmd'), tmp_file, source.dest()) os.remove(tmp_file) else: helpers.execute(conf.get('less_cmd'), source.path(), source.dest()) helpers.utime(source.dest(), source.updated()) source.processed(True)