diff options
author | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-09-21 13:37:59 +0200 |
---|---|---|
committer | Frederic Hemberger <mail@frederic-hemberger.de> | 2011-09-21 14:09:48 +0200 |
commit | 2a30d9a1eb5219e5335d1afdd214204d61ea6367 (patch) | |
tree | 6f5c9cb556bd1b5aa46d93cd0a128e087abe5485 /.themes/classic/source | |
parent | b2828eb039ddc7c0108b6af06ca7f5d8c87a5459 (diff) | |
download | my_new_personal_website-2a30d9a1eb5219e5335d1afdd214204d61ea6367.tar.xz my_new_personal_website-2a30d9a1eb5219e5335d1afdd214204d61ea6367.zip |
Refactored inclusion of disqus script
- Added ARIA setting `aria-live="polite"` to comment output
- Removed duplicate <div id="disqus_thread"> from page/post templates
- Moved blocking JavaScript loading to the end of the document body.
- Merged JavaScript code for index and pages/posts using conditionals
- Moved global JavaScript disqus variables into the anonymous function to stop pollution of global namespace
Diffstat (limited to '')
-rw-r--r-- | .themes/classic/source/_includes/disqus.html | 22 | ||||
-rw-r--r-- | .themes/classic/source/_includes/post/disqus_thread.html | 12 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/default.html | 1 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/page.html | 2 | ||||
-rw-r--r-- | .themes/classic/source/_layouts/post.html | 4 | ||||
-rw-r--r-- | .themes/classic/source/index.html | 47 |
6 files changed, 44 insertions, 44 deletions
diff --git a/.themes/classic/source/_includes/disqus.html b/.themes/classic/source/_includes/disqus.html new file mode 100644 index 00000000..4b913534 --- /dev/null +++ b/.themes/classic/source/_includes/disqus.html @@ -0,0 +1,22 @@ +{% comment %} Load script if disquss comments are enabled and `page.comments` is either empty (index) or set to true {% endcomment %} +{% if site.disqus_short_name and page.comments != false %} +<script type="text/javascript"> + (function () { + var disqus_shortname = '{{ site.disqus_short_name }}'; + {% if page.comments == true %} + {% comment %} `page.comments` can be only be set to true on pages/posts, so we embed the comments here. {% endcomment %} + // var disqus_developer = 1; + var disqus_identifier = '{{ site.url }}{{ page.url }}'; + var disqus_url = '{{ site.url }}{{ page.url }}'; + var disqus_script = 'embed.js' + {% else %} + {% comment %} As `page.comments` is empty, we must be on the index page. {% endcomment %} + var disqus_script = 'count.js' + {% endif %} + + var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; + dsq.src = 'http://' + disqus_shortname + '.disqus.com/' + disqus_script; + (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); + }()); +</script> +{% endif %} diff --git a/.themes/classic/source/_includes/post/disqus_thread.html b/.themes/classic/source/_includes/post/disqus_thread.html index f966f03a..b1acd8cc 100644 --- a/.themes/classic/source/_includes/post/disqus_thread.html +++ b/.themes/classic/source/_includes/post/disqus_thread.html @@ -1,13 +1 @@ -<div id="disqus_thread"></div> -<script type="text/javascript"> - var disqus_shortname = '{{ site.disqus_short_name }}'; - var disqus_identifier = '{{ site.url }}{{ page.url }}'; - var disqus_url = '{{ site.url }}{{ page.url }}'; - //var disqus_developer = 1; - (function() { - var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; - dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js'; - (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq); - })(); -</script> <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript> diff --git a/.themes/classic/source/_layouts/default.html b/.themes/classic/source/_layouts/default.html index 629468d3..d84da44c 100644 --- a/.themes/classic/source/_layouts/default.html +++ b/.themes/classic/source/_layouts/default.html @@ -9,6 +9,7 @@ </div> </div> <footer>{% include footer.html %}</footer> + {% include disqus.html %} {% include google_analytics.html %} {% include google_plus_one.html %} {% include twitter_sharing.html %} diff --git a/.themes/classic/source/_layouts/page.html b/.themes/classic/source/_layouts/page.html index dbf209c4..20c17452 100644 --- a/.themes/classic/source/_layouts/page.html +++ b/.themes/classic/source/_layouts/page.html @@ -27,7 +27,7 @@ layout: default {% if site.disqus_short_name and page.comments == true %} <section> <h1>Comments</h1> - <div id="disqus_thread">{% include post/disqus_thread.html %}</div> + <div id="disqus_thread" aria-live="polite">{% include post/disqus_thread.html %}</div> </section> {% endif %} </div> diff --git a/.themes/classic/source/_layouts/post.html b/.themes/classic/source/_layouts/post.html index ce8a5dea..e81cc787 100644 --- a/.themes/classic/source/_layouts/post.html +++ b/.themes/classic/source/_layouts/post.html @@ -17,10 +17,10 @@ single: true {% endunless %} </footer> </article> -{% if site.disqus_short_name and page.comments != false %} +{% if site.disqus_short_name and page.comments == true %} <section> <h1>Comments</h1> - <div id="disqus_thread">{% include post/disqus_thread.html %}</div> + <div id="disqus_thread" aria-live="polite">{% include post/disqus_thread.html %}</div> </section> {% endif %} </div> diff --git a/.themes/classic/source/index.html b/.themes/classic/source/index.html index e7e96956..1e896b0d 100644 --- a/.themes/classic/source/index.html +++ b/.themes/classic/source/index.html @@ -3,35 +3,24 @@ layout: default --- <div class="blog-index"> -{% assign index = true %} -{% for post in paginator.posts %} -{% assign content = post.content %} - <article> - {% include article.html %} - </article> -{% endfor %} -<nav role="pagination"> - <div> - {% if paginator.next_page %} - <a class="prev" href="{{paginator.next_page}}">← Older</a> - {% endif %} - <a href="/blog/archives">Blog Archives</a> - {% if paginator.previous_page %} - <a class="next" href="{{paginator.previous_page}}">Newer →</a> - {% endif %} - </div> -</nav> -{% if site.disqus_short_name %} -<script type="text/javascript"> - var disqus_shortname = '{{ site.disqus_short_name }}'; - (function () { - var s = document.createElement('script'); s.async = true; - s.type = 'text/javascript'; - s.src = 'http://' + disqus_shortname + '.disqus.com/count.js'; - (document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s); - }()); -</script> -{% endif %} + {% assign index = true %} + {% for post in paginator.posts %} + {% assign content = post.content %} + <article> + {% include article.html %} + </article> + {% endfor %} + <nav role="pagination"> + <div> + {% if paginator.next_page %} + <a class="prev" href="{{paginator.next_page}}">← Older</a> + {% endif %} + <a href="/blog/archives">Blog Archives</a> + {% if paginator.previous_page %} + <a class="next" href="{{paginator.previous_page}}">Newer →</a> + {% endif %} + </div> + </nav> </div> <aside role=sidebar> {% if site.blog_index_asides.size %} |