Пример #1
0
def create_permalink(auto_permalink_path, site_url,
                     blog_path, title, date, uuid, filename):
    """
    >>> d = {"site_url" : "http://www.example.com",\
         "blog_path" : "/blog",\
         "title" : "Test Title",\
         "date" : datetime(2011, 2, 28),\
         "uuid" : "123456789-aaaa-12345",\
         "filename" : "001-post-one.markdown" }
    >>> create_permalink(":blog_path/:year/:month/:title",**d)
    'http://www.example.com/blog/2011/02/test-title'
    >>> create_permalink("/:uuid/fuzz/:filename",**d)
    'http://www.example.com/123456789-aaaa-12345/fuzz/001-post-one.markdown'
    """
    permalink = site_url.rstrip("/") + auto_permalink_path
    permalink = \
        re.sub(":blog_path", blog_path, permalink)
    permalink = \
        re.sub(":year", date.strftime("%Y"), permalink)
    permalink = \
        re.sub(":month", date.strftime("%m"), permalink)
    permalink = \
        re.sub(":day", date.strftime("%d"), permalink)
    permalink = \
        re.sub(":hour", date.strftime("%H"), permalink)
    permalink = \
        re.sub(":minute", date.strftime("%M"), permalink)
    permalink = \
        re.sub(":second", date.strftime("%S"), permalink)
    permalink = \
        re.sub(":title", create_slug(title), permalink)
    permalink = \
        re.sub(":filename", create_slug(filename), permalink)
    permalink = re.sub(":uuid", uuid, permalink)
    return permalink
Пример #2
0
def create_permalink(auto_permalink_path, site_url, blog_path, title, date,
                     uuid, filename):
    """
    >>> d = {"site_url" : "http://www.example.com",\
         "blog_path" : "/blog",\
         "title" : "Test Title",\
         "date" : datetime(2011, 2, 28),\
         "uuid" : "123456789-aaaa-12345",\
         "filename" : "001-post-one.markdown" }
    >>> create_permalink(":blog_path/:year/:month/:title",**d)
    'http://www.example.com/blog/2011/02/test-title'
    >>> create_permalink("/:uuid/fuzz/:filename",**d)
    'http://www.example.com/123456789-aaaa-12345/fuzz/001-post-one.markdown'
    """
    permalink = site_url.rstrip("/") + auto_permalink_path
    permalink = \
        re.sub(":blog_path", blog_path, permalink)
    permalink = \
        re.sub(":year", date.strftime("%Y"), permalink)
    permalink = \
        re.sub(":month", date.strftime("%m"), permalink)
    permalink = \
        re.sub(":day", date.strftime("%d"), permalink)
    permalink = \
        re.sub(":hour", date.strftime("%H"), permalink)
    permalink = \
        re.sub(":minute", date.strftime("%M"), permalink)
    permalink = \
        re.sub(":second", date.strftime("%S"), permalink)
    permalink = \
        re.sub(":title", create_slug(title), permalink)
    permalink = \
        re.sub(":filename", create_slug(filename), permalink)
    permalink = re.sub(":uuid", uuid, permalink)
    return permalink
Пример #3
0
def create_permalink(auto_permalink_path, site_url, blog_path, title, date, uuid, filename):
    permalink = site_url.rstrip("/") + auto_permalink_path
    permalink = re.sub(":blog_path", blog_path, permalink)
    permalink = re.sub(":year", date.strftime("%Y"), permalink)
    permalink = re.sub(":month", date.strftime("%m"), permalink)
    permalink = re.sub(":day", date.strftime("%d"), permalink)
    permalink = re.sub(":hour", date.strftime("%H"), permalink)
    permalink = re.sub(":minute", date.strftime("%M"), permalink)
    permalink = re.sub(":second", date.strftime("%S"), permalink)
    permalink = re.sub(":title", create_slug(title), permalink)
    permalink = re.sub(":filename", create_slug(filename), permalink)
    permalink = re.sub(":uuid", uuid, permalink)
    return permalink
Пример #4
0
def create_permalink(auto_permalink_path, site_url, blog_path, title, date,
                     uuid, filename):
    permalink = site_url.rstrip("/") + auto_permalink_path
    permalink = re.sub(":blog_path", blog_path, permalink)
    permalink = re.sub(":year", date.strftime("%Y"), permalink)
    permalink = re.sub(":month", date.strftime("%m"), permalink)
    permalink = re.sub(":day", date.strftime("%d"), permalink)
    permalink = re.sub(":hour", date.strftime("%H"), permalink)
    permalink = re.sub(":minute", date.strftime("%M"), permalink)
    permalink = re.sub(":second", date.strftime("%S"), permalink)
    permalink = re.sub(":title", create_slug(title), permalink)
    permalink = re.sub(":filename", create_slug(filename), permalink)
    permalink = re.sub(":uuid", uuid, permalink)
    return permalink
