Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
@static-pages/file-writer
Advanced tools
Generic file writer implementation for @static-pages/core.
Writes contents of a page data to file.
import fileWriter from '@static-pages/file-writer';
const write = fileWriter({
outDir: 'dist',
outFile: d => d.url + '.html',
renderer: d => d.body,
onOverwrite: fileName => console.log(fileName),
onInvalidPath: fileName => console.log(fileName),
});
const pageData = {
url: 'folder/file',
body: '[file contents]',
};
write({ value: pageData });
@static-pages/file-writer@5
and higher versions are compatible with @static-pages/core@6
and higher versions.
writer(options: Options): void
Options
options.outDir
(default: dist
) sets the output directory.options.outFile
resolves the file name based on the provided page data.options.renderer
renders the file contents based on the provided page data.options.onOverwrite
callback function that gets executed when a file name collision occurs. Defaults to log on the console.options.onInvalidPath
callback function that gets executed when a file name contains invalid characters. Defaults to log on the console.outFile
defaultsThe default behaviour is to guess file path by a few possible properties of the data:
data.url
is defined, append .html
and use that.data.header.path
is defined, replace extension to .html
and use that.onInvalidPath
handler with undefined
file name.renderer
defaultsThe default behaviour is to retrieve file contents from data.body
.
Tip: you can implement your own rendering logic in the
renderer
callback, eg:renderer: d => myRenderingLibrary.render('template', d)
.
This module can be used to generate static HTML pages. Read more at the Static Pages JS project page.
FAQs
Generic file writer implementation for @static-pages/core.
The npm package @static-pages/file-writer receives a total of 3 weekly downloads. As such, @static-pages/file-writer popularity was classified as not popular.
We found that @static-pages/file-writer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.