(As a side note, I can’t reference {{ page.title }} from news.html without getting Reason: Variable page.title not found in context while rendering 'news.html' despite the fact I set the title.)
Aha! Changing line 7 of news.html from {% for year, posts in section.pages | group_by(attribute="year") %} to {% for year, posts in paginator.pages | group_by(attribute="year") %} gets it working.
One more question, can I access it this from multiple places? Like, the 5 most recent posts on the main page, the paginator on /news, and an archive page that has every single post in a list. I tried duplicating what I have in news.html in my index.html for the main page, but no luck.
That works now, but I can’t figure out how to limit it to X posts. It grabs every single one, and I don’t think I can use paginate_by to limit it? I tried {% if loop.index > 5 %} inside {% for page in recent_changes.pages %} but no luck.
Edit: I should have been using < (less-than), not > (greater-than). {% if loop.index < 5 %} does what I want!
Based on the stuff above I figured out how to create an archive though! For anyone in the future looking to do the same thing, here’s what I did.
archive.html:
{% extends "base.html" %}
{% block title %}{{ section.title }}{% endblock title %}
{% block content %}
<h2>News Archive</h2>
<ul>
{% set recent_changes = get_section(path="news/_index.md") %}
{% for page in recent_changes.pages %}
{% if page.date and not page.template %}
<li>
{{page.date}} - <a href="{{ page.permalink | safe }}">{{ page.title }}</a>
</li>
{% endif %}
{% endfor %}
</ul>
{% endblock content %}
content/news/archive/_index.md:
+++
title = "News Archive"
template = "archive.html"
+++