forked from braziljs/newsletter-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f55e72
commit 487ef99
Showing
3 changed files
with
97 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,46 @@ | ||
|
||
class Comment { | ||
constructor (data = {}) { | ||
this.applyData(data) | ||
} | ||
constructor(data = {}) { | ||
this.applyData(data) | ||
} | ||
|
||
applyData (data) { | ||
this.mdBody = data.body | ||
this.htmlBody = window.markdown.toHTML(data.body) | ||
this.title = this.mdBody.match(/^[\*_][\*_]\[(.+)\].+[\*_][\*_][\n\r]/) | ||
this.title = this.title ? this.title[1] : '' | ||
this.link = this.mdBody.match(/^[\*_][\*_].+\((.+)\)[\*_][\*_][\n\r]/) | ||
this.link = this.link ? this.link[1] : '' | ||
this.outline = `<a href="${this.link}">${this.title}</a>:<br/>${this.link}<br/>` | ||
this.created_at = data.created_at | ||
this.id = data.id | ||
this.url = data.url | ||
this.author = { | ||
id: data.user.id, | ||
login: data.user.login, | ||
avatar: data.user.avatar_url, | ||
url: data.user.html_url | ||
} | ||
this.applyCategory() | ||
applyData(data) { | ||
this.mdBody = data.body | ||
this.htmlBody = window.markdown.toHTML(data.body) | ||
this.title = this.mdBody.match(/^[\*_][\*_]\[(.+)\].+[\*_][\*_][\n\r]/) | ||
this.title = this.title ? this.title[1] : '' | ||
this.link = this.mdBody.match(/^[\*_][\*_].+\((.+)\)[\*_][\*_][\n\r]/) | ||
this.link = this.link ? this.link[1] : '' | ||
this.outline = `<a href="${this.link}">${this.title}</a>:<br/>${this.link}<br/>` | ||
this.created_at = data.created_at | ||
this.id = data.id | ||
this.url = data.url | ||
this.author = { | ||
id: data.user.id, | ||
login: data.user.login, | ||
avatar: data.user.avatar_url, | ||
url: data.user.html_url | ||
} | ||
this.applyCategory() | ||
} | ||
|
||
applyCategory () { | ||
let cat = this.mdBody.match(/[\n\r][\*_](.+)[\*_]$/m) | ||
let testCat = cat[1].toLowerCase() | ||
applyCategory() { | ||
let cat = this.mdBody.match(/[\n\r][\*_](.+)[\*_]$/m) | ||
let testCat = cat[1].toLowerCase() | ||
|
||
if (testCat.match(/(new|not.cia|novidade|an.nci|announc)/)) { | ||
cat = "Notícias" | ||
} else if (testCat.match(/(event|confer.ncia|summit|workshop|congresso)/)) { | ||
cat = "Eventos" | ||
} else if (testCat.match(/(artigo|article|text|post)/)) { | ||
cat = "Artigos" | ||
} else if (testCat.match(/(talk|palestr|aula|curso|v.deo)/)) { | ||
cat = "Vídeos" | ||
} else if (testCat.match(/(tool|demo|experiment|ferrament)/)) { | ||
cat = "Demos e Ferramentas" | ||
} else { | ||
cat = 'Outros' | ||
} | ||
|
||
this.category = cat | ||
if (testCat.match(/(new|not.cia|novidade|an.nci|announc)/)) { | ||
cat = 'Notícias' | ||
} else if (testCat.match(/(event|confer.ncia|summit|workshop|congresso)/)) { | ||
cat = 'Eventos' | ||
} else if (testCat.match(/(artigo|article|text|post)/)) { | ||
cat = 'Artigos' | ||
} else if (testCat.match(/(talk|palestr|aula|curso|v.deo)/)) { | ||
cat = 'Vídeos' | ||
} else if (testCat.match(/(tool|demo|experiment|ferrament)/)) { | ||
cat = 'Demos e Ferramentas' | ||
} else { | ||
cat = 'Outros' | ||
} | ||
|
||
this.category = cat | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,63 @@ | ||
|
||
class Weekly { | ||
constructor (data) { | ||
this.applyData(data) | ||
this.state = "partial" | ||
this.loadComments().then(UI.update) | ||
this.contributors = {} | ||
this.categories = {} | ||
} | ||
static isValid (data) { | ||
if ( | ||
data.title.startsWith('Edição ') && | ||
data.repository_url === "https://api.github.com/repos/braziljs/weekly" | ||
) { | ||
if (data.labels.find(item => item.name === "campaign")) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
applyData (data) { | ||
this.id = data.id | ||
this.title = data.title | ||
this.number = data.number | ||
this.edition = this.title.match(' ([0-9]+) ')[1] || 0, | ||
this.created_at = data.created_at | ||
this.closed_at = data.closed_at | ||
this.state = data.state | ||
constructor(data) { | ||
this.applyData(data) | ||
this.state = 'partial' | ||
this.loadComments().then(UI.update) | ||
this.contributors = {} | ||
this.categories = {} | ||
} | ||
static isValid(data) { | ||
if (data.title.startsWith('Edição ') && data.repository_url === 'https://api.github.com/repos/braziljs/weekly') { | ||
if (data.labels.find(item => item.name === 'campaign')) { | ||
return true | ||
} | ||
} | ||
filterData (data) { | ||
const { id, number, created_at, closed_at, title, state } = data | ||
return { | ||
id, | ||
number, | ||
edition: this.title.match(' ([0-9]+) ')[1] || 0, | ||
created_at, | ||
closed_at, | ||
title, | ||
state | ||
} | ||
return false | ||
} | ||
applyData(data) { | ||
this.id = data.id | ||
this.title = data.title | ||
this.number = data.number | ||
;(this.edition = this.title.match(' ([0-9]+) ')[1] || 0), (this.created_at = data.created_at) | ||
this.closed_at = data.closed_at | ||
this.state = data.state | ||
} | ||
filterData(data) { | ||
const { id, number, created_at, closed_at, title, state } = data | ||
return { | ||
id, | ||
number, | ||
edition: this.title.match(' ([0-9]+) ')[1] || 0, | ||
created_at, | ||
closed_at, | ||
title, | ||
state | ||
} | ||
loadComments () { | ||
return new Promise((resolve, reject) => { | ||
if (this.comments) { | ||
return resolve(this.comments) | ||
} | ||
Github.get('comments', { issue: this.number }) | ||
.then(comments => { | ||
comments.forEach(data => { | ||
|
||
if(data.body.charAt(0) !== '*') | ||
data.body = this.applyMarkdown(data.body) | ||
} | ||
loadComments() { | ||
return new Promise((resolve, reject) => { | ||
if (this.comments) { | ||
return resolve(this.comments) | ||
} | ||
Github.get('comments', { issue: this.number }).then(comments => { | ||
comments.forEach(data => { | ||
if (data.body.charAt(0) !== '*') data.body = this.applyMarkdown(data.body) | ||
|
||
this.addComment(new Comment(data)) | ||
}) | ||
resolve(this) | ||
}) | ||
this.addComment(new Comment(data)) | ||
}) | ||
} | ||
addComment (comment) { | ||
this.contributors[comment.author.id] = comment.author | ||
this.categories[comment.category] = this.categories[comment.category] || [] | ||
this.categories[comment.category].push(comment) | ||
} | ||
applyMarkdown (item){ | ||
item = item.replace(/^\[/, '**[') | ||
item = item.replace(/\)/, ')**') | ||
item = item.trim().replace(/(.+\w)$/, '*$1*') | ||
return item | ||
} | ||
resolve(this) | ||
}) | ||
}) | ||
} | ||
addComment(comment) { | ||
this.contributors[comment.author.id] = comment.author | ||
this.categories[comment.category] = this.categories[comment.category] || [] | ||
this.categories[comment.category].push(comment) | ||
} | ||
applyMarkdown(item) { | ||
item = item.replace(/^\[/, '**[') | ||
item = item.replace(/\)/, ')**') | ||
item = item.trim().replace(/(.+\w)$/, '*$1*') | ||
return item | ||
} | ||
} |