diff --git a/scripts/web.js b/scripts/web.js index 6a4d9b30e..992108db0 100644 --- a/scripts/web.js +++ b/scripts/web.js @@ -138,7 +138,7 @@ if(!util.isTravisCI() || (util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] // Test the API's rate limit (keep for various reasons) https.get({host: githubApi, path: '/rate_limit?', headers: headers}, res => { res.on('data', function (chunk) { - console.log('Remaining requests: '+JSON.parse(chunk).resources.core.remaining); + console.log(`Remaining requests: ${JSON.parse(chunk).resources.core.remaining}`); }); }); // Send requests and wait for responses, write to the page @@ -146,10 +146,10 @@ if(!util.isTravisCI() || (util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] https.get({host: githubApi, path: '/repos/chalarangelo/30-seconds-of-code/contributors?per_page=1', headers: headers}, resContributors => { https.get({host: githubApi, path: '/repos/chalarangelo/30-seconds-of-code/stargazers?per_page=1', headers: headers}, resStars => { let commits = resCommits.headers.link.split('&').slice(-1)[0].replace(/[^\d]/g, ''), - contribs = resContributors.headers.link.split('&').slice(-1)[0].replace(/[^\d]/g, ''), - stars = resStars.headers.link.split('&').slice(-1)[0].replace(/[^\d]/g, ''); - indexStaticFile = indexStaticFile.replace(/\$snippet-count/g, Object.keys(snippets).length).replace(/\$commit-count/g,commits).replace(/\$contrib-count/g,contribs).replace(/\$star-count/g, stars); - indexStaticFile = minify(indexStaticFile, { + contribs = resContributors.headers.link.split('&').slice(-1)[0].replace(/[^\d]/g, ''), + stars = resStars.headers.link.split('&').slice(-1)[0].replace(/[^\d]/g, ''); + indexStaticFile = indexStaticFile.replace(/\$snippet-count/g, Object.keys(snippets).length).replace(/\$commit-count/g, commits).replace(/\$contrib-count/g,contribs).replace(/\$star-count/g, stars); + indexStaticFile = minify(indexStaticFile, { collapseBooleanAttributes: true, collapseWhitespace: true, decodeEntities: false, @@ -181,56 +181,56 @@ if(!util.isTravisCI() || (util.isTravisCI() && (process.env['TRAVIS_EVENT_TYPE'] // Create the output for individual category pages try { // Add the start static part - output += `${startPart + '\n'}`; + output += `${startPart}${'\n'}`; // Loop over tags and snippets to create the table of contents for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1][0]))] .filter(v => v) .sort((a, b) => util.capitalize(a, true) === 'Uncategorized' ? 1 : util.capitalize(b, true) === 'Uncategorized' ? -1 : a.localeCompare(b))) { - output += `

` + - md - .render(`${util.capitalize(tag, true)}\n`) - .replace(/

/g, '') - .replace(/<\/p>/g, '') + - `

`; - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) - output += md - .render(`[${taggedSnippet[0]}](./${tag}#${taggedSnippet[0].toLowerCase()})\n`) - .replace(/

/g, '') - .replace(/<\/p>/g, '') - .replace(//g, '') + .replace(/<\/p>/g, '') + + ''; + for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) + output += md + .render(`[${taggedSnippet[0]}](./${tag}#${taggedSnippet[0].toLowerCase()})\n`) + .replace(/

/g, '') + .replace(/<\/p>/g, '') + .replace(/

`; - output += ` `; + output += '
'; + output += ' '; // Loop over tags and snippets to create the list of snippets for (let tag of [...new Set(Object.entries(tagDbData).map(t => t[1][0]))] .filter(v => v) .sort((a, b) => util.capitalize(a, true) === 'Uncategorized' ? 1 : util.capitalize(b, true) === 'Uncategorized' ? -1 : a.localeCompare(b))) { - let localOutput = output.replace(/\$tag/g, util.capitalize(tag)).replace(new RegExp(`./${tag}#`,'g'),'#'); - localOutput += md - .render(`## ${util.capitalize(tag, true)}\n`) - .replace(/

/g, '

'); - for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) - localOutput += - '
' + - md - .render(`\n${snippets[taggedSnippet[0] + '.md']}`) - .replace(/

/g, `${taggedSnippet[1].includes('advanced')?'advanced':''}

`) - .replace(/<\/h3>/g, '

') - .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) - .replace(/<\/pre>\s+
📋 Copy to clipboard' +
-          '
'; - // Add the ending static part - localOutput += `\n${endPart + '\n'}`; - // Optimize punctuation nodes - localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize operator nodes - localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - // Optimize keyword nodes - localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); - pagesOutput.push({'tag': tag,'content': localOutput}); + let localOutput = output.replace(/\$tag/g, util.capitalize(tag)).replace(new RegExp(`./${tag}#`,'g'),'#'); + localOutput += md + .render(`## ${util.capitalize(tag, true)}\n`) + .replace(/

/g, '

'); + for (let taggedSnippet of Object.entries(tagDbData).filter(v => v[1][0] === tag)) + localOutput += + '
' + + md + .render(`\n${snippets[taggedSnippet[0] + '.md']}`) + .replace(/

/g, `${taggedSnippet[1].includes('advanced')?'advanced':''}

`) + .replace(/<\/h3>/g, '

') + .replace(/
([^\0]*?)<\/code><\/pre>/gm, (match, p1) => `
${Prism.highlight(unescapeHTML(p1), Prism.languages.javascript)}
`) + .replace(/<\/pre>\s+
📋 Copy to clipboard' +
+        '
'; + // Add the ending static part + localOutput += `\n${endPart + '\n'}`; + // Optimize punctuation nodes + localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize operator nodes + localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + // Optimize keyword nodes + localOutput = util.optimizeNodes(localOutput, /([^\0<]*?)<\/span>([\n\r\s]*)([^\0]*?)<\/span>/gm, (match, p1, p2, p3) => `${p1}${p2}${p3}`); + pagesOutput.push({'tag': tag,'content': localOutput}); } // Minify output pagesOutput.forEach(page => { @@ -269,8 +269,8 @@ try { .filter(key => beginnerSnippetNames.map(name => name+'.md').includes(key)) .reduce((obj, key) => { obj[key] = snippets[key]; - return obj; - }, {}); + return obj; + }, {}); for (let snippet of Object.entries(filteredBeginnerSnippets)) beginnerOutput +=