Пример #5
0
 def __init__(self, name):
     self.name = str(name)
     # TODO: consider making url_name and path read-only properties?
     self.url_name = create_slug(self.name)
     self.path = bf.util.site_path_helper(
         blog_config.path, blog_config.category_dir, self.url_name, trailing_slash=True
     )
Пример #6
0
 def __post_process(self):
     # fill in empty default value
     if not self.date:
         self.date = datetime.datetime.now(pytz.timezone(self.__timezone))
     if not self.updated:
         self.updated = self.date
     #Make sure dates have timezone info:
     if not self.date.tzinfo:
         pytz.timezone(self.__timezone).localize(self.date)
     if not self.updated.tzinfo:
         pytz.timezone(self.__timezone).localize(self.updated)
     if not self.title:
         self.title = "Untitled - {0}".format(self.date)
     if not self.slug:
         self.slug = create_slug(self.title)
     if not self.categories or len(self.categories) == 0:
         self.categories = set([Category('uncategorized')])
     if self.guid:
         # Used for expanding :uuid in permalink template code below
         uuid = urllib_parse_quote(self.guid)
     else:
         self.guid = uuid = create_guid(self.title, self.date)
     if not self.permalink and \
             blog_config.auto_permalink.enabled:
         self.permalink = create_permalink(
             blog_config.auto_permalink.path, bf.config.site.url,
             blog_config.path, self.title, self.date, uuid, self.filename)
     logger.debug("Permalink: {0}".format(self.permalink))
Пример #7
0
 def __init__(self, name):
     self.name = str(name)
     # TODO: consider making url_name and path read-only properties?
     self.url_name = create_slug(self.name)
     self.path = bf.util.site_path_helper(blog_config.path,
                                          blog_config.category_dir,
                                          self.url_name,
                                          trailing_slash=True)
Пример #8
0
def create_post_filename(spec, title, date):
    filename = spec
    filename = re.sub(":title", create_slug(title), filename)
    filename = re.sub(":year", date.strftime("%Y"), filename)
    filename = re.sub(":month", date.strftime("%m"), filename)
    filename = re.sub(":day", date.strftime("%d"), filename)
    filename = re.sub(":hour", date.strftime("%H"), filename)
    filename = re.sub(":minute", date.strftime("%M"), filename)
    filename = re.sub(":second", date.strftime("%S"), filename)
    return filename
Пример #9
0
def create_post_filename(spec, title, date):
    filename = spec
    filename = re.sub(":title", create_slug(title), filename)
    filename = re.sub(":year", date.strftime("%Y"), filename)
    filename = re.sub(":month", date.strftime("%m"), filename)
    filename = re.sub(":day", date.strftime("%d"), filename)
    filename = re.sub(":hour", date.strftime("%H"), filename)
    filename = re.sub(":minute", date.strftime("%M"), filename)
    filename = re.sub(":second", date.strftime("%S"), filename)
    return filename
Пример #10
0
 def __post_process(self):
     if not self.title:
         self.title = "Untitled - {0}".format(self.date)
     if not self.slug:
         self.slug = create_slug(self.title)
     if not self.categories or len(self.categories) == 0:
         self.categories = set([Category('uncategorized')])
     if self.guid:
         # Used for expanding :uuid in permalink template code below
         uuid = urllib_parse_quote(self.guid)
     else:
         self.guid = uuid = create_guid(self.title, self.date)
     if not self.permalink and \
             blog_config.auto_permalink.enabled:
         self.permalink = create_permalink(
             blog_config.auto_permalink.path, bf.config.site.url,
             blog_config.path, self.title, self.date, uuid, self.filename)
     logger.debug("Permalink: {0}".format(self.permalink))
Пример #11
0
 def __post_process(self):
     if not self.title:
         self.title = "Untitled - {0}".format(self.date)
     if not self.slug:
         self.slug = create_slug(self.title)
     if not self.categories or len(self.categories) == 0:
         self.categories = set([Category('uncategorized')])
     if self.guid:
         # Used for expanding :uuid in permalink template code below
         uuid = urllib_parse_quote(self.guid)
     else:
         self.guid = uuid = create_guid(self.title, self.date)
     if not self.permalink and \
             blog_config.auto_permalink.enabled:
         self.permalink = create_permalink(blog_config.auto_permalink.path,
                                           bf.config.site.url,
                                           blog_config.path, self.title,
                                           self.date, uuid, self.filename)
     logger.debug("Permalink: {0}".format(self.permalink))