Esempio n. 1
0
 def get_resource_destination(self):
     _format = ns.site.format
     post = self.parse_post()
     if hasattr(post, 'ext'):
         filename = self.get_resource_basename() + '.' + post.ext
     else:
         filename = self.get_resource_basename() + '.html'
     year = str(post.date.year)
     month = str(post.date.month)
     day = str(post.date.day)
     if '/' in _format:
         path = ''
         dates = {'year': year, 'month': month, 'day': day}
         for attr in _format.split('/'):
             if attr in dates:
                 path = os.path.join(path, dates[attr])
             elif attr:
                 try:
                     path = os.path.join(path, getattr(post, attr))
                 except AttributeError:
                     logger.warn('Attribute %s Missing: %s'\
                                 % (attr, filename))
                     pass
         return os.path.join(path, filename)
     if _format == 'year':
         return os.path.join(year, filename)
     if _format == 'month':
         return os.path.join(year, month, filename)
     if _format == 'day':
         return os.path.join(year, month, day, filename)
     if hasattr(post, 'folder'):
         return os.path.join(post.folder, filename)
     return os.path.join(self.get_relative_folder(), filename)
Esempio n. 2
0
def static_url(name):
    f = os.path.join(namespace.projectdir, namespace.site.get('staticdir','static'), name)
    url = namespace.site.get('static_prefix', '/static')
    if not os.path.exists(f):
        logger.warn('No such static file: %s' % f)
        return os.path.join(url, name)
    f = open(f, 'rb')
    stat = hashlib.md5(f.read()).hexdigest()
    return os.path.join(url, name) + '?v=' + stat[:5]
Esempio n. 3
0
def static_url(name):
    f = os.path.join(ns.storage.projectdir, ns.site.staticdir, name)
    url = ns.site.static_prefix
    if not os.path.exists(f):
        logger.warn('No such static file: %s' % f)
        return os.path.join(url, name)
    f = open(f, 'rb')
    stat = hashlib.md5(f.read()).hexdigest()
    return os.path.join(url, name) + '?v=' + stat[:5]
Esempio n. 4
0
 def _get_rel_posts(self, post):
     if not post.public:
         logger.warn('Non-indexed Post: %s' % post.filepath)
         return post
     olders = filter(lambda p: p.date < post.date and p.public,
                    ns.storage.posts)
     newers = filter(lambda p: p.date > post.date and p.public,
                    ns.storage.posts)
     if olders:
         post.older = sort_posts(olders)[0]
     if newers:
         post.newer = sort_posts(newers, False)[0]
     return post
Esempio n. 5
0
 def _get_rel_posts(self, post):
     if not post.public:
         logger.warn('Non-indexed Post: %s' % post.filepath)
         return post
     olders = filter(lambda p: p.date < post.date and p.public,
                     ns.storage.posts)
     newers = filter(lambda p: p.date > post.date and p.public,
                     ns.storage.posts)
     if olders:
         post.older = sort_posts(olders)[0]
     if newers:
         post.newer = sort_posts(newers, False)[0]
     return post
Esempio n. 6
0
def static_url(name):
    global _hash_cache
    url = ns.site.static_prefix
    if name in _hash_cache:
        return os.path.join(url, name) + '?v=' + _hash_cache[name]

    f = os.path.join(ns.storage.projectdir, ns.site.staticdir, name)
    if not os.path.exists(f):
        logger.warn('No such static file: %s' % f)
        return os.path.join(url, name)
    f = open(f, 'rb')
    stat = hashlib.md5(f.read()).hexdigest()[:5]
    _hash_cache[name] = stat
    return os.path.join(url, name) + '?v=' + stat
Esempio n. 7
0
def static_url(name):
    global _hash_cache
    url = ns.site.static_prefix
    if name in _hash_cache:
        return os.path.join(url, name) + '?v=' + _hash_cache[name]

    f = os.path.join(ns.storage.projectdir,
                     ns.site.staticdir, name)
    if not os.path.exists(f):
        logger.warn('No such static file: %s' % f)
        return os.path.join(url, name)
    f = open(f, 'rb')
    stat = hashlib.md5(f.read()).hexdigest()[:5]
    _hash_cache[name] = stat
    return os.path.join(url, name) + '?v=' + stat
