def create_project_item(path, gen): def render_md(name, asset_filter=None): p = os.path.join(path, name) if not os.path.exists(p): return "" md = open(p).read() html = markdown.markdown(md.decode('utf-8')) return link_assets(html, path, gen, asset_filter=asset_filter) data_path = os.path.join(path, 'data.json') data = json.load(open(data_path)) if os.path.exists(data_path) else {} preview_html = render_md('preview.markdown') d = { "preview_html": preview_html, "preview_html_for_tile": kill_links(render_md('preview.markdown')), "content_html": render_md('content.markdown'), "name": path.split('/')[-1], "classes": u" ".join(data.get('classes', [])), "title": u"".join(map(unicode, BeautifulSoup(preview_html, 'lxml').find('h1').contents)), "link": data.get("link") } from crop import SquareCropAssetFilter tile_filter = SquareCropAssetFilter(size=500) tile_path = os.path.join(path, 'tile.png') if os.path.exists(tile_path): colors = ui_colors(tile_path) d['project_css'] = "<style>.header{ background-color: BG; color: COLOR; } .project_content a:link, .project_content a:visited { color: COLOR } </style>".replace('COLOR', colors['text']).replace('BG', colors['background']) d['style'] = u"background-image: url({0})".format(gen.include_asset(tile_path, filter=tile_filter)) if d['link']: d['url'] = d['link'] else: d['url'] = '/projects/' + sanitize_name(d['name']) + '.html' return d
def extract_brand(markup, url): soup = BeautifulSoup(markup, 'lxml') favicon = urljoin(url, '/favicon.ico') def find_link_with_rel(rel): link = soup.find('link', attrs={'rel': rel}) if link and link.has_attr('href'): return urljoin(url, link['href']) icon = find_link_with_rel('icon') shortcut_icon = find_link_with_rel('shortcut icon') brand = {} for icon_link in [icon, shortcut_icon, favicon]: # print icon_link colors = ui_colors(icon_link) if colors: brand['colors'] = colors brand['favicon'] = icon_link return brand