Last active
December 25, 2015 11:38
-
-
Save jsoffer/6969950 to your computer and use it in GitHub Desktop.
Filtro para resultados de Google Search (que no use reescritura del url, etc)
This file contains hidden or 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
/* Uso: 'node gsearch.js'; en el navegador, 'http://localhost:8000/?q=la búsqueda' */ | |
var http = require('http') | |
, url = require('url') | |
, google = require('google-tools') | |
, mu = require('mu2'); | |
mu.root = __dirname + '/templates'; | |
http.createServer(function (req, web_out) { | |
var kw = url.parse(req.url, true).query['q']; | |
if (process.env.NODE_ENV == 'DEVELOPMENT') { | |
mu.clearCache(); | |
} | |
google.search({q: kw}, function(err, resultados){ | |
console.log(kw); | |
var stream = mu.compileAndRender('index.html', {varios: resultados['results']}); | |
stream.pipe(web_out); | |
}); | |
}).listen(8000, '127.0.0.1'); | |
/* | |
index.html (plantilla; poner en el subdirectorio '/templates'): | |
<html><body> | |
{{#varios}} | |
<p><ul><li><a href={{link}}>{{link}}</a></li><li>{{snippet}}</li></ul></p> | |
{{/varios}} | |
</body></html> | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment