Skip to content

Commit

Permalink
Live footer content support (google#3839)
Browse files Browse the repository at this point in the history
* WIP

* WIP

* MemCaches the footer
  • Loading branch information
petele authored Nov 10, 2016
1 parent 596ed76 commit ba2b9de
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 168 deletions.
115 changes: 96 additions & 19 deletions devsiteHelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ def slugify(str):
slug = re.sub(r'[-]+', '-', slug)
return slug

def getFromMemCache(memcacheKey):
try:
result = memcache.get(memcacheKey)
except Exception as e:
result = None
return result

def setMemCache(memcacheKey, value):
try:
memcache.set(memcacheKey, value)
except Exception as e:
pass

def checkForRedirect(requestedPath, lang, useMemcache):
# Reads the redirect files from the current directory and up the directory
Expand Down Expand Up @@ -321,25 +333,90 @@ def getIncludeCode(include_tag, lang='en'):

def getAnnouncementBanner(lang='en'):
# Returns the announcement banner
result = ''
projectFile = os.path.join(SOURCE_PATH, lang, '_project.yaml')
if not os.path.isfile(projectFile):
projectFile = os.path.join(SOURCE_PATH, 'en', '_project.yaml')
raw = open(projectFile, 'r').read().decode('utf8')
project = yaml.load(raw)
if 'announcement' in project:
startBanner = project['announcement']['start']
startBanner = datetime.strptime(startBanner, '%Y-%m-%dT%H:%M:%SZ')
endBanner = project['announcement']['end']
endBanner = datetime.strptime(endBanner, '%Y-%m-%dT%H:%M:%SZ')
if startBanner < datetime.now() < endBanner:
result = '<div class="devsite-banner devsite-banner-announcement">\n'
result += '<div class="devsite-banner-inner">\n'
result += project['announcement']['description']
result += '\n</div>\n'
result += '</div>'
else:
logging.warn('Announcement in _project.yaml expired: not shown')
memcacheKey = 'header-Announcement-' + lang
result = getFromMemCache(memcacheKey)
if result is None:
result = ''
projectFile = os.path.join(SOURCE_PATH, lang, '_project.yaml')
if not os.path.isfile(projectFile):
projectFile = os.path.join(SOURCE_PATH, 'en', '_project.yaml')
raw = open(projectFile, 'r').read().decode('utf8')
project = yaml.load(raw)
if 'announcement' in project:
startBanner = project['announcement']['start']
startBanner = datetime.strptime(startBanner, '%Y-%m-%dT%H:%M:%SZ')
endBanner = project['announcement']['end']
endBanner = datetime.strptime(endBanner, '%Y-%m-%dT%H:%M:%SZ')
if startBanner < datetime.now() < endBanner:
result = '<div class="devsite-banner devsite-banner-announcement">\n'
result += '<div class="devsite-banner-inner">\n'
result += project['announcement']['description']
result += '\n</div>\n'
result += '</div>'
else:
logging.warn('Announcement in _project.yaml expired: not shown')
setMemCache(memcacheKey, result)
return result


def getFooterPromo(lang='en'):
"""Gets the promo footer.
Args:
lang: The language to pick from.
Returns:
An HTML string with the appropriate footer.
"""
memcacheKey = 'footerLinkPromo-' + lang
result = getFromMemCache(memcacheKey)
if result is None:
result = ''
footer = yaml.load(readFile('_footer.yaml', lang))
if 'promos' in footer['footer'][0]:
for promo in footer['footer'][0]['promos']:
result += '<li class="devsite-footer-promo">'
result += '<a href="' + promo['path']
result += '" class="devsite-footer-promo-title">'
if 'icon' in promo:
result += '<img class="devsite-footer-promo-icon" '
result += 'src="' + promo['icon'] + '">'
if 'icon_name' in promo:
result +='<div class="devsite-footer-promo-icon material-icons">'
result += promo['icon_name'] + '</div>'
result += promo['title']
result += '</a><div class="devsite-footer-promo-description">'
result += promo['description']
result += '</div></li>\n'
setMemCache(memcacheKey, result)
return result


def getFooterLinkBox(lang='en'):
"""Gets the promo boxes.
Args:
lang: The language to pick from.
Returns:
An HTML string with the appropriate footer.
"""
memcacheKey = 'footerLinkBoxes-' + lang
result = getFromMemCache(memcacheKey)
if result is None:
result = ''
footer = yaml.load(readFile('_footer.yaml', lang))
if 'linkboxes' in footer['footer'][1]:
for linkBox in footer['footer'][1]['linkboxes']:
result += '<li class="devsite-footer-linkbox">'
result += '<h3 class="devsite-footer-linkbox-heading">'
result += linkBox['name'] + '</h3>'
result += '<ul class="devsite-footer-linkbox-list">'
for linkItem in linkBox['contents']:
result += '<li class="devsite-footer-linkbox-item">'
result += '<a href="' + linkItem['path'] + '">'
result += linkItem['title'] + '</a></li>'
result += '</ul>'
result += '</li>'
setMemCache(memcacheKey, result)
return result
5 changes: 4 additions & 1 deletion devsiteIndex.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ def generateYaml(lang, requestPath, rawYaml):
'customcss': customCss,
'header': header,
'content': content,
'lang': lang}
'lang': lang,
'footerPromo': devsiteHelper.getFooterPromo(),
'footerLinks': devsiteHelper.getFooterLinkBox()
}
)
return text
9 changes: 6 additions & 3 deletions devsitePage.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def getPage(requestPath, lang):
title = 'Web Fundamentals'
leftNav = '- No Left Nav Found - '
toc = '- No TOC Found - '
banner = devsiteHelper.getAnnouncementBanner(lang)
template = 'gae/article.tpl'
fileLocations = [
os.path.join(SOURCE_PATH, lang, requestPath) + '.md',
Expand Down Expand Up @@ -132,19 +131,23 @@ def getPage(requestPath, lang):
gitHubIssueUrl += lang + ']&body='
gitHubIssueUrl += gitHubEditUrl

x = devsiteHelper.getFooterPromo()

# Renders the content into the template
response = render(template, {
'title': title,
'announcementBanner': banner,
'announcementBanner': devsiteHelper.getAnnouncementBanner(lang),
'gitHubIssueUrl': gitHubIssueUrl,
'gitHubEditUrl': gitHubEditUrl,
'requestPath': requestPath.replace('index', ''),
'leftNav': leftNav,
'content': content,
'toc': toc,
'dateUpdated': dateUpdated,
'lang': lang}
'lang': lang,
'footerPromo': devsiteHelper.getFooterPromo(),
'footerLinks': devsiteHelper.getFooterLinkBox()
}
)
break

