0.1.0 • Published 5 years ago

looptic v0.1.0

Weekly downloads
4
License
BSD-3-Clause
Repository
github
Last release
5 years ago

looptic

Getting started

Install package

npm install looptic

Use it to create a static site (or anything else)

'use strict';

const {looptic, LoopticOptions} = require('looptic');

const options = new LoopticOptions();

options.apiEndpoint = 'https://YOUR_REPOSITORY.prismic.io/api/v2';
options.accessToken = 'YOUR_ULTRA_SUPER_SECRET_LONG_ACCESS_TOKEN_WITH_A_LOT_OF_RANDOM_CHARACTERS';
options.dist = './dist';

looptic(options).then(() => console.log('Finished'));

Architecture overview

Prismic.io + looptic + handlebars templates --> HTML File

Custom resolvers

resolveTemplates

options.resolveTemplates = async function resolveTemplates() {
    return Promise.resolve({
        index: '<h1>Page {{document.uid}}</h1>',
        post: '<h1>Blog Post {{document.uid}}</h1>'
    });
}

resolvePartials

options.resolvePartials = async function resolvePartials() {
    return Promise.resolve({
        title: '<title>My Blog</title>',
        footer: 'Copyright 2019'
    });
}

resolveHelpers

options.resolveHelpers = async function resolveHelpers() {
    function quickFox(color) {
        return 'The quick ' + color + ' fox jumps over the lazy dog';
    }

    return Promise.resolve({
        quickFox: quickFox
    });
}

Usage

<h1>The Fox</h1>
<p>{{quickFox "brown"}}</p>

resolveBlueprint

options.resolveBlueprint = async function(data, context) {
    const filename = data.document.uid + '.html';
    const templateName = data.document.type;
    const blueprint = context.createBlueprint(filename, templateName, data)

    const blueprints = [blueprint];

    Promise.resolve(blueprints);
}

Helpers

Looptic Helpers

toText

Converts a prismic richt text field to text.

<div>{{toText document.data.richText}}</div>