Skip to content

Commit

Permalink
reformat missed files
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed May 18, 2018
1 parent 7c8f551 commit 0a5604f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 33 deletions.
7 changes: 3 additions & 4 deletions scripts/dedefine.js
Expand Up @@ -7,10 +7,9 @@

const through = require('through2');
const defineRx = /typeof\s+define\s*===?\s*['"]function['"]\s*&&\s*(?:define\.amd|typeof\s+define\.amd\s*===?\s*['"]object['"]\s*&&\s*define\.amd)/g;
function createStream () {
return through.obj(function (chunk, enc, next) {
this.push(String(chunk)
.replace(defineRx, 'false'));
function createStream() {
return through.obj(function(chunk, enc, next) {
this.push(String(chunk).replace(defineRx, 'false'));
next();
});
}
Expand Down
21 changes: 13 additions & 8 deletions scripts/docs-update-toc.js
Expand Up @@ -16,18 +16,23 @@ const docsFilepath = path.join(__dirname, '..', 'docs', 'index.md');

console.log('Updating TOC...');

fs.createReadStream(docsFilepath)
fs
.createReadStream(docsFilepath)
.on('error', err => {
console.log(err);
process.exit(1);
})
.on('close', () => {
console.log('Done.');
})
.pipe(utils.concat(input => {
const output = toc.insert(String(input), {
bullets: '-',
maxdepth: 2
}).replace(/\n\n$/, '\n');
return fs.writeFileSync(docsFilepath, output);
}));
.pipe(
utils.concat(input => {
const output = toc
.insert(String(input), {
bullets: '-',
maxdepth: 2
})
.replace(/\n\n$/, '\n');
return fs.writeFileSync(docsFilepath, output);
})
);
55 changes: 34 additions & 21 deletions scripts/netlify-headers.js
Expand Up @@ -2,9 +2,7 @@

const AssetGraph = require('assetgraph');

const headers = [
'Content-Security-Policy'
];
const headers = ['Content-Security-Policy'];

const resourceHintTypeMap = {
HtmlPreloadLink: 'preload',
Expand All @@ -13,8 +11,10 @@ const resourceHintTypeMap = {
HtmlDnsPrefetchLink: 'dns-prefetch'
};

function getHeaderForRelation (rel) {
let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${rel.as}; type=${rel.to.contentType}`;
function getHeaderForRelation(rel) {
let header = `Link: <${rel.href}>; rel=${resourceHintTypeMap[rel.type]}; as=${
rel.as
}; type=${rel.to.contentType}`;

if (rel.as === 'font') {
header = `${header}; crossorigin=anonymous`;
Expand All @@ -23,24 +23,31 @@ function getHeaderForRelation (rel) {
return header;
}

new AssetGraph({ root: 'docs/_dist' })
new AssetGraph({root: 'docs/_dist'})
.loadAssets('*.html')
.populate({
followRelations: { type: 'HtmlAnchor', crossorigin: false }
followRelations: {type: 'HtmlAnchor', crossorigin: false}
})
.queue(function (assetGraph) {
const assets = assetGraph.findAssets({ type: 'Html', isInline: false });
.queue(function(assetGraph) {
const assets = assetGraph.findAssets({type: 'Html', isInline: false});

const headerMap = {};

assets.forEach(function (asset) {
const url = '/' + asset.url.replace(assetGraph.root, '').replace(/#.*/, '').replace('index.html', '');
assets.forEach(function(asset) {
const url =
'/' +
asset.url
.replace(assetGraph.root, '')
.replace(/#.*/, '')
.replace('index.html', '');
if (!headerMap[url]) {
headerMap[url] = [];
}

headers.forEach(function (header) {
const node = asset.parseTree.querySelector('meta[http-equiv=' + header + ']');
headers.forEach(function(header) {
const node = asset.parseTree.querySelector(
'meta[http-equiv=' + header + ']'
);

if (node) {
headerMap[url].push(`${header}: ${node.getAttribute('content')}`);
Expand All @@ -51,9 +58,11 @@ new AssetGraph({ root: 'docs/_dist' })
});

const firstCssRel = asset.outgoingRelations.filter(r => {
return r.type === 'HtmlStyle' &&
r.crossorigin === false &&
r.href !== undefined;
return (
r.type === 'HtmlStyle' &&
r.crossorigin === false &&
r.href !== undefined
);
})[0];

if (firstCssRel) {
Expand All @@ -62,15 +71,19 @@ new AssetGraph({ root: 'docs/_dist' })
headerMap[url].push(header);
}

const resourceHintRelations = asset.outgoingRelations.filter(r => ['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type));
const resourceHintRelations = asset.outgoingRelations.filter(r =>
['HtmlPreloadLink', 'HtmlPrefetchLink'].includes(r.type)
);

resourceHintRelations.forEach(rel => {
headerMap[url].push(getHeaderForRelation(rel));

rel.detach();
});

const preconnectRelations = asset.outgoingRelations.filter(r => ['HtmlPreconnectLink'].includes(r.type));
const preconnectRelations = asset.outgoingRelations.filter(r =>
['HtmlPreconnectLink'].includes(r.type)
);

preconnectRelations.forEach(rel => {
let header = `Link: <${rel.href}>; rel=preconnect`;
Expand All @@ -83,17 +96,17 @@ new AssetGraph({ root: 'docs/_dist' })

console.log('\n## Autogenerated headers:\n');

Object.keys(headerMap).forEach(function (url) {
Object.keys(headerMap).forEach(function(url) {
console.log(url);

const httpHeaders = headerMap[url];

httpHeaders.forEach(function (header) {
httpHeaders.forEach(function(header) {
console.log(` ${header}`);
});

console.log('');
});
})
.writeAssetsToDisc({ isLoaded: true })
.writeAssetsToDisc({isLoaded: true})
.run();

0 comments on commit 0a5604f

Please sign in to comment.