-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mi md links Iris Trejo #28
base: master
Are you sure you want to change the base?
Changes from all commits
6d9439b
7b1c543
8666cf5
8acdaf6
e00b3d6
c6d2341
7119783
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
.DS_Store | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#! / usr / bin / env nodo | ||
|
||
//Grab provided args. | ||
const [,, ...args] = process.argv | ||
|
||
//print hello world provided args. | ||
console.log('hello worls ${args}'); |
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||||||||||||
let fs = require('fs') | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cuando las variable mutan(cambian su valor) se usa let, si no mutan se usa const
Suggested change
|
||||||||||||||||
let index = process.argv.indexOf("--file") | ||||||||||||||||
let uri = process.argv[index+1] | ||||||||||||||||
let fetch = require ('node-fetch') | ||||||||||||||||
let colors = require ("colors") | ||||||||||||||||
Comment on lines
+4
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
// read file | ||||||||||||||||
function readMd (uri){ | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. define mejor el parametro |
||||||||||||||||
let readString = fs.readFileSync(uri, 'utf-8') | ||||||||||||||||
return `${readString}` | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
} | ||||||||||||||||
// get links | ||||||||||||||||
function getLinks(uri){ | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
let links = readMd(uri) | ||||||||||||||||
let regEx = /\bhttps:\/\/([a-z0-9.a-z0-9\/]+)([-a-z0-9?=_$#\/]+)([.a-z0-9]+)/gi | ||||||||||||||||
let arrayLinks = links.match(regEx); | ||||||||||||||||
return arrayLinks | ||||||||||||||||
} | ||||||||||||||||
// Validar links | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
let totalLinksValidate =[] | ||||||||||||||||
function validateLinks(uri){ | ||||||||||||||||
Comment on lines
+21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
let readlinks = getLinks(uri) | ||||||||||||||||
let promises = readlinks.map(link => fetch(link) | ||||||||||||||||
.then(result =>{ | ||||||||||||||||
totalLinksValidate.push(({ url:result.url, status:result.status, boolean: true })) | ||||||||||||||||
}) | ||||||||||||||||
.catch(err => { | ||||||||||||||||
totalLinksValidate.push(({url:link, status:'Error', text: err.message, boolean: false })) | ||||||||||||||||
}) | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
return Promise.all(promises) | ||||||||||||||||
.then(result =>{ | ||||||||||||||||
totalLinksValidate.reduce((accountant, elem) =>{ | ||||||||||||||||
if (elem.status!== 200){ | ||||||||||||||||
console.log(colors.yellow(elem)); | ||||||||||||||||
} | ||||||||||||||||
if (elem.status === 200){ | ||||||||||||||||
console.log(colors.green(elem)); | ||||||||||||||||
} | ||||||||||||||||
}) | ||||||||||||||||
}) | ||||||||||||||||
} | ||||||||||||||||
validateLinks(uri) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. La invocación no es aqui
Suggested change
|
||||||||||||||||
|
||||||||||||||||
// contar links | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
let totalLinksCounted =[] | ||||||||||||||||
function counterLinks(uri){ | ||||||||||||||||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||
let readlinks = getLinks(uri) | ||||||||||||||||
let promises = readlinks.map(link => fetch(link) | ||||||||||||||||
.then(result =>{ | ||||||||||||||||
totalLinksCounted.push(({ url:result.url, status:result.status, boolean: true })) | ||||||||||||||||
}) | ||||||||||||||||
.catch(err => { | ||||||||||||||||
totalLinksCounted.push(({url:link, status:'Error', text: err.message, boolean: false })) | ||||||||||||||||
}) | ||||||||||||||||
) | ||||||||||||||||
|
||||||||||||||||
return Promise.all(promises) | ||||||||||||||||
.then(result =>{ | ||||||||||||||||
console.log('total: ', totalLinksCounted.length); | ||||||||||||||||
console.log('Rechazados ',totalLinksCounted.reduce((accountant, elem) =>{ | ||||||||||||||||
if (elem.status !== 200){ | ||||||||||||||||
return accountant += 1 | ||||||||||||||||
} | ||||||||||||||||
return accountant | ||||||||||||||||
},0)); | ||||||||||||||||
console.log('Buenos ', totalLinksCounted.reduce((accountant, elem) =>{ | ||||||||||||||||
if (elem.status === 200){ | ||||||||||||||||
return accountant +=1 | ||||||||||||||||
} | ||||||||||||||||
return accountant | ||||||||||||||||
},0)); | ||||||||||||||||
return result | ||||||||||||||||
}) | ||||||||||||||||
} | ||||||||||||||||
counterLinks(uri) | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ten cuidado con las invocaciones, busca que todo este en un solo lado
Suggested change
|
||||||||||||||||
|
||||||||||||||||
|
||||||||||||||||
module.exports = { readMd } |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1 @@ | ||||||
[Markdown](https://es.wikipedia.org/wiki/ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. este archivo debería estar en una carpeta llamada assets y a su vez esta carpeta estar excluida
Suggested change
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
esta genial el excluir estas carpetas, añadiría la carpeta assets y package-lock.json