mirror of
https://github.com/cobalt-org/cobalt.rs
synced 2024-11-15 00:17:29 +00:00
fix(pagination_permalink): fixes #666 and adjust tests
This commit is contained in:
parent
659da654df
commit
9621b31a7c
14 changed files with 40 additions and 55 deletions
|
@ -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)
|
||||
}
|
||||
|
|
4
tests/fixtures/pagination_all/index.liquid
vendored
4
tests/fixtures/pagination_all/index.liquid
vendored
|
@ -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">←</a>
|
||||
{% endif %}
|
||||
{% if paginator.next_index %}
|
||||
<a href="{{ paginator.next_index_permalink }}"
|
||||
<a href="/{{ paginator.next_index_permalink }}"
|
||||
class="right arrow">→</a>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -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">←</a>
|
||||
{% endif %}
|
||||
{% if paginator.next_index %}
|
||||
<a href="{{ paginator.next_index_permalink }}"
|
||||
<a href="/{{ paginator.next_index_permalink }}"
|
||||
class="right arrow">→</a>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -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">←</a>
|
||||
{% endif %}
|
||||
{% if paginator.next_index %}
|
||||
<a href="{{ paginator.next_index_permalink }}"
|
||||
<a href="/{{ paginator.next_index_permalink }}"
|
||||
class="right arrow">→</a>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -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">←</a>
|
||||
{% endif %}
|
||||
{% if paginator.next_index %}
|
||||
<a href="{{ paginator.next_index_permalink }}"
|
||||
<a href="/{{ paginator.next_index_permalink }}"
|
||||
class="right arrow">→</a>
|
||||
{% endif %}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -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">←</a>
|
||||
|
||||
|
||||
|
||||
<span>2 / 2</span>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -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">→</a>
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<title>test</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>/</h1>
|
||||
<h1></h1>
|
||||
|
||||
This is my Index page!
|
||||
|
||||
|
|
Loading…
Reference in a new issue