You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

@static-pages/file-writer

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@static-pages/file-writer

Generic file writer implementation for @static-pages/core.


Version published
Weekly downloads
260
decreased by-5.45%
Maintainers
2
Created
Weekly downloads
 

Readme

Source

Static Pages / File writer

Writes contents of a page data to file.

Usage

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 });

Docs

@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 defaults

The default behaviour is to guess file path by a few possible properties of the data:

  • if data.url is defined, append .html and use that.
  • if data.header.path is defined, replace extension to .html and use that.
  • if nothing matches call the onInvalidPath handler with undefined file name.

renderer defaults

The 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).

Where to use this?

This module can be used to generate static HTML pages. Read more at the Static Pages JS project page.

Keywords

FAQs

Package last updated on 29 Dec 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc