def default_mkdir(): load_base() safe_mkdir(g.path.posts) safe_mkdir(g.path.images) safe_mkdir(g.path.site) safe_mkdir(g.path.templates) with indent(2, quote='>'): puts('all directories were initiated successfully.')
def new_post(filename): try: load_config() load_base() load_path() initial_content = 'title: Your post title\ndate: %s\n\nStart writing here...' % datetime.now().strftime('%Y-%m-%d %H:%M:%S') write(g.path.posts, filename + '.md', initial_content) puts(colored.green('New post is written successfully.')) except: puts(colored.red('Post cannot be written.'))
def install(template): load_base() force_mkdir(get_path(g.path.templates, template)) templates = urllib2.urlopen('https://raw.github.com/shunfan/hazel/master/templates.yml').read() templates = yaml.load(templates) try: git_template = templates[template] os.chdir(g.path.templates) os.system('git clone %s' % git_template) puts(colored.green('Template is installed properly, please change the template name in the general config file manually.')) except: shutil.rmtree(get_path(g.path.templates, template)) puts(colored.red('Template %s is not found or installed properly.' % template))
def generate(): try: load_config() load_base() load_path() load_template_config() load_jinja() reset() handle_posts() handle_pages() copy_assets() puts(colored.green('Complete.')) except: puts(colored.red('Generated fail, please check if all files are in the directory.'))