@chronocide/spider
v0.3.1
Published
Simple static HTML generator
Downloads
51
Readme
Install
Install using npm:
npm i @chronocide/spider
Usage
spider
only supports JS ESM exports. If you wish to use TypeScript, JSX or anything else, code must be transpiled to JS ESM. See @chronocide/esbuild-plugin-spider for an examples.
Single page
// index.js
export const url = '/';
export default ({ ctime }) => `<body>${ctime}</body>`;
// about.js
export const url = '/about';
export default '<h1>About</h1>';
// about-spider.js
export const url = '/about/spider';
export default '<h1>About spider</h1>';
import fs from 'fs';
import spider from '@chronocide/spider';
/**
* path: '/index.html'
* html: '<body>Mon, 10 Oct 2011 23:24:11 GMT</body>'
*/
await spider()('index.js');
/**
* path: '/about.html'
* html: '<h1>About</h1>'
*/
await spider()('about.js');
/**
* path: '/about/spider.html'
* html: '<h1>About spider</h1>'
*/
await spider()('about-spider.js');
/**
* path: 'www/about/spider.html'
* html: '<h1>About spider</h1>'
*/
await spider({ outdir: 'www' })('about-spider.js');
Multiple pages
// blogs.js
import fsp from 'fs/promises';
import path from 'path';
const files = await Promise.all(fsp.readdir(path.join(process.cwd(), 'src/blog/posts')));
const pages = await Promise.all(files.map(file => {
const { name } = path.parse(file);
const html = await fs.readFile(file, 'utf-8');
return ({
url: `/blog/${name}`,
html
});
}));
export default pages;
import fs from 'fs';
import spider from '@chronocide/spider';
/**
* path: '/blog/<name>'
* html: '<blog>'
*/
await spider()('blogs.js');