Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
rawAttrs: link.rawAttrs,
validId: isValidId,
};
}
return null;
};
// Build a list of files to lint from the layouts directory.
const filesToLint = buildFileList("../layouts");
const linkLintErrors = {};
for (let i = 0; i < filesToLint.length; i++) {
const fileToLint = filesToLint[i];
const html = fs.readFileSync(fileToLint, "utf8");
const parsedHtml = parse.parse(html);
const links = parsedHtml.querySelectorAll("a").map(validateTrackingLink)
.filter(function(result) { return result !== null });
if (links.length > 0) {
linkLintErrors[fileToLint] = links;
}
}
const filesWithErrors = Object.keys(linkLintErrors);
function createErrorOutput(error) {
let msg = "";
if (!error.validId) {
msg += "Link missing 'data-tracking-id' attribute.";
}
msg += "\n";
return msg;
fs.readFile('views/leaderboard.html', 'utf8', (err, html) => {
if (err) {
throw err;
}
var sort_array = [];
for (var key in data) {
sort_array.push({ key: key, score: data[key].score, nick: data[key].nick });
}
sort_array.sort(function (x, y) { return y.score - x.score });
const root = parse(html);
const tbody = root.querySelector('tbody');
for (var i = 0; i < sort_array.length; i++) {
var item = data[sort_array[i].key];
const table = `
${i + 1}
${item.nick}
${item.score}
`
tbody.appendChild(table);
}
// add term date
res.status(200).send(root.toString());
});
});
const fs = require('fs');
const path = require('path');
const recursive = require("recursive-readdir");
const { parse } = require('node-html-parser');
const baseurl = path.resolve(__dirname, "..");
const ghUrl = 'https://ml5js.github.io/ml5-examples'
const indexPath = `${baseurl}/public/index.html`
let $index = parse(fs.readFileSync(indexPath, 'utf8'));
let $myLinks = $index.querySelector('#myLinks')
// clear the content;
$myLinks.set_content("")
const p5Examples = getReferences(`${baseurl}/p5js`, 'p5js', ghUrl);
const plainJsExamples = getReferences(`${baseurl}/javascript`, 'javascript', ghUrl);
const d3Examples = getReferences(`${baseurl}/d3`, 'd3', ghUrl);
const p5Header = `<div class="category-header"><h2>ml5 examples with p5.js</h2></div>`
const jsHeader = `<div class="category-header"><h2>ml5 examples with plain javascript</h2></div>`
const d3Header = `<div class="category-header"><h2>ml5 examples with d3</h2></div>`
// p5 examples
$myLinks.appendChild(p5Header);
addToDom(p5Examples, $myLinks)
matches.forEach(absPath => {
const content = fs.readFileSync(absPath);
const root = parse(`${content}`);
const codes = root.querySelectorAll('docs-code');
codes.map(c => c.attributes).filter(a => a.path).forEach(c => {
const path = c.path;
const completePath = findMatchingFile(allFiles, path);
if (!completePath) {
console.error(`ERROR: could not find a file for the short path ${path}`);
} else {
object[path] = fs.readFileSync(completePath).toString().replace(/from 'src\/public_api'/g, `from 'iwerk-angular-ui'`);
}
});
});
fs.writeFileSync(path.join(projectRootPath, 'assets/examples.json'), JSON.stringify(object));
export default async (username: string): Promise => {
if (!username) {
return {
result: false,
details: 'No Codecademy account provided',
};
}
const url = `${URL}${username}`;
try {
const page = (await axios.get(url)).data;
const dom = parse(page) as HTMLElement;
const skills = dom
.querySelectorAll('.contentContainer__3yhRX203mZ5d3LM9QdQ1lj')
.map(skill => {
const name = skill.querySelector('.title__3niw5hwoyf-vt1SazvY5Gd').childNodes[0].rawText;
const isPassed =
skill.querySelector('.description__5pwX6COkDGktqHdkXYDuu').childNodes[0].rawText === 'Completed';
return { name, isPassed };
})
.filter(skill => TASKS.includes(skill.name) && skill.isPassed);
console.log('Codecademy skills =>', JSON.stringify(skills));
return {
result: skills.length === TASKS.length,
function updateMl5Reference(filePath, ml5src){
let pos;
let el = parse(fs.readFileSync(filePath, 'utf8'));
let scripts = el.querySelectorAll('script')
let selectedRef = scripts.find((item, idx) => {
if(item.rawAttrs.includes('ml5')){
pos = idx;
return item
}
})
selectedRef.rawAttrs = ml5src
scripts[pos] = selectedRef;
fs.writeFileSync(filePath, el, 'utf8');
}
export function parseHTML(html: string) {
return (parse(html) as (HTMLElement & {
valid: boolean;
}))
}
async function loadRooms(domain, page = 1) {
if (!domainVars.doneWithRooms.hasOwnProperty(domain)) {
domainVars.doneWithRooms[domain] = false
}
if (domainVars.doneWithRooms[domain]) return
const res = await request(`https://chat.${domain}.com/?tab=all&sort=active&page=${page}`)
const root = parse(res)
const rooms = root.querySelectorAll('.roomcard').map(room => ({
id: +room.querySelector('.room-name a').rawAttributes.href.replace(/\/rooms\/(\d+)\/(?:.+)?/, '$1'),
name: room.querySelector('span.room-name').attributes.title,
users: +room.querySelector('.room-users').rawAttributes.title.replace(/ users? present/, '')
}))
if (!domainVars.rooms.hasOwnProperty(domain)) {
domainVars.rooms[domain] = {}
}
const newRooms = rooms
.filter(room => !domainVars.rooms[domain].hasOwnProperty(room.id))
domainVars.doneWithRooms[domain] = newRooms.length === 0
newRooms
.forEach(room => domainVars.rooms[domain][room.id] = room)
return newRooms
}