Skip to content

Commit f92092f

Browse files
committed
Improve error message in case of invalid path
Previously, if blog authors didn't set the path key in the front matter, the error message from Zola was: Filter `nth` received an incorrect type for arg `n`: got `-2` but expected a usize This is misleading, as it doesn't point out the cause of the problem. The new error message makes authors aware of the required path format.
1 parent 5caa789 commit f92092f

File tree

4 files changed

+4
-0
lines changed

4 files changed

+4
-0
lines changed

Diff for: templates/feed.xml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
<title>{{ macros::escape_hbs(input=page.title) | safe }}</title>
2121
<link rel="alternate" href="https://blog.rust-lang.org{{ macros::escape_hbs(input=page.path) | safe }}" type="text/html" title="{{ macros::escape_hbs(input=page.title) | safe }}" />
2222
{%- set num_comps = page.components | length %}
23+
{%- if num_comps < 4 %}{{ throw(message="Missing date in 'path' key, required format: '[inside-rust/]YYYY/MM/DD/slug-of-your-choice'") }}{% endif %}
2324
{%- set year = page.components | nth(n=num_comps - 4) %}
2425
{%- set month = page.components | nth(n=num_comps - 3) %}
2526
{%- set day = page.components | nth(n=num_comps - 2) %}

Diff for: templates/index.html

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
{%- set rev_pages = section.pages | reverse %}
2828
{%- for page in rev_pages %}
2929
{%- set num_comps = page.components | length %}
30+
{%- if num_comps < 4 %}{{ throw(message="Missing date in 'path' key, required format: '[inside-rust/]YYYY/MM/DD/slug-of-your-choice'") }}{% endif %}
3031
{%- set year = page.components | nth(n=num_comps - 4) | int %}
3132
{%- set month = page.components | nth(n=num_comps - 3) | int %}
3233
{%- set day = page.components | nth(n=num_comps - 2) | int %}

Diff for: templates/page.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{% extends "layout.html" -%}
33
{% block page -%}
44
{% set num_comps = page.components | length -%}
5+
{% if num_comps < 4 %}{{ throw(message="Missing date in 'path' key, required format: '[inside-rust/]YYYY/MM/DD/slug-of-your-choice'") }}{% endif -%}
56
{% set year = page.components | nth(n=num_comps - 4) | int -%}
67
{% set month = page.components | nth(n=num_comps - 3) | int -%}
78
{% set day = page.components | nth(n=num_comps - 2) | int -%}

Diff for: templates/releases.html

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
{%- set rev_pages = section.pages | reverse %}
2727
{%- for page in rev_pages %}
2828
{%- set num_comps = page.components | length %}
29+
{%- if num_comps < 4 %}{{ throw(message="Missing date in 'path' key, required format: '[inside-rust/]YYYY/MM/DD/slug-of-your-choice'") }}{% endif %}
2930
{%- set year = page.components | nth(n=num_comps - 4) | int %}
3031
{%- set month = page.components | nth(n=num_comps - 3) | int %}
3132
{%- set day = page.components | nth(n=num_comps - 2) | int %}

0 commit comments

Comments
 (0)