-
Notifications
You must be signed in to change notification settings - Fork 12
/
functions.py
58 lines (47 loc) · 1.68 KB
/
functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
# -*- coding: utf-8 -*- #
import hashlib
import functools
import os
import posixpath
import random
def GET_AVATAR(autor, membros):
if autor in membros:
if 'github' in membros[autor]:
formatter = "https://avatars.githubusercontent.com/{}?size=250"
username = membros[autor]['github']
elif 'email' in membros[autor]:
formatter = "http://www.gravatar.com/avatar/{}?s=250"
username = hashlib.md5(membros[autor]['email'].strip().lower().encode("utf-8")).hexdigest()
elif 'twitter' in membros[autor]:
formatter = "http://avatars.io/twitter/{}"
username = membros[autor]['twitter']
if username.startswith("@"):
username = username[1:]
else:
formatter = "/theme/img/{}"
username = "default_avatar.png"
else:
formatter = "/theme/img/{}"
username = "default_avatar.gif"
return formatter.format(username)
def GET_ARTICLE_IMAGE(article, root):
if hasattr(article, 'image'):
img = article.image
if img.startswith('/'):
img = img[1:]
return img
if not root:
return ""
base = os.path.join('content', root)
banners = map(functools.partial(os.path.join, root), os.walk(base).next()[2])
random.seed(article.date)
return random.choice(banners)
def GET_ARTICLE_AT_GITHUB(article, repo, branch):
base = posixpath.relpath(article.source_path, os.getcwd())
return posixpath.join(repo, 'tree/', branch, base)
def GET_LINK(link):
if link.startswith('http://') or link.startswith('https://'):
return link
else:
return '/' + link