some little updates

This commit is contained in:
Martin Donnelly 2016-03-21 13:47:26 +00:00
parent 01fa7b4495
commit 7564136a67
4 changed files with 302 additions and 278 deletions

View File

@ -56,6 +56,8 @@ var Keeper = (function () {
var html = new EJS({url: 'partials/view.ejs'}).render(vdata);
$bodyContents.empty();
$bodyContents.scrollTop(0);
$bodyContents.append(html);
$('#redo').on('click', function () {

View File

@ -6,7 +6,7 @@
<span id="visualTabs">
<span class="lnr lnr-tag"></span>
<% for(var i=0; i<data.tags.list.length; i++) {%>
<a class="mui--text-dark mui--text-button" href="#?<%=data.tags.list[i]%>"><%=data.tags.list[i]%></a>
<a class="mui--text-dark-secondary mui--text-button" href="#?<%=data.tags.list[i]%>"><%=data.tags.list[i]%></a>
<% } %>
<span class="lnr lnr-pencil" id="tageditmode"></span>
</span>

View File

@ -28,8 +28,8 @@ gulp.task('scripts', function() {
.pipe(concat('main.js'))
/*.pipe(gulp.dest('dist/js'))*/
/*.pipe(rename({suffix: '.min'}))*/
/* .pipe(uglify())*/
.pipe(concat('app.js'))
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('dist/js'))
.pipe(notify({ message: 'Scripts task complete' }));
});

View File

@ -25,100 +25,112 @@ var dbCouch = nano.use(db_name);
var bodyfile = __dirname + '/' + 'body.html';
var htmlfile = __dirname + '/' + 'testoutput.html';
var generics = [
'ARTICLE',
'div.content_column',
'div.post',
'div.page',
'#recipe-single'
'ARTICLE',
'div.content_column',
'div.post',
'div.page',
'#recipe-single'
];
function cleaner(b) {
var _b = b;
var _b = b;
var unwanted = [
'div#disqus_thread',
'SCRIPT',
'FOOTER',
'div.ssba',
'.shareaholic-canvas',
'.yarpp-related',
'div.dfad',
'div.postFooterShare',
'div#nextPrevLinks',
'.post-comments',
'HEADER',
'.post-title',
'#side-menu',
'.footer-container',
'#pre-footer',
'#cakephp-global-navigation',
'.masthead',
'.breadcrumb-header',
'.single-recipe-sidebar',
'#recipe-related-videos'
];
var unwanted = [
'div#disqus_thread',
'SCRIPT',
'FOOTER',
'div.ssba',
'.shareaholic-canvas',
'.yarpp-related',
'div.dfad',
'div.postFooterShare',
'div#nextPrevLinks',
'.post-comments',
'HEADER',
'.post-title',
'#side-menu',
'.footer-container',
'#pre-footer',
'#cakephp-global-navigation',
'.masthead',
'.breadcrumb-header',
'.single-recipe-sidebar',
'#recipe-related-videos'
];
for (var i = 0; i < unwanted.length; i++) {
_b.find(unwanted[i]).remove();
}
for (var i = 0; i < unwanted.length; i++) {
_b.find(unwanted[i]).remove();
}
return _b;
return _b;
}
function insertBookmark(obj) {
logger.debug('Inserting into couch...');
logger.info(util.inspect(obj));
dbCouch.insert(obj, function(err, body, header) {
if (err) {
logger.error('Error inserting into couch');
return;
}
});
logger.debug('Insert done..');
logger.debug('Inserting into couch...');
logger.info(util.inspect(obj));
dbCouch.insert(obj, function (err, body, header) {
if (err) {
logger.error('Error inserting into couch');
return;
}
});
logger.debug('Insert done..');
}
function updateBookmark(obj, _id, _rev) {
logger.debug('Updating couch...');
var _obj = obj;
_obj._id = _id;
_obj._rev = _rev;
logger.debug('Updating couch...');
var _obj = obj;
_obj._id = _id;
_obj._rev = _rev;
dbCouch.insert(_obj, function(err, body, header) {
if (err) {
logger.error('Error updating into couch');
return;
} else {
logger.info('I think we updated ok...');
}
});
logger.debug('Update done..');
dbCouch.insert(_obj, function (err, body, header) {
if (err) {
logger.error('Error updating into couch');
return;
} else {
logger.info('I think we updated ok...');
busEmitter.emit("updateTagsDB");
}
});
logger.debug('Update done..');
}
var doInsertBookmark = (obj) => {
// logger.info('sendSocket: ' + JSON.stringify(obj));
insertBookmark(obj);
var doInsertBookmark = (obj) =>
{
// logger.info('sendSocket: ' + JSON.stringify(obj));
insertBookmark(obj);
};
var doUpdateBookmark = (obj, _id, _rev) => {
// logger.info('sendSocket: ' + JSON.stringify(obj));
updateBookmark(obj, _id, _rev);
var doUpdateBookmark = (obj, _id, _rev) =>
{
// logger.info('sendSocket: ' + JSON.stringify(obj));
updateBookmark(obj, _id, _rev);
};
var doGetBookmark = (obj) => {
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(obj);
var doGetBookmark = (obj) =>
{
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(obj);
};
var doGetBookmarkRedo = (obj) => {
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(obj);
var doGetBookmarkRedo = (obj) =>
{
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(obj);
};
var doGetBookmarkRes = (url, res) => {
logger.debug('doGetBookmarkRes');
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(url, res);
var doGetBookmarkRes = (url, res) =>
{
logger.debug('doGetBookmarkRes');
// logger.info('sendSocket: ' + JSON.stringify(obj));
genericGrab(url, res);
};
var doUpdateTagsDB = () =>
{
logger.debug('Update the tags database...');
}
// Events
busEmitter.on('saveBookmarkData', doInsertBookmark);
busEmitter.on('updateBookmarkData', doUpdateBookmark);
@ -126,258 +138,268 @@ busEmitter.on('getBookmark', doGetBookmark);
busEmitter.on('getBookmarkRes', doGetBookmarkRes);
busEmitter.on('getBookmarkRedo', doGetBookmarkRedo);
busEmitter.on('updateTagsDB', doUpdateTagsDB);
function processBody(body, url, _id, _rev) {
var obj, tdihbody, i, urlObj, urlPrefix;
var $ = cheerio.load(body);
var title = $('TITLE').text();
var obj, tdihbody, i, urlObj, urlPrefix;
var $ = cheerio.load(body);
var title = $('TITLE').text();
// try to find a body to grab
// try to find a body to grab
i = 0;
i = 0;
while (($(generics[i]).length == 0) && (i < generics.length)) {
i++;
}
logger.debug(i);
while (($(generics[i]).length == 0) && (i < generics.length)) {
i++;
}
logger.debug(i);
obj = {};
if (i < generics.length) {
tdihbody = $(generics[i]);
logger.debug(tdihbody.length);
tdihbody = cleaner(tdihbody);
logger.debug(title);
obj = {};
if (i < generics.length) {
tdihbody = $(generics[i]);
logger.debug(tdihbody.length);
tdihbody = cleaner(tdihbody);
logger.debug(title);
}
else {
// bah. nothing to reduce so just grab the body, tidy it and use that
tdihbody = $('BODY');
logger.debug(tdihbody.length);
tdihbody = cleaner(tdihbody);
logger.debug(title);
}
}
else {
// bah. nothing to reduce so just grab the body, tidy it and use that
tdihbody = $('BODY');
logger.debug(tdihbody.length);
tdihbody = cleaner(tdihbody);
logger.debug(title);
}
urlObj = URL.parse(url);
urlPrefix = urlObj.protocol + '//' + urlObj.host + '/';
try {
tdihbody.find('IMG').each(function(i, elem) {
let s, src = $(this).attr("src");
urlObj = URL.parse(url);
urlPrefix = urlObj.protocol + '//' + urlObj.host + '/';
try {
tdihbody.find('IMG').each(function (i, elem) {
let s, src = $(this).attr("src");
if (!STRING(src).startsWith('http')) {
src = urlPrefix + STRING(src).stripLeft('/').s;
}
s = 'http://image.silvrtree.co.uk/900,fit/' + src;
if (!STRING(src).startsWith('http')) {
src = urlPrefix + STRING(src).stripLeft('/').s;
}
s = 'http://image.silvrtree.co.uk/900,fit/' + src;
$(this).attr("src", s);
$(this).attr("src", s);
});
}
catch (e) {
logger.error(e);
}
});
}
catch (e) {
logger.error(e);
}
obj.url = url;
obj.html = $.html();
obj.reduced = STRING(tdihbody.html()).trim().s;
obj.title = STRING(title).collapseWhitespace().s;
obj.url = url;
obj.html = $.html();
obj.reduced = STRING(tdihbody.html()).trim().s;
obj.title = STRING(title).collapseWhitespace().s;
if (_id !== null) {
busEmitter.emit("updateBookmarkData", obj, _id, _rev);
}
else {
busEmitter.emit("saveBookmarkData", obj);
}
if (_id !== null) {
busEmitter.emit("updateBookmarkData", obj, _id, _rev);
}
else {
busEmitter.emit("saveBookmarkData", obj);
}
return obj;
return obj;
}
function genericGrab(obj, res) {
var url, _id = null, _ver = null;
if (typeof obj === 'string') {
logger.info(obj);
url = obj;
}
else {
url = obj.url;
_id = obj._id || null;
_ver = obj._rev || null;
}
logger.warn(typeof obj);
logger.info(url);
logger.info(_id);
logger.info(_ver);
request(url, function(err, resp, body) {
if (err)
throw err;
if (resp.headers.hasOwnProperty('content-encoding')) {
logger.warn('content-encoding');
if (resp.headers['content-encoding'] == 'gzip') {
// to test http://chaosinthekitchen.com/2009/07/lime-and-coconut-chicken/
var gunzip = zlib.createGunzip();
var jsonString = '';
resp.pipe(gunzip);
gunzip.on('data', function(chunk) {
jsonString += chunk;
});
gunzip.on('end', function() {
console.log((jsonString));
callback(JSON.stringify(jsonString));
});
gunzip.on('error', function(e) {
console.log(e);
});
}
else {
var b = processBody(body, url, _id, _ver);
if (res != null) {
res.render('grabbed');
}
}
var url, _id = null, _ver = null;
if (typeof obj === 'string') {
logger.info(obj);
url = obj;
}
else {
var b = processBody(body, url, _id, _ver);
if (res != null) {
res.render('grabbed', {data: b});
}
url = obj.url;
_id = obj._id || null;
_ver = obj._rev || null;
}
});
logger.warn(typeof obj);
logger.info(url);
logger.info(_id);
logger.info(_ver);
request(url, function (err, resp, body) {
if (err)
throw err;
if (resp.headers.hasOwnProperty('content-encoding')) {
logger.warn('content-encoding');
if (resp.headers['content-encoding'] == 'gzip') {
// to test http://chaosinthekitchen.com/2009/07/lime-and-coconut-chicken/
var gunzip = zlib.createGunzip();
var jsonString = '';
resp.pipe(gunzip);
gunzip.on('data', function (chunk) {
jsonString += chunk;
});
gunzip.on('end', function () {
console.log((jsonString));
callback(JSON.stringify(jsonString));
});
gunzip.on('error', function (e) {
console.log(e);
});
}
else {
var b = processBody(body, url, _id, _ver);
if (res != null) {
res.render('grabbed');
}
}
}
else {
var b = processBody(body, url, _id, _ver);
if (res != null) {
res.render('grabbed', {data: b});
}
}
});
}
router.get('/list', function(req, res) {
logger.debug('list..');
router.get('/list', function (req, res) {
logger.debug('list..');
dbCouch.view('titles', 'titles', function(err, body) {
if (!err) {
dbCouch.view('titles', 'titles', function (err, body) {
if (!err) {
var outJSON = [];
body.rows.forEach(function(doc) {
outJSON.push({id: doc.id, title: doc.value})
});
var outJSON = [];
body.rows.forEach(function (doc) {
outJSON.push({id: doc.id, title: doc.value})
});
//logger.debug(util.inspect(body));
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({list: outJSON}));
//logger.debug(util.inspect(body));
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({list: outJSON}));
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
}
});
});
router.get('/entry/:id', function (req, res) {
logger.debug('entry..');
logger.debug(req.params.id);
dbCouch.get(req.params.id, function (err, body) {
if (!err) {
var outJSON = {};
outJSON._id = body._id;
outJSON._rev = body._rev;
outJSON.title = body.title;
outJSON.reduced = body.reduced;
outJSON.url = body.url;
outJSON.tags = body.tags || {solid: '', list: []};
//logger.debug(util.inspect(body));
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify(outJSON));
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
}
});
});
router.post('/add', function (req, res) {
logger.debug('add entry..');
var t = req.body;
if (t.hasOwnProperty('url')) {
var url = JSON.parse(t.url.toString());
logger.debug(url);
busEmitter.emit("getBookmark", t);
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
logger.error('No data block!');
}
});
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({adding: url}));
});
router.get('/entry/:id', function(req, res) {
logger.debug('entry..');
router.post('/tags', function (req, res) {
var t = req.body;
console.log(t);
logger.debug(req.params.id);
logger.info('regetting:' + req.body._id);
dbCouch.get(req.params.id, function(err, body) {
if (!err) {
dbCouch.get(req.body._id, function (err, body) {
if (!err) {
var outJSON = {};
outJSON._id = body._id;
outJSON._rev = body._rev;
outJSON.title = body.title;
outJSON.reduced = body.reduced;
outJSON.url = body.url;
outJSON.tags = body.tags || {solid:'',list:[]};
var obj = {};
//logger.debug(util.inspect(body));
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify(outJSON));
obj.url = body.url;
obj.html = body.html;
obj.reduced = body.reduced;
obj.title = body.title;
obj.tags = req.body.tags;
logger.info('Updating...');
busEmitter.emit("updateBookmarkData", obj, body._id, body._rev, res);
var outJSON = {};
outJSON._id = body._id;
outJSON._rev = body._rev;
outJSON.title = body.title;
outJSON.reduced = body.reduced;
outJSON.url = body.url;
outJSON.tags = req.body.tags;
//logger.debug(util.inspect(body));
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify(outJSON));
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
}
});
});
router.post('/redo', function (req, res) {
logger.debug('redoing entry..');
var t = req.body;
console.log(t);
if (t.hasOwnProperty('url')) {
var url = t.url.toString();
logger.debug(url);
busEmitter.emit("getBookmark", t);
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
logger.error('No data block!');
}
});
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({adding: url}));
});
router.post('/add', function(req, res) {
logger.debug('add entry..');
var t = req.body;
if (t.hasOwnProperty('url')) {
var url = JSON.parse(t.url.toString());
logger.debug(url);
busEmitter.emit("getBookmark", t);
}
else {
logger.error('No data block!');
}
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({adding: url}));
});
router.post('/tags', function(req,res) {
var t = req.body;
console.log(t);
logger.info('regetting:' + req.body._id);
dbCouch.get(req.body._id, function(err, body) {
if (!err) {
var obj = {};
obj.url = body.url;
obj.html = body.html;
obj.reduced = body.reduced;
obj.title = body.title;
obj.tags = req.body.tags;
logger.debug(util.inspect(obj));
logger.info('Updating...');
busEmitter.emit("updateBookmarkData", obj, body._id, body._rev);
}
else {
res.writeHead(500, {"ContentType": "application/json"});
res.end(JSON.stringify({}));
}
});
});
router.post('/redo', function(req, res) {
logger.debug('redoing entry..');
var t = req.body;
console.log(t);
if (t.hasOwnProperty('url')) {
var url = t.url.toString();
logger.debug(url);
busEmitter.emit("getBookmark", t);
}
else {
logger.error('No data block!');
}
res.writeHead(200, {"ContentType": "application/json"});
res.end(JSON.stringify({adding: url}));
});
router.get('/new', function(req, res) {
logger.debug('Save new');
busEmitter.emit("getBookmarkRes", req.query.url, res);
router.get('/new', function (req, res) {
logger.debug('Save new');
busEmitter.emit("getBookmarkRes", req.query.url, res);
});