ah-content-exporter
v0.5.3
Published
Export a folder with web content
Downloads
6
Readme
Anthill Content Exporter
Export a folder of web content, resolving assets external to the folder.
It will generate a new folder where all external assets have been copied into the folder with all references updated in source files.
Will currently look for following when resolving resources:
- href
- src
- url()
All HTML and CSS files will be inspected.
Not Yet Supported
- CSS imports (not using 'url()')
- srcset property
NOTE: Templates, markdown, and other files that need compiling should be compiled before exporting.
NOTE 2: Although absolute paths are supported they can create very long paths.
API
run(src, config, next)
Export a folder
param src
Source to the folder to export.
Alternatively a specific file can be included in the path. Then only assets directly or indirectly linked from that file will be included. Note that this means that no PDFs or other supporting files will be included in the export, unless linked (e.g. with href property).
The path given will be resolved from where the script is running.
config.dest
Where to put the resulting folder. Defaults to '../_exports'
config.output
What to call the resulting folder. Defaults to original folder name
config.include
Array of filepaths that should be included even though they are not referenced, i.e. force them to be included.
config.offline
If remote assets should be downloaded. Defaults to false
Currently following file formats will be downloaded png, jpg, gif, css, js
Examples
// Copy everything in the folder and assets linked from html, css and js files
exporter.run("slides/safety", {}, function(err, dest) { console.log("Exported to", dest) });
// Copy index.html file and any assets directly, or indirectly linked to that file
exporter.run("slides/safety/index.html", {}, function(err, dest) { console.log("Exported to", dest) });
// Copy index.html file and any assets directly, or indirectly linked to that file. Also include default files
// and download any external referencs
var config = {
offline: true,
include: ['_vendor/jquery.min.js']
}
exporter.run("slides/safety/index.html", config, function(err, dest) { console.log("Exported to", dest) });
See tests for more examples of how to use the API.
resolve(src, defaultRefs, next)
Resolve all assets referenced in a folder without exporting.
Will return an object like:
{
local: ["img/bg.png", ...],
external: ["../_shared/css/styles.css", ...],
remote: ["https://cdn.jquery.com", ...]
}