@@ -4,53 +4,81 @@ repo: sphido/sphido
44homepage : https://sphido.org/
55language :
66 - JavaScript
7+ - Node.js
78license :
89 - MIT
910templates :
10- - Nunjucks
11- description : A rocket fast, lightweight, static site generator.
12- twitter : ozzyczech
11+ - Any JS
12+ description : A rocket fast, light-weight and flexible static site generator.
13+ twitter : sphidocms
14+
1315---
1416
15- Sphido is pure ** static site generator** written with speed, simplicity and flexibility in mind.
17+ I know, another [ static site generator] ( https://github.com/collections/static-site-generators ) !
18+ This one is different - it's totally minimalistic. Basically, it's just two functions.
19+ The first, the ` getPages() ` function, allows you to retrieve a list of pages,
20+ and the ` allPages() ` function allows you to iterate through them.
21+
22+ You get a static site generator that is:
23+
24+ - 🚀 rocket fast
25+ - 💭️ light-weight
26+ - 🤘 no dependencies
27+ - ⚡️ flexible
28+
29+ ### Supports
30+
31+ - YAML front-matter
32+ - html/markdown source files
33+ - custom extenders
34+ - any JS templates
1635
17- ## Installation
36+ ### Installation
1837
19- ``` bash
20- $ npm i @sphido/core @sphido/frontmatter @sphido/marked @sphido/meta @sphido/nunjucks
38+ ``` shell
39+ yarn add @sphido/core # that's all
2140```
2241
23- ## Usage
42+ ### Usage
2443
2544``` javascript
26- const globby = require (' globby' )
27- const { getPages } = require (' @sphido/core' )
28- const { save } = require (' @sphido/nunjucks' )
29-
30- ;(async () => {
31- // 1. get list of pages
32- const pages = await getPages (
33- await globby (' content/**/*.md' ),
34- ... [
35- require (' @sphido/frontmatter' ),
36- require (' @sphido/marked' ),
37- require (' @sphido/meta' ),
38- { save },
39- ]
40- )
41-
42- // 2. save them (with default template)
43- for await (const page of pages ) {
44- await page .save (page .dir .replace (' content' , ' public' ))
45- }
46- })()
45+ #! / usr/ bin/ env node
46+
47+ import {dirname , relative , join } from ' node:path' ;
48+ import {getPages , allPages , readFile , writeFile } from ' @sphido/core' ;
49+ import slugify from ' @sindresorhus/slugify' ;
50+ import {marked } from ' marked' ;
51+
52+ const pages = await getPages ({path: ' content' }, // ... extenders
53+ (page ) => {
54+ page .slug = slugify (page .name ) + ' .html' ;
55+ page .dir = dirname (page .path );
56+ });
57+
58+ for (const page of allPages (pages)) {
59+ page .output = join (' public' , relative (' content' , page .dir ), page .slug );
60+ page .content = marked (await readFile (page .path ));
61+ await writeFile (page .output , ` <!DOCTYPE html>
62+ <html lang="en" dir="ltr">
63+ <head>
64+ <meta charset="UTF-8">
65+ <script src="https://cdn.tailwindcss.com?plugins=typography"></script>
66+ <title>${ page .name } | Sphido Example</title>
67+ </head>
68+ <body class="prose mx-auto my-6">${ page .content } </body>
69+ <!-- Generated by Sphido from ${ page .path } -->
70+ </html>
71+ ` );
72+ }
4773```
4874
49- [ See more examples ] ( https://github.com/sphido/examples ) on GitHub.
75+ ### Run script
5076
51- ## Supports
77+ ``` shell
78+ node index.js
79+ ```
5280
53- - YAML front-matter
54- - html/markdown source
55- - custom extenders
56- - Nunjucks templates
81+ ### Need more examples?
82+
83+ Let's look at the [ source code of sphido.org ] ( https://sphido.org ) or
84+ the [ examples repository ] ( https://github.com/sphido/examples ) .
0 commit comments