Esempio n. 8
0
def static_url(name):
    global _hash_cache
    url = ns.site.static_prefix
    path = os.path.join(url, name)
    if sys.platform.startswith('win'):
        path = path.replace('\\', '/')
    if name in _hash_cache:
        return path + '?v=' + _hash_cache[name]

    f = os.path.join(ns.storage.projectdir,
                     ns.site.staticdir, name)
    if not os.path.exists(f):
        logger.warn('No such static file: %s' % f)
        return path
    f = open(f, 'rb')
    stat = hashlib.md5(f.read()).hexdigest()[:5]
    _hash_cache[name] = stat
    return path + '?v=' + stat
Esempio n. 9
0
 def _calc_rel_posts(self):
     public_posts = []
     secret_posts = []
     for post in ns.storage.posts:
         if post.public:
             public_posts.append(post)
         else:
             logger.warn('Non-indexed Post: %s' % post.filepath)
             secret_posts.append(post)
     public_posts = sort_posts(public_posts)
     # get related_posts
     for thispost in public_posts:
         flag = 0
         thispost.related = []
         tags = thispost.get("tags", None)
         all_posts = sort_posts(public_posts)
         for tag in tags:
             for other_post in all_posts:
                 if other_post.slug != thispost.slug:
                     other_tags = other_post.get("tags",None)
                     for other_tag in other_tags:
                         if other_tag == tag:
                             if flag == 0:
                                 thispost.related.append(other_post)
                                 flag = 1
                             else:
                                 for existed in thispost.related:
                                     print existed.slug
                                     print other_post.slug
                                     if other_post.slug != existed.slug:
                                         thispost.related.append(other_post)
     i = 0
     count = len(public_posts)
     for post in public_posts:
         if i > 0:
             public_posts[i].prev = public_posts[i - 1]
         if i + 1 < count:
             public_posts[i].next = public_posts[i + 1]
         i += 1
     posts = public_posts
     posts.extend(secret_posts)
     return posts
Esempio n. 10
0
 def _calc_rel_posts(self):
     public_posts = []
     secret_posts = []
     for post in ns.storage.posts:
         if post.public:
             public_posts.append(post)
         else:
             logger.warn('Non-indexed Post: %s' % post.filepath)
             secret_posts.append(post)
     public_posts = sort_posts(public_posts)
     # get related_posts
     for thispost in public_posts:
         flag = 0
         thispost.related = []
         tags = thispost.get("tags", None)
         all_posts = sort_posts(public_posts)
         for tag in tags:
             for other_post in all_posts:
                 if other_post.slug != thispost.slug:
                     other_tags = other_post.get("tags", None)
                     for other_tag in other_tags:
                         if other_tag == tag:
                             if flag == 0:
                                 thispost.related.append(other_post)
                                 flag = 1
                             else:
                                 for existed in thispost.related:
                                     print existed.slug
                                     print other_post.slug
                                     if other_post.slug != existed.slug:
                                         thispost.related.append(other_post)
     i = 0
     count = len(public_posts)
     for post in public_posts:
         if i > 0:
             public_posts[i].prev = public_posts[i - 1]
         if i + 1 < count:
             public_posts[i].next = public_posts[i + 1]
         i += 1
     posts = public_posts
     posts.extend(secret_posts)
     return posts
Esempio n. 11
0
def make_notify():
    logger.warn("Important!!!!!")
    logger.warn("Please use post.newer and post.older instead of"
                " post.prev and post.next")
    logger.warn("Edit your post.html, change post.prev to post.newer")
    logger.warn("Edit your post.html, change post.next to post.older")
Esempio n. 12
0
def make_notify():
    logger.warn("Important!!!!!")
    logger.warn("Please use post.newer and post.older instead of"
                " post.prev and post.next")
    logger.warn("Edit your post.html, change post.prev to post.newer")
    logger.warn("Edit your post.html, change post.next to post.older")
Esempio n. 13
0
def make_notify():
    logger.warn("Important!!!!!")
    logger.warn("sourcecode in markdown changed to the new mark")
    logger.warn("using ```python instead of [sourcecode:python]")
    logger.warn("using ``` to end the code block instead of [/sourcecode]")