Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination info to sections #2653

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions components/content/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ pub struct SerializingSection<'a> {
backlinks: Vec<BackLink<'a>>,
generate_feeds: bool,
transparent: bool,
paginated: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for that one, let's match what is in the frontmatter

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just removed the unecessary paginated attribute and retrieved raw values from the frontmatter.

Adapted testsite: testsite.zip

paginate_by: Option<usize>,
paginate_reversed: Option<bool>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -203,6 +206,19 @@ impl<'a> SerializingSection<'a> {
}
}

let paginated;
let paginate_by;
let paginate_reversed;
if let Some(_) = section.meta.paginate_by.filter(|nb_pages| *nb_pages > 0) {
paginated = true;
paginate_by = section.meta.paginate_by;
paginate_reversed = Some(section.meta.paginate_reversed);
} else {
paginated = false;
paginate_by = None;
paginate_reversed = None;
}

Self {
relative_path: &section.file.relative,
colocated_path: &section.file.colocated_path,
Expand All @@ -226,6 +242,9 @@ impl<'a> SerializingSection<'a> {
subsections,
translations,
backlinks,
paginated,
paginate_by,
paginate_reversed,
}
}
}
11 changes: 11 additions & 0 deletions docs/content/documentation/templates/pages-sections.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,19 @@ backlinks: Array<{permalink: String, title: String?}>;
generate_feeds: bool;
// Whether this section is transparent. Taken from the front-matter if set
transparent: bool;
// Information about pagination (see below)
// Whether this section is paginated.
paginated: bool;
// How many items per pager
paginate_by: Number?;
// If items order is reversed in the pagination
paginate_reversed: bool?;
```

Information about pagination is useful when using the `get_section` Tera function for which the `paginator` is not available.

See [pagination template documentation](@/documentation/templates/pagination.md) for more information on the `paginator` variable.

## Table of contents

Both page and section templates have a `toc` variable that corresponds to an array of `Header`.
Expand Down