Skip to content

Commit

Permalink
Rework article dates.
Browse files Browse the repository at this point in the history
Don't use the tablet thingies. Add metadata after the first h1 element, with
the author and date of the article.
  • Loading branch information
sfiera committed Aug 19, 2012
1 parent dac67d6 commit 54312f0
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 70 deletions.
11 changes: 0 additions & 11 deletions _themes/arescentral/layout.html
Expand Up @@ -163,23 +163,12 @@ <h3>{{ _('Navigation') }}</h3>
{%- block content %}
<div class="document">
{%- block document %}

{% if "date" in meta %}
{{ meta["date"]|date_html }}
<div class="article">
{% endif %}

<div class="documentwrapper">
<div class="body">
{% block body %} {% endblock %}
</div>
</div>

{% if "date" in meta %}
</div>
{% endif %}
{%- endblock %}

</div>
{%- endblock %}

Expand Down
43 changes: 7 additions & 36 deletions _themes/arescentral/static/arescentral.css
Expand Up @@ -110,40 +110,6 @@ a.image-reference {
position: relative;
}

.article-date {
float: left;
position: relative;
margin-right: 1em;
background: hsl(0, 0%, 85%);
color: hsl(0, 0%, 50%);
width: 5.75em;
text-transform: uppercase;
}
.article-date .month-day {
color: white;
position: absolute;
top: 0;
bottom: 0;
right: 0;
width: 2.125em;
font-size: 0.6em;
font-weight: bold;
text-align: center;
line-height: 1.25em;
padding: 0.25em 0.5em;
}
.article-date .year,
.article-date .month,
.article-date .day,
.article-date .month-day {
display: block;
}
.article-date .year {
font-size: 1.5em;
line-height: 1em;
padding: 0.1em 0.25em;
}

h1,
h2,
h3,
Expand Down Expand Up @@ -190,6 +156,13 @@ a.headerlink:link {
a.headerlink:hover {
color: white !important;
}
.meta {
margin: -0.5em 0 0 0;
font-size: 90%;
}
.meta span {
margin: 0 1em 0 0;
}

.image-reference .screenshot {
float: left;
Expand Down Expand Up @@ -273,7 +246,6 @@ pre {
.highlight {
border-color: hsl(0, 66%, 50%);
}
.article-date .month-day,
a.headerlink:hover {
background: hsl(0, 66%, 50%);
}
Expand All @@ -292,7 +264,6 @@ a:visited {
.antares .highlight {
border-color: hsl(120, 25%, 45%);
}
.antares .article-date .month-day,
.antares a.headerlink:hover {
background: hsl(120, 25%, 45%);;
}
Expand Down
2 changes: 1 addition & 1 deletion conf.py
Expand Up @@ -25,12 +25,12 @@
"ext.articlelist",
"ext.feed",
"ext.issuetracker",
"ext.meta",
"ext.youtube",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
template_bridge = 'ext.template_helpers.TemplateBridge'

# The suffix of source filenames.
source_suffix = ".rst"
Expand Down
70 changes: 70 additions & 0 deletions ext/meta.py
@@ -0,0 +1,70 @@
import html5lib
import re
import time

def setup(app):
app.connect('html-page-context', add_byline)

def add_byline(app, docname, templatename, ctx, doctree):
date = None
author = None
author_email = None
if "meta" in ctx:
meta = ctx["meta"]
if "author" in meta:
author = meta["author"]
m = re.match("\s*(.*\S)\s*<(.+)>\s*", author)
if m:
author = m.group(1)
author_email = m.group(2)
if "date" in meta:
date = time.strptime(meta["date"], "%Y-%m-%d")
date = date_string(date)
if not (date or author):
return

tree_builder = html5lib.treebuilders.getTreeBuilder("dom")
parser = html5lib.html5parser.HTMLParser(tree = tree_builder)
dom = parser.parse(ctx["body"])

h1 = dom.getElementsByTagName("h1")[0]
div = dom.createElement("div")
div.setAttribute("class", "meta")
h1.parentNode.insertBefore(div, h1.nextSibling)

if author:
span = dom.createElement("span")
span.setAttribute("class", "author")
span.appendChild(dom.createTextNode("By: "))
if author_email:
a = dom.createElement("a")
a.setAttribute("href", "mailto:%s" % author_email)
a.appendChild(dom.createTextNode(author))
span.appendChild(a)
else:
span.appendChild(dom.createTextNode(author))
div.appendChild(span)

if date:
span = dom.createElement("span")
span.setAttribute("class", "date")
span.appendChild(dom.createTextNode("On: %s" % date))
div.appendChild(span)

body = dom.getElementsByTagName("body")[0]
tree_walker = html5lib.treewalkers.getTreeWalker("dom")
html_serializer = html5lib.serializer.htmlserializer.HTMLSerializer()
ctx["body"] = u"".join(html_serializer.serialize(tree_walker(body)))

def date_string(t):
year = time.strftime("%Y", t)
month = time.strftime("%B", t)
day = time.strftime("%e", t)
if day in [" 1", "21", "31"]:
return "%s %sst, %s" % (month, day, year)
elif day in [" 2", "22"]:
return "%s %snd, %s" % (month, day, year)
elif day in [" 3", "23"]:
return "%s %srd, %s" % (month, day, year)
else:
return "%s %sth, %s" % (month, day, year)
22 changes: 0 additions & 22 deletions ext/template_helpers.py

This file was deleted.

0 comments on commit 54312f0

Please sign in to comment.