Understanding the core concepts presented on this page will enable you to use Trio to its fullest potential.
Creating web pages with Trio involves the use of project assets to create and augment composites which Trio eventually saves to your computer's file system as HTML files. The following project assets are available to you to compose your pages:
It helps to think of composites as pages that haven't been written to the file system yet, that only exist in your computer's memory.
Fragments are either .html or .md file types that you create in the root/source/fragments folder. Fragments must always include front matter at the very top of the file and optionally can have their own content.
Fragment front matter must include the template property to which is assigned the name of the template that the fragment is associated with.
A fragment asset can only be associated with a single template asset.
Templates are .html file types that you create in the root/source/templates folder. Templates define the overall layout of your site's pages (i.e. they include the !DOCTYPE document preamble, html, head and body sections typically found in an HTML document).
Optionally, you can decorate a single HTML tag in the template asset with a data-trio-fragment tag attribute and Trio will copy the fragment's content to this tag.
Templates never include front matter.
A template asset can be associated with multiple fragment assets.
Includes are either .html or .md file types that you create in the root/source/includes folder. They are used to add reusable blocks of content to the composites created from fragment and template assets and can be used across multiple pages (e.g. headers, footers, indexes, etc.). They can optionally include front matter at the very top of the file.
You can add as many include assets as needed into both template and fragment assets by decorating the tags you are targeting with the data-trio-include="name + file type" of the include file or data-trio-include="the name of a property declared in the fragment's front matter" whose value is the name of the include file.
JSON Data Files
JSON data files are .json file types that you create in the root/source/data folder. Tag-based callbacks can access these files' data through the metadata that is passed to them.
You can hand-code these data files yourself or you can create NPM tasks that, for example, retrieve the data from a local database, a content management system, or a remote service.
Metadata is the collection of data that Trio derives from your project's other assets and from the root/trio.json configuration file and uses the metadata internally to build your site.
Trio also passes metadata to the tag-based callbacks it finds declared in your project's fragment, template and include assets, which they can use to further augment your composites. Trio organizes its metadata in a structured format that makes using it in your tag-based callbacks easier to reason about.
For example, you can use this metadata in your tag-based callbacks to:
- Create links to other pages on your web site.
- Generate content based on JSON data or from custom front matter properties.
- Make lists of blog articles related by their categories and tags.
- Construct links to the next and previous blog article based on their published dates.
After each development build of your project, Trio persists most of the metadata that it collects to a file named root/trio.manifest.json. You can use this file as a reference to assist you when you are coding your collection filter functions and tag-based callbacks.
A Page Composition Overview
Anatomy Of A Generated Page
Trio's approach to page generation (also called page composition throughout these document pages) is quite different from other static site generators and it is what makes Trio the flexible and powerful tool that it is.
- First and foremost, every web page (.html file) that is generated must have a template asset and a fragment asset (see project assets above). Trio uses the markup from the template asset identified by the template property in the fragment's front matter (see front matter below) to initialize a brand new composite.
- Trio then searches the newly created composite's content for a single tag that has the "data-trio-fragment" attribute (see tag attributes below). If one is found, Trio will copy any content that the fragment may have to that tag. If the fragment's content is in markdown format, Trio will convert the markdown to markup prior to copying.
- Trio then searches the composite for all the tags that have "data-trio-include" attributes (see tag attributes below), which name the include files (see project assets above) whose content is copied to their respective tags in the composite. If an include file's content is in markdown format, Trio will convert the markdown to markup prior to copying.
- Trio then searches the composite for all the tags that have "data-trio-callback" attributes (see tag attributes below), which name the Node modules that Trio calls to dynamically add content derived from Trio's metadata to the composite (see advanced page composition below).
- Finally, page composition is complete and Trio writes the composite to an .html file using Trio's file naming conventions (see page generation).
Trio repeats this process for every fragment/template pair declared in the project.
Anatomy Of A Generated Page, Steps 1 - 3: Basic Page Composition
At a minimum, every page that Trio generates is composed of a single fragment asset and a single template asset and optionally one or more include assets.
Basic page composition allows template assets to provide the overall layout of pages, fragment assets to augments those pages with their own unique content, and include assets to add blocks of commonly repeated content.
Basic page composition produces pages that don't vary much in the way of content other than what each fragment, template and include asset contributes. Often you will find that your pages require dynamic content, which is what advanced page composition provides through the use of tag-based callbacks and metadata.
Anatomy Of A Generated Page, Step 4: Advanced Page Composition
Since Trio is built on top of Node (it is currently using v14 LTS), you have all the latest ES6+ goodies to work with without having to transpile your code. In addition, and this is a biggie, your markup remains "clean", readable, easy to reason about and maintain because it isn't littered with scattered bits of framework API calls or with templating engine statements.
You can add as many tag-based callback assets as needed to a template, fragment and include assets by decorating the tags you are targeting with the data-trio-callback="name of module" tag attribute.
Trio predefines numerous front matter properties that it expects to find in your assets, which it uses internally when creating its composites. For example, Trio expects to find the name of the template that a fragment is associated with in its front matter template property.
You can also define your own custom front matter properties in fragment assets as need requires. Both Trio's predefined front matter properties and any custom front matter properties that you define are exposed to your tag-based callbacks.
Trio uses the awesome OS library called gray-matter to implement its front matter support.
Introduced in Trio v2.0.0, Collections are groups of pages that are dynamically generated by Trio that you would otherwise have to manually create yourself.
Introduced in Trio v3.0.0, Permalinks are used to modify how Trio generates the destination paths and ultimately the URLs of pages that it generates for your site.
Trio's use of common metaphors for its project assets, its approach to page composition, its organized collections of metadata and its tag-based callback mechanism serve to create an easy to learn and use, highly adaptable and powerful platform upon which to create your static sites.