Exemple #1
0
    def create(name, force=False):
        """Creates page file.

        Arguments:
            name -- page name (will be used for file name and URL).
            force -- True to overwrite existing file;
                False to throw exception."""
        page_name = urlify(name, ext_map={ord(u"\\"): u"/"}) + ".md"
        file_name = os.path.join(pathes.pages(), page_name)
        if os.path.exists(file_name) and not force:
            raise PageExistsException(path=file_name)
        created = datetime.now().strftime(conf.get("time_format")[0])
        text = const.PROTO_PAGE
        helpers.newfile(file_name, text.format(title=name, created=created))
        return page_name
Exemple #2
0
    def create(name, force=False):
        """Create new post file placeholder with a unique name.

        Arguments:
            name -- post name.
            force -- True to overwrite existing file;
                False to raise an exception."""
        created = datetime.now()
        post_name = urlify(name) or const.UNTITLED_POST
        file_name = PostSource._ymd(POST_NAME_FORMAT, created, post_name)
        post_path = os.path.join(pathes.posts(), file_name)

        count = 0
        while True:
            file_name = helpers.suffix(post_path, count)
            if force or not os.path.exists(file_name):
                created = created.strftime(conf.get("time_format")[0])
                text = const.PROTO_POST
                text = text.format(title=name, created=created)
                helpers.newfile(file_name, text)
                break
            count += 1
        return os.path.basename(file_name)
Exemple #3
0
def tag_path(tag):
    """Returns full path to the specified tag page."""
    file_name = conf.get('tag_location').format(tag=urlify(tag))
    return os.path.join(conf.get('build_path'), file_name)
Exemple #4
0
def tag_url(tag):
    """Returns relative URL to the specified tag page."""
    tag_location = conf.get('tag_location').format(tag=urlify(tag))
    return conf.get('rel_root_url') + tag_location