Skip to content
This repository has been archived by the owner on Feb 11, 2022. It is now read-only.

Theming

Andreas Eldh edited this page Mar 15, 2015 · 9 revisions

Theming

The building blocks of Antwar themes are React components. They serve as templates for posts and pages.

Required files

There are a few required file in an Antwar theme.

  • Body(.js/.jsx/.coffee)
    A react component that will be put directly in the body tag and which should render content that all routes of your sites have in common. This component is responsible for rendering its children.

  • Post(.js/.jsx/.coffee)
    The base component for all blog posts in your site. This file is responsible for rendering the content of the blog post.

  • Blog(.js/.jsx/.coffee)
    The landing page for your blog. Usually lists all (or recent) blog posts.

Optional files

A theme can contain any files, but there are a few that antwar core looks for.

  • functions(.js/.coffee)
    Functions that hook into component generation. For example if you want to control how url:s are generated or how the content is parsed before it's passed to the components. (Full docs on these functions further down in this document).

Antwar theming helpers

Antwar exposes a few files through which the theme can access and manipulate the site content.

PathsMixin

The PathsMixin has methods for getting posts and pages. require('antwar-core/PathsMixin') includes the mixin.

These functions are provided by PathsMixin

  • getAllPosts()
    Get all the posts the site.

  • getAllPages()
    Get all the pages the site.

  • getPost()
    Get the post for the current path

  • getPostForPath(path)
    Get the post for a specific path

  • getPageTitle()
    Get the title of the current page

MdHelper

Exposes functions to parse Markdown files.

  • render(content)
    Returns the rendered html of a .md file

  • parse(content)
    Returns the parsed content of a .md file as a json object.

Processing hooks

Antwar core provides some hooks into the post processing. Define functions in the file functions(.js/.coffee).

  • preProcessPosts(posts)
    Called before posts are processed by antwar. Has to return an object with the same structure as the input.

  • postProcessPosts(posts)
    Called after posts are processed by antwar. Has to return an object with the same structure as the input.

  • postProcessPages(pages)
    Called after page are processed by antwar. Has to return an object with the same structure as the input.

  • url(file, fileName)
    Sets the url of the post. Has to return a string that is unique for each post.

  • date(file, fileName)
    Sets the date field of the post. Has to return a string.

  • preview(file, fileName)
    Sets the preview of the post. Has to return a string.

Clone this wiki locally