Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
.DS_Store
Comment on lines +1 to +2

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

7 changes: 7 additions & 0 deletions cli.js
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}');
Binary file added img/Pseudocódigo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
let fs = require('fs')

Choose a reason for hiding this comment

The 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 fs = require('fs')
const fs = require('fs')

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let fetch = require ('node-fetch')
let colors = require ("colors")
const fetch = require ('node-fetch')
const colors = require ("colors")



// read file
function readMd (uri){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function readMd (uri){
function readMd (file){

Choose a reason for hiding this comment

The 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}`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return `${readString}`
return readString

}
// get links
function getLinks(uri){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function getLinks(uri){
function getLinks(md){

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Validar links
// Validate links

let totalLinksValidate =[]
function validateLinks(uri){
Comment on lines +21 to +22

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let totalLinksValidate =[]
function validateLinks(uri){
let totalLinksValidate =[]
function validateLinks(uri){

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

La invocación no es aqui

Suggested change
validateLinks(uri)


// contar links

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// contar links
// en ingles

let totalLinksCounted =[]
function counterLinks(uri){
Comment on lines +48 to +49

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let totalLinksCounted =[]
function counterLinks(uri){
let totalLinksCounted =[]
function counterLinks(uri){

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
function counterLinks(uri){
function statsLinks(uri){

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)

Choose a reason for hiding this comment

The 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
counterLinks(uri)
counterLinks(uri)



module.exports = { readMd }
1 change: 1 addition & 0 deletions otraCosa.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[Markdown](https://es.wikipedia.org/wiki/

Choose a reason for hiding this comment

The 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
[Markdown](https://es.wikipedia.org/wiki/
[Markdown](https://es.wikipedia.org/wiki/

Loading