Skip to content

Commit f40c264

Browse files
committed
Localize sidebar links on news and archive pages
1 parent 2708ebd commit f40c264

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

_layouts/news.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h3><strong>{{ locales.yearly_archives }}</strong></h3>
4040

4141
<ul class="menu">
4242
{% for year in page.years %}
43-
<li><a href="{{ year }}/">{{ year }}</a></li>
43+
<li><a href="{{ year[0] }}/">{{ year[1] }}</a></li>
4444
{% endfor %}
4545
</ul>
4646
</div>

_layouts/news_archive_year.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ <h3><strong>{{ locales.monthly_archives }}</strong></h3>
4040

4141
<ul class="menu">
4242
{% for month in page.months %}
43-
<li><a href="{{ month[0] }}/">{{ month[1] }} {{ page.year }}</a></li>
43+
<li><a href="{{ month[0] }}/">{{ month[1] }}</a></li>
4444
{% endfor %}
4545
</ul>
4646
</div>

_plugins/news.rb

+19-3
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,22 @@ def initialize(site,base,lang,year,posts)
7676
@dir = File.join(@dir,@year.to_s)
7777

7878
title = locales['yearly_archive_title']
79+
month_link_text = locales['monthly_archive_link']
7980

8081
data['title'] = title.gsub('%Y', @year.to_s)
82+
data['year'] = @year
8183

8284
months = posts.map { |post| post.date.month }.uniq
8385

84-
data['year'] = year
86+
# hash with url => link_text (including year) elements
8587
data['months'] = Hash[
8688
months.map { |month| "%.2d" % month }.zip(
87-
months.map { |month| month_names[month] }
89+
months.map { |month| month_link_text.gsub(/%Y|%m|%B/, {
90+
'%Y' => @year.to_s,
91+
'%m' => "%.2d" % month,
92+
'%B' => month_names[month]
93+
})
94+
}
8895
)
8996
]
9097
end
@@ -101,10 +108,19 @@ def initialize(site,base,lang,posts)
101108
super(site,base,LAYOUT,lang,posts)
102109

103110
title = locales['recent_news']
111+
year_link_text = locales['yearly_archive_link']
104112

105113
data['title'] = title
106-
data['years'] = posts.map { |post| post.date.year }.uniq.reverse
107114
data['posts'] = posts.last(MAX_POSTS).reverse
115+
116+
years = posts.map { |post| post.date.year }.uniq.reverse
117+
118+
# hash with url => link_text elements
119+
data['years'] = Hash[
120+
years.map { |year| year.to_s }.zip(
121+
years.map { |year| year_link_text.gsub(/%Y/, '%Y' => year.to_s) }
122+
)
123+
]
108124
end
109125

110126
end

0 commit comments

Comments
 (0)