diff --git a/package.json b/package.json index bd90acb..62677a7 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "awesome-seo", "version": "1.0.0", "description": "A curated list of SEO links.", - "main": "src/run.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/template.md b/template.md deleted file mode 100644 index be49d78..0000000 --- a/template.md +++ /dev/null @@ -1,22 +0,0 @@ -# Awesome SEO - -{{lastUpdateBadge}} -[![Join the chat at https://gitter.im/teles/awesome-seo](https://img.shields.io/badge/gitter-join%20chat%20%E2%86%92%20-brightgreen.svg?style=flat-square)](https://gitter.im/teles/awesome-seo?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) - -> A curated list of seo links! - -[br]: https://upload.wikimedia.org/wikipedia/commons/4/40/Icons-flag-br.png "Conteúdo disponível em português" - -{{#each this}} -## {{@key}} - {{#each this}} -* [{{link.title}}]({{link.href}}) {{#if link.description}}- {{link.description}} {{/if}} {{#equal link.language 'Português'}}![brazilian flag][br]{{/equal}} - {{/each}} - -{{/each}} - -## License - -[![CC0](https://i.creativecommons.org/l/by/4.0/88x31.png)](http://creativecommons.org/licenses/by/4.0/) - -To the extent possible under law, [Jota Teles](http://github.com/teles) has waived all copyright and related or neighboring rights to this work. \ No newline at end of file diff --git a/template.tags.md b/template.tags.md deleted file mode 100644 index e12a545..0000000 --- a/template.tags.md +++ /dev/null @@ -1,3 +0,0 @@ -# - A curated list of seo links! -[br]: https://upload.wikimedia.org/wikipedia/commons/4/40/Icons-flag-br.png "Conteúdo disponível em português" \ No newline at end of file diff --git a/update.js b/update.js deleted file mode 100644 index 97d9859..0000000 --- a/update.js +++ /dev/null @@ -1,159 +0,0 @@ -GLOBAL = {}; -GLOBAL.endpoint_url = "https://sheetsu.com/apis/1878d9c1"; -GLOBAL.template_url = "template.md"; -GLOBAL.readme_url = "readme.md"; - -var http = require("https"); -var handlebars = require('handlebars'); -var fs = require('fs'); -process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; - -handlebars.registerHelper('equal', function(lvalue, rvalue, options) { - if (arguments.length < 3) - throw new Error("Handlebars Helper equal needs 2 parameters"); - if( lvalue!=rvalue ) { - return options.inverse(this); - } else { - return options.fn(this); - } -}); - -handlebars.registerHelper('lastUpdateBadge', function() { - var today = new Date(); - var dd = today.getDate(); - var mm = today.getMonth(); - var yyyy = today.getFullYear(); - - if(dd<10) { - dd='0'+dd - } - - var monthNames = ["JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"]; - today = dd+' '+ monthNames[mm]+' '+yyyy; - today = encodeURIComponent(today); - - var markdownBadge = "![Last update](https://img.shields.io/badge/last%20update-"+today+"-green.svg?style=flat-square)"; - - return new handlebars.SafeString(markdownBadge); -}); - -var request = http.get(GLOBAL.endpoint_url, function (response) { - var buffer = ""; - var data; - var result; - - response.on("data", function (chunk) { - buffer += chunk; - }); - - response.on("end", function (err) { - data = JSON.parse(buffer); - var results = data.result; - var links = parseResultToLinks(results); - var categoriesMap = arrayLinksToMap(links); - var tagsMap = arrayLinksToTags(links); - imprimeTagsParaREADME(tagsMap); - imprimeLinksParaREADME(categoriesMap); - }); -}); - -function Link(title, href, description, category, language, tags){ - this.title = title; - this.href = href; - this.description = description; - this.category = category; - this.language = language; - this.tags = tags; -} - -function Category(name, link){ - this.name = name; - this.link = link; -} - -function Tag(name, link){ - this.name = name; - this.link = link; -} - -function arrayLinksToMap(links){ - var categoriesMap = {}; - - for(var i=0; i < links.length; i++) { - var link = links[i]; - var categoryName = link.category.toString().trim(); - var category = new Category(categoryName, link); - - if(!categoriesMap[categoryName]){ - categoriesMap[categoryName] = [category]; - } - else{ - categoriesMap[categoryName].push(category) - } - } - return categoriesMap; -} - -function arrayLinksToTags(links){ - var tagsMap = {}; - - for(var i=0; i < links.length; i++){ - var link = links[i]; - link.tags.map(function(tag){ - if(tag.toString().length > 1){ - var tagName = tag.toString().trim(); - var tag = new Tag(tagName, link); - } - - if(!tagsMap[tagName]){ - tagsMap[tagName] = [tag]; - } - else{ - tagsMap[tagName].push(tag) - } - }); - } - return tagsMap; -} - - -function parseResultToLinks(results){ - var links = []; - for(var i=results.length-1; i >= 0; i--){ - var result = results[i]; - var title = result['Título']; - var href = result['Link']; - var description = result['Descrição']; - var category = result['Categoria']; - var language = result['Idioma']; - var tags = result['Tags'].split(","); - var link = new Link(title, href, description, category, language, tags); - links.push(link); - } - return links; -} - -function imprimeTagsParaREADME(tagsMap){ - var i = 0; - for (var tags in tagsMap) { - var tagName = tagsMap[tags][0].name; - if (tagsMap.hasOwnProperty(tags) && typeof(tagName)!== 'undefined') { - // creates the tag folder if it doesnt exists - if (!fs.existsSync(tagName)){ - fs.mkdirSync(tagName); - } - } - } -} - -function imprimeLinksParaREADME(links){ - fs.readFile(GLOBAL.template_url, 'utf-8', function(error, source){ - var template = handlebars.compile(source); - var markdown = template(links); - fs.writeFile(GLOBAL.readme_url, markdown, function(err) { - if(err) { - return console.log(err); - } - }); - }); -} \ No newline at end of file