Expand Down
74 changes: 2 additions & 72 deletions gae/article.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -151,84 +151,14 @@
<footer class="devsite-footer-promos nocontent">
<nav class="devsite-full-site-width">
<ul class="devsite-footer-promos-list">
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/stars_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/thumb_up_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/pets_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/favorite_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
{% autoescape off %}{{footerPromo}}{% endautoescape %}
</ul>
</nav>
</footer>
<footer class="devsite-footer-linkboxes nocontent">
<nav class="devsite-full-site-width">
<ul class="devsite-footer-linkboxes-list">
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
{% autoescape off %}{{footerLinks}}{% endautoescape %}
</ul>
</nav>
</footer>
Expand Down
74 changes: 2 additions & 72 deletions gae/home.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -90,84 +90,14 @@
<footer class="devsite-footer-promos nocontent">
<nav class="devsite-full-site-width">
<ul class="devsite-footer-promos-list">
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/stars_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/thumb_up_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/pets_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
<li class="devsite-footer-promo">
<a href="#" class="devsite-footer-promo-title">
<img class="devsite-footer-promo-icon" src="https://www.gstatic.com/images/icons/material/system/2x/favorite_black_48dp.png">
Title
</a>
<div class="devsite-footer-promo-description">
Lorem ipsum something this that or the other thing.
</div>
</li>
{% autoescape off %}{{footerPromo}}{% endautoescape %}
</ul>
</nav>
</footer>
<footer class="devsite-footer-linkboxes nocontent">
<nav class="devsite-full-site-width">
<ul class="devsite-footer-linkboxes-list">
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
<li class="devsite-footer-linkbox">
<h3 class="devsite-footer-linkbox-heading">Heading</h3>
<ul class="devsite-footer-linkbox-list">
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
<li class="devsite-footer-linkbox-item"><a href="#">Lorem Ipsum</a></li>
</ul>
</li>
{% autoescape off %}{{footerLinks}}{% endautoescape %}
</ul>
</nav>
</footer>
Expand Down
1 change: 0 additions & 1 deletion gae/scripts/devsite.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@
elem.querySelector('article.hentry').style.display = 'block';
elem.querySelector('header').textContent = placeholderTitle;
elem.querySelector('.entry-content').innerHTML = placeholderText;
elem.querySelector('.vcard').innerHTML = 'Jane Doe';
elem.querySelector('.published').textContent = 'January 1st, 2016';
});
}
Expand Down

0 comments on commit ba2b9de

Please sign in to comment.