Trio Icon
Trio v6.1.0
Documentation is evolving and is a WIP

Frequently Asked Questions

How do I get the total number of pages, excluding articles? How do I get the total number of article pages? How do I get a reference to the list of all the pages, excluding articles? How do I get a reference to the list of all the article pages? My site has too many articles to display on a single page. How can I display them using multiple pages and limit the number of articles per page and provide links to the previous and next pages?

Q) How do I get the total number of pages, excluding articles?

A) The following works in both collection filter functions and tag-based callbacks:

site.frags.length;

Q) How do I get the total number of article pages?

A) The following works in both collection filter functions and tag-based callbacks:

site.articlesCount;

Q) How do I get a reference to the list of all the pages, excluding articles?

A) The following works in both collection filter functions and tag-based callbacks:

const frags = site.frags;

Q) How do I get a reference to the list of all the article pages?

A) The following works in both collection, filter functions, and tag-based callbacks:

const articles = site.articlesCatalog;

Q) My site has too many articles to display on a single page. How can I display them using multiple pages and limit the number of articles per page and provide links to the previous and next pages?

A) The following is an example of how to accomplish this using a collection filter function:

/*
 * Break up the articlesCatalog into multiple pages of articlesPerPage articles.
 * The value of articlesPerPage is stored in trio.json.
 * Pages are named "index.html", "page2.html", "page3.html", ...
 * Each dataset item's data property is assigned a subset of site.articlesCatalog
 * using Array.slice.
 * Links to the previous page with newer articles and to the next page with older
 * articles are assigned to the dataset item's newerUrl and olderUrl properties,
 * respectively.
 */

module.exports = ({ site }) => {
    const articlesPerPage = site.userConfig.articlesPerPage;
    const dataset = [];
    const noOfPages = Math.ceil(site.articlesCatalog.length / articlesPerPage);
    for (let i = 0; i < noOfPages; i++) {
        const pageName = (i === 0 && "index") || "page" + (i + 1);
        const data = site.articlesCatalog.slice(articlesPerPage * i, articlesPerPage * i + articlesPerPage);
        dataset.push({
            pageName,
            data,
            newerUrl: i === 0 ? "" : i === 1 ? "/blog" : "/blog/page" + i,
            olderUrl: i + 1 === noOfPages ? "" : "/blog/page" + (i + 2)
        });
    }
    return dataset;
};

Your Financial Support Of This Project Is Greatly Appreciated

Trio is an open source project and is therefore free of charge to use both for noncommercial and commercial use, but when you use Trio to create a new website, please consider donating a few bucks. It doesn't take very long, the process is secure, and it will allow us to continue to support the community and to maintain and enhance Trio going forward.

Show your ❤️, add your ★ to the Github repo.