Skip to content

Commit f29a3d5

Browse files
committed
Fix generated news archive pages for Jekyll 4.2.0
Before this change, with Jekyll 4.2.0 all news archive pages used `news.html` as layout, also the yearly and monthly archive pages, leading to wrong sidebars that list "Archives by Year" (without any entries) and "Syndicate". The reason is that `Page#relative_path` is a memoized value and Jekyll 4.2.0 changes when `relative_path` is first called during generation of the archive pages. Other than before it is now called from `read_yaml`, see jekyll/jekyll@2608640 `YearlyArchive` and `MonthlyArchive` call `ArchivePage#new` (via `super`), which uses `read_yaml`, so that from then on `relative_path` is set and will not change anymore. Therefore the reassignments of `@dir` in YearlyArchive and MonthlyArchive after the `super` calls have no effect on `relative_path`. Hence *all* archive pages have their relative path set to `<lang>/news/index.html`. Then for rendering, apparently the content of the page under the relative path is used (i.e. the `news.html` layout) instead of the in fact correctly set `content` of the respective archive page (i.e. `news_archive_year.html` or `news_archive_month.html`). This issue is fixed by not changing `@dir` after calling `super`.
1 parent c8ce0e1 commit f29a3d5

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

_plugins/news.rb

+14-10
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ module Jekyll
66
module News
77
class ArchivePage < Page
88

9-
def initialize(site, base, layout, lang, posts)
9+
def initialize(site, base, subdir, layout, lang, posts)
1010
@site = site
1111
@base = base
12-
1312
@lang = lang
14-
@dir = File.join(@lang, news_dir)
13+
@dir = if subdir
14+
File.join(@lang, news_dir, subdir)
15+
else
16+
File.join(@lang, news_dir)
17+
end
1518
@name = "index.html"
1619

1720
@locales = @site.data["locales"][@lang]["news"] ||
@@ -47,11 +50,11 @@ class MonthlyArchive < ArchivePage
4750
LAYOUT = "news_archive_month.html"
4851

4952
def initialize(site, base, lang, year, month, posts)
50-
super(site, base, LAYOUT, lang, posts)
51-
5253
@year = year
5354
@month = month
54-
@dir = File.join(@dir, @year.to_s, "%.2d" % @month)
55+
subdir = File.join(@year.to_s, "%.2d" % @month)
56+
57+
super(site, base, subdir, LAYOUT, lang, posts)
5558

5659
title = @locales["monthly_archive_title"]
5760

@@ -65,10 +68,10 @@ class YearlyArchive < ArchivePage
6568
LAYOUT = "news_archive_year.html"
6669

6770
def initialize(site, base, lang, year, posts)
68-
super(site, base, LAYOUT, lang, posts)
69-
7071
@year = year
71-
@dir = File.join(@dir, @year.to_s)
72+
subdir = @year.to_s
73+
74+
super(site, base, subdir, LAYOUT, lang, posts)
7275

7376
title = @locales["yearly_archive_title"]
7477
month_link_text = @locales["monthly_archive_link"]
@@ -94,7 +97,8 @@ class Index < ArchivePage
9497
MAX_POSTS = 10
9598

9699
def initialize(site, base, lang, posts)
97-
super(site, base, LAYOUT, lang, posts)
100+
subdir = nil
101+
super(site, base, subdir, LAYOUT, lang, posts)
98102

99103
title = @locales["recent_news"]
100104
year_link_text = @locales["yearly_archive_link"]

0 commit comments

Comments
 (0)