Skip to content

Instantly share code, notes, and snippets.

@Munter
Created July 23, 2019 15:22
Show Gist options
  • Save Munter/1f2deefc0e35633305d9d1651a928f5a to your computer and use it in GitHub Desktop.
Save Munter/1f2deefc0e35633305d9d1651a928f5a to your computer and use it in GitHub Desktop.
const AssetGraph = require('assetgraph');
async function everythingIsRelative(graphInstance) {
const relations = graphInstance.findRelations({hrefType: {$not: 'inline'}});
for (const relation of relations) {
relation.hrefType = 'relative';
}
}
async function main() {
const graph = new AssetGraph({
root: 'docs/_site',
canoniralRoot: 'https://mochajs.org/'
});
// Logging for easier debugging
await graph.logEvents();
// Add initial entry points
await graph.loadAssets('index.html');
// Expand the graph to the entirety of your site
await graph.populate({
followRelations: {
crossorigin: false
}
});
// Make al URL's root relative
await everythingIsRelative(graph);
// Write the whole thing to the `dist`-folder
await graph.writeAssetsToDisc({isLoaded: true}, 'dist-demo');
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment