def new_post(title, tag, category, edit, image):
    """Creates an empty markdown post with the given title for Jekyll in the 
    directory specified by the configs. It will include a front-matter
    with the default options and optional tags or categories.
    """

    if image:
        contents = _get_contents_img()
    else:
        contents = _get_contents_no_img()

    slug = slugify(title)
    date = datetime.now()
    date_str = date.strftime("%Y-%m-%d %H:%M:%S %z")
    tags = ",".join(list(map(lambda el: '"' + str(el).strip() + '"', tag)))
    categories = ",".join(
            list(map(lambda el: '"' + str(el).strip() + '"', category)))

    file_name = date.strftime("%Y-%m-%d") + "-" + slug + ".markdown"

    path_to_file = get_path_to_posts_dir().rstrip("/") + "/" + file_name

    with open(path_to_file, "w") as f:
        f.write(textwrap
                .dedent(contents)
                .lstrip()
                .format(title, date_str, tags, categories))

    if edit:
        editor = get_editor_name()
        editor_executable = get_executable_from_name(editor)
        call([editor_executable, path_to_file])
        time.sleep(2)  # just to give the os time for the editor to load

    click.echo(wrap_success("Post created at: {0}".format(path_to_file)))
Exemple #2
0
def clear_configs():
    configs.clear_configs()
    click.echo(wrap_success("Configs cleared"))
Exemple #3
0
def set_path_to_posts_dir(path):
    absolute_path = files.resolve_path(path)
    configs.set_path_to_posts_dir(absolute_path)
    click.echo(wrap_success(
        """Config key "path-to-jekyll-posts" was set to "{0}" """.format(path)))
Exemple #4
0
def set_editor(name):
    configs.set_editor_name(name)
    click.echo(
        wrap_success("""Config key "editor" was set to "{0}" """.format(name)))