Add fuzzy dates with lw-timeago
Fixes #14
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..2c5f24e
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "static/js/lw-timeago"]
+ path = static/js/lw-timeago
+ url = https://github.com/pR0Ps/lw-timeago.git
diff --git a/README.md b/README.md
index 600bb58..7827cff 100644
--- a/README.md
+++ b/README.md
@@ -18,10 +18,12 @@
- Google Authorship
- Supports displaying a custom list of links with icons in the sidebar
- Global keyword support
+- Fuzzy date display using Javascript
## Installing
-Clone the [repository](https://github.com/pR0Ps/pelican-subtle), edit your `pelicanconf.py` and modify the `THEME` variable to point to the downloaded theme location.
+1. Clone the [repository](https://github.com/pR0Ps/pelican-subtle) making sure to get the submodules (ex: `git clone --recursive [repo]`)
+2. Edit `pelicanconf.py` and modify the `THEME` variable to point to the downloaded theme location.
## pelicanconf.py
@@ -39,6 +41,7 @@
- `FORCE_PIXELS`: Some screens (mostly mobiles) don't use pixels directly and scale based on the concept of a 'display pixel'. Setting this to `True` tells the device to use actual pixels. Enable with care.
- `MANGLE_EMAILS`: If enabled, any emails in the `SOCIAL` links will be obfuscated in HTML and have their links generated by Javascript when the page loads.
- `GLOBAL_KEYWORDS`: A list of strings that will be set as keywords for each page.
+- `FUZZY_DATES`: If `True`, uses [lw-timeago](https://github.com/pR0Ps/lw-timeago) to display fuzzy dates on articles (eg. 'Posted 3 months ago').
- `SERVER_LESS`: If `True`, `static/css/style.css` will be used as the style (compile it server-side). Otherwise `static/css/style.less` will be compiled client-side with `less.js`.
## Authors
diff --git a/static/js/lw-timeago b/static/js/lw-timeago
new file mode 160000
index 0000000..b6a09a3
--- /dev/null
+++ b/static/js/lw-timeago
@@ -0,0 +1 @@
+Subproject commit b6a09a39eb432418c603c7b0583aa961ae425209
diff --git a/templates/article.html b/templates/article.html
index 553eb15..8814aab 100644
--- a/templates/article.html
+++ b/templates/article.html
@@ -24,7 +24,7 @@
{{ article.content }}
</div>
<div class="article_meta">
- <p>Posted on <time datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time>
+ <p>Posted <time datetime="{{ article.date.isoformat() }}">{{ article.locale_date }}</time>
{% if article.author %}
by {% if AUTHORS_URL %} <a href="{{ SITEURL }}/{{ article.author.url }}">{{ article.author }}</a>{% else %}{{ article.author}}{% endif %}
{% endif %}
@@ -59,7 +59,15 @@
</script>
<noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
</div>
- {% endif %}
+ {% endif %}
+
+ {% if FUZZY_DATES %}
+ {% block scripts %}
+ {{ super() }}
+ <script type="text/javascript">lw_timeago.doReplace()</script>
+ {% endblock %}
+ {% endif %}
+
</article>
{% endblock %}
diff --git a/templates/base.html b/templates/base.html
index b0d97de..1200546 100644
--- a/templates/base.html
+++ b/templates/base.html
@@ -9,6 +9,11 @@
<script src="//cdnjs.cloudflare.com/ajax/libs/less.js/1.6.1/less.min.js" type="text/javascript"></script>
{% endif %}
+
+ {% if FUZZY_DATES %}
+ <script src="{{ SITEURL }}/theme/js/lw-timeago/lw-timeago.js" type="text/javascript"></script>
+ {% endif %}
+
<link rel="stylesheet" type="text/css" href="{{ SITEURL }}/theme/css/pygments.css">
<link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.min.css" rel="stylesheet">
@@ -138,6 +143,7 @@
</div>
</main>
+ {% block scripts %}
{% if SCROLL_TO_CONTENT %}
<script type="text/javascript">
if (window.location.pathname != '/' && window.location.pathname != '/index.html'){
@@ -169,5 +175,7 @@
}
</script>
{% endif %}
+
+ {% endblock scripts %}
</body>
</html>