Transforming Pages

Beyond adding or updating page metadata Acetate also provides helper functions for transforming and altering pages at a larger scale. There are 4 transformation methods.

Transformers are particularly useful for manipulating or extracting data from a page's template property or for altering metadata like url or dest in complex ways.

Example: Extracting Markdown Headers

module.exports = function (acetate) {
  // ...

  const MARKDOWN_HEADER_REGEX = /^#{1,6}\s(.+)$/;

  acetate.transform('**/*.md', function (page) {
    if (page.title) {
      return page;
    }

    var headers = MARKDOWN_HEADER_REGEX.exec(page.template);

    if (headers && headers[1]) {
      page.title = headers[1];
    }

    return page;
  });

  // ...
};

Edit this Page on GitHub