Real-world examples
See Spignite in action
Here are some real-world Spignite examples. Even though we didn't talk about existing operations, these examples will be understandable.

Simple website

1
const { Spig } = require('spignite');
2
​
3
Spig.hello();
4
​
5
Spig
6
.on('/**/*.{md,njk}')
7
​
8
._("INIT")
9
.pageMeta()
10
.pageLinks()
11
.tags()
12
​
13
._("RENDER")
14
.render()
15
.applyTemplate()
16
.htmlMinify()
17
;
18
​
19
Spig
20
.on('/**/*.{png,jpg,gif}')
21
​
22
._("INIT")
23
.assetLinks()
24
​
25
._("IMG")
26
.imageMinify()
27
;
28
​
29
Spig.run();
Copied!
This is how one simple website is built. Let's dig the code.
  • Spig.hello defines the HELLO phase with all the default operations that works on default structure: dealing with css, javascript, images, static etc. Content and layers are not covered.
  • INIT phase for markdown files collect some meta-data (attributes) and define the output links. Similar thing happens on the second set (images), where only output links are defined.
  • INIT phase on the first set also collect tags and pages that defines them.
  • RENDER phase is one that process markdown files to HTML (render() operation), then applies the template, and finally, performs the HTML minification of the code.
  • Images set does not have the RENDER phase, but the IMG phase, where images gets minified.
The order of phases is: HELLO, INIT, RENDER, IMG.

Advanced example

1
const { Spig } = require('spignite');
2
​
3
Spig.hello();
4
​
5
function postsToRoot(path) {
6
if (path.dirname.startsWith('/posts/')) {
7
path.dirname = path.dirname.substr(6);
8
}
9
}
10
​
11
Spig
12
.on('/**/*.{md,njk}')
13
.watchSite()
14
​
15
._('META')
16
.pageMeta()
17
.readingTime()
18
.tags()
19
.summary()
20
​
21
._('INIT')
22
.do('slug-from-title', fileRef => {...})
23
.pageLinks()
24
.rename(postsToRoot)
25
​
26
._('RENDER')
27
.render()
28
.applyTemplate()
29
.htmlMinify()
30
;
31
​
32
Spig
33
.on('/**/*.{png,jpg,gif}')
34
​
35
._('IMAGES')
36
.assetLinks()
37
.rename(postsToRoot);
38
​
39
Spig
40
.on('/index.json')
41
​
42
._('RENDER^BEFORE')
43
.pageMeta()
44
.applyTemplate()
45
;
46
​
47
Spig.run();
Copied!
This example has two custom javascript codes: one is a function postsToRoot and the second is a lambda in line #22 (removed for simplicity).
  • Content files this time defines also reading time and extract the summary, all in META phase. In other words, we just collect meta-data about the content.
  • INIT phase is all about links. It defines page slugs from the page title and removes the /post/ prefix from the URL.
  • RENDER phase is the same as in previous example.
  • IMAGES process the images from the content folder. Note that images from the /src/images are processed in HELLO phase, defined in defaults by Spig.hello().
  • index.json is some kind of meta-data file that needs to exist on website. It is executed before RENDER phase. This is the only time in the pipeline when we have both the target links defined AND the content is still in Markdown.
Last modified 1yr ago
Export as PDF
Copy link