Instantly share code, notes, and snippets.
Created
November 1, 2015 18:27
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save navilan/b5829786a62c41f1fdc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/content/en/blog/index.html b/content/en/blog/index.html | |
index 9c7d08d..ff91543 100644 | |
--- a/content/en/blog/index.html | |
+++ b/content/en/blog/index.html | |
@@ -7,8 +7,6 @@ paginator: | |
size: 10 | |
file_pattern: page$PAGE$EXT | |
--- | |
-{% set post_list = resource.page.posts %} | |
- | |
{% extends "blog-list.j2" %} | |
{# If we are rendering a year, just replace the title #} | |
diff --git a/layout/blog-list.j2 b/layout/blog-list.j2 | |
index 30175dd..9a9c350 100644 | |
--- a/layout/blog-list.j2 | |
+++ b/layout/blog-list.j2 | |
@@ -1,5 +1,17 @@ | |
{% extends "base.j2" %} | |
+{% set tag_dict = {} %} | |
+{% for tag, meta in site.tagger.tags %} | |
+ {% set tag_res = [] %} | |
+ {% for res in meta.resources %} | |
+ {% set lang_root = site.content.source_folder.child_folder(res.meta.language) %} | |
+ {% if resource.node.source_folder.is_descendant_of(lang_root) or resource.node.source_folder == lang_root %} | |
+ {% do tag_res.append(res) %} | |
+ {% endif %} | |
+ {% endfor %} | |
+ {% do tag_dict.update({meta.name: tag_res}) %} | |
+{% endfor %} | |
+ | |
{% block js %} | |
{{ super() }} | |
@@ -15,8 +27,8 @@ | |
</script> | |
{% endblock %} | |
-{% macro render_blog_listing(walker) %} | |
- {% for res in walker %} | |
+{% macro render_blog_listing(resources) %} | |
+ {% for res in resources %} | |
<div class="container post format-image"> | |
<div class="entry"> | |
<header class="entry-header"> | |
@@ -26,7 +38,7 @@ | |
<small> | |
<i class="fa fa-folder"></i> | |
{% for tag in res.meta.tags %} | |
- <a href="/blog/tags/{{tag}}.html">{{tag}}</a>{% if not loop.last -%},{%- endif %} | |
+ <a href="/{{ resource.meta.language }}/tags/{{tag}}.html">{{tag}}</a>{% if not loop.last -%},{%- endif %} | |
{% endfor %} | |
</small> | |
<a href="{{ site_url }}{{ res.full_url }}#disqus_thread"> | |
@@ -53,7 +65,11 @@ | |
{% block content %} | |
<div class="col-md-9 col-sm-7 posts"> | |
- {{ render_blog_listing(post_list) }} | |
+ {% if tag is defined %} | |
+ {{ render_blog_listing(tag_dict[tag.name]) }} | |
+ {% else %} | |
+ {{ render_blog_listing(resource.page.posts) }} | |
+ {% endif %} | |
<div class="container pagination-bar text-center"> | |
<ul class="pagination"> | |
@@ -74,15 +90,28 @@ | |
<!-- .widget --> | |
<div class="widget"> | |
<h4>Tags</h4> | |
+ {% set lang = 'en' %} | |
+ {% set previous = None %} | |
+ {% set current = None %} | |
+ {% set n = resource.node %} | |
+ {% set cont = False %} | |
+ {% for _ in range(1, 100) if cont %} | |
+ {% if n.source_folder == site.content.source_folder %} | |
+ {% set cont = True %} | |
+ {% else %} | |
+ {% set previous = current %} | |
+ {% set current = n %} | |
+ {% set n = n.parent %} | |
+ {% endif %} | |
+ {% endfor %} | |
+ {% if previous %} | |
+ {% set lang = previous.source_folder.name %} | |
+ {% endif %} | |
+ | |
<ul class="category-list flat"> | |
- {% set tag_dict = {} %} | |
- {% for tag, meta in site.tagger.tags %} | |
- {% do tag_dict.update({meta:meta.resources|count})%} | |
- {% endfor %} | |
- {% for meta, post_count in tag_dict|dictsort(by='value')|reverse %} | |
+ {% for name, resources in tag_dict|dictsort(by='value')|reverse %} | |
<li> | |
<a{% if tag == meta %} class="active"{% endif %} | |
- href="/blog/tags/{{ meta.name }}"> | |
- {{ meta.name }} | |
+ href="/{{ lang }}/tags/{{ name }}"> | |
+ {{ name }} | |
<span class="text-right pull-right"> | |
- {{(pos | |
t_count) }} | |
+ {{(resources|count) }} | |
</span> | |
</a> | |
</li> | |
diff --git a/layout/macros.j2 b/layout/macros.j2 | |
index 9de883c..3c1b4ac 100644 | |
--- a/layout/macros.j2 | |
+++ b/layout/macros.j2 | |
@@ -8,7 +8,7 @@ | |
<published>{{ res.meta.created|xmldatetime }}</published> | |
<id>{{ content_url(res.url) }}</id> | |
{% for tag in res.meta.tags %} | |
- <category scheme="{{ content_url('blog/tags') }}" | |
+ <category scheme="{{ content_url(meta.resource.language ~ '/tags/') }}" | |
term="{{tag}}" | |
label="{{ tag|title }}" /> | |
{% endfor %} | |
diff --git a/layout/tag.j2 b/layout/tag.j2 | |
index 332b126..51fb325 100644 | |
--- a/layout/tag.j2 | |
+++ b/layout/tag.j2 | |
@@ -1,9 +1,7 @@ | |
-{% set post_list = walker() %} | |
- | |
{% extends "blog-list.j2" %} | |
{% block rss %} | |
-<link rel="alternate" type="application/rss+xml" href="/blog/tags/{{tag}}.xml" title="jd:/dev/blog – {{tag}}"> | |
+<link rel="alternate" type="application/rss+xml" href="/{{ resource.meta.language }}/tags/{{tag}}.xml" title="jd:/dev/blog – {{tag}}"> | |
{% endblock %} | |
{% block title %}Posts with tag {{tag}}{% endblock %} | |
diff --git a/site-local.yaml b/site-local.yaml | |
index dbf8896..d3ad62a 100644 | |
--- a/site-local.yaml | |
+++ b/site-local.yaml | |
@@ -64,14 +64,24 @@ sorter: | |
tagger: | |
sorter: time | |
archives: | |
- atom: | |
- source: blog | |
- target: blog/tags | |
+ atom_en: | |
+ source: en/blog | |
+ target: en/tags | |
template: tag.xml.j2 | |
extension: xml | |
- blog: | |
- source: blog | |
- target: blog/tags | |
+ blog_en: | |
+ source: en/blog | |
+ target: en/tags | |
+ template: tag.j2 | |
+ extension: html | |
+ atom_es: | |
+ source: es/blog | |
+ target: es/tags | |
+ template: tag.xml.j2 | |
+ extension: xml | |
+ blog_es: | |
+ source: es/blog | |
+ target: es/tags | |
template: tag.j2 | |
extension: html | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment