fix(pagination_permalink): fixes #666 and adjust tests

This commit is contained in:
Geobert Quach 2019-08-09 19:14:37 +01:00
parent 659da654df
commit 9621b31a7c
14 changed files with 40 additions and 55 deletions

View file

@ -138,7 +138,7 @@ fn interpret_permalink(
let mut attributes = document::permalink_attributes(&doc.front, &doc.file_path);
let permalink = permalink::explode_permalink(&config.front_permalink, &attributes)?;
let permalink_path = std::path::Path::new(&permalink);
let mut pagination_root = permalink_path.extension().map_or_else(
let pagination_root = permalink_path.extension().map_or_else(
|| permalink.clone(),
|os_str| {
permalink
@ -149,7 +149,13 @@ fn interpret_permalink(
let interpreted_permalink = if page_num == 1 {
index.map_or_else(
|| doc.url_path.clone(),
|index| format!("{}/{}", pagination_root, index_to_string(&index)),
|index| {
if pagination_root.is_empty() {
index_to_string(&index)
} else {
format!("{}/{}", pagination_root, index_to_string(&index))
}
},
)
} else {
let pagination_attr = pagination_attributes(page_num as i32);
@ -157,19 +163,26 @@ fn interpret_permalink(
let index = index.map_or_else(
|| {
if config.include != Include::All {
unreachable!("Include is not `All` and no index");
unreachable!("Include is not All and no index");
}
"all".to_string()
},
|index| index_to_string(&index),
);
format!(
"{}/{}/{}",
pagination_root,
index,
permalink::explode_permalink(&config.permalink_suffix, &attributes)?
)
if pagination_root.is_empty() {
format!(
"{}/{}",
index,
permalink::explode_permalink(&config.permalink_suffix, &attributes)?
)
} else {
format!(
"{}/{}/{}",
pagination_root,
index,
permalink::explode_permalink(&config.permalink_suffix, &attributes)?
)
}
};
Ok(interpreted_permalink)
}

View file

@ -13,11 +13,11 @@ This is my Index page!
<div>
{% if paginator.previous_index %}
<a href="{{ paginator.previous_index_permalink }}"
<a href="/{{ paginator.previous_index_permalink }}"
class="left arrow">&#8592;</a>
{% endif %}
{% if paginator.next_index %}
<a href="{{ paginator.next_index_permalink }}"
<a href="/{{ paginator.next_index_permalink }}"
class="right arrow">&#8594;</a>
{% endif %}

View file

@ -15,11 +15,11 @@ This is my Index page!
<div>
{% if paginator.previous_index %}
<a href="{{ paginator.previous_index_permalink }}"
<a href="/{{ paginator.previous_index_permalink }}"
class="left arrow">&#8592;</a>
{% endif %}
{% if paginator.next_index %}
<a href="{{ paginator.next_index_permalink }}"
<a href="/{{ paginator.next_index_permalink }}"
class="right arrow">&#8594;</a>
{% endif %}

View file

@ -15,11 +15,11 @@ This is my Index page!
<div>
{% if paginator.previous_index %}
<a href="{{ paginator.previous_index_permalink }}"
<a href="/{{ paginator.previous_index_permalink }}"
class="left arrow">&#8592;</a>
{% endif %}
{% if paginator.next_index %}
<a href="{{ paginator.next_index_permalink }}"
<a href="/{{ paginator.next_index_permalink }}"
class="right arrow">&#8594;</a>
{% endif %}

View file

@ -15,11 +15,11 @@ This is my Index page!
<div>
{% if paginator.previous_index %}
<a href="{{ paginator.previous_index_permalink }}"
<a href="/{{ paginator.previous_index_permalink }}"
class="left arrow">&#8592;</a>
{% endif %}
{% if paginator.next_index %}
<a href="{{ paginator.next_index_permalink }}"
<a href="/{{ paginator.next_index_permalink }}"
class="right arrow">&#8594;</a>
{% endif %}

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -1,28 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<h1>/</h1>
This is my Index page!
<a href="posts/my-first-blogpost.html">My first Blogpost</a>
<div>
<a href="/"
class="left arrow">&#8592;</a>
<span>2 / 2</span>
</div>
</body>
</html>

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!
@ -34,7 +34,7 @@
<div>
<a href="/all/./2/"
<a href="/all/2/"
class="right arrow">&#8594;</a>

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!

View file

@ -4,7 +4,7 @@
<title>test</title>
</head>
<body>
<h1>/</h1>
<h1></h1>
This is my Index page!