From 12cbfba6b4b27e3edb37ca36159d5a415853945e Mon Sep 17 00:00:00 2001 From: luchenqun Date: Tue, 20 Jun 2017 16:18:46 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E4=BB=8EGithub=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97=E3=80=822=E3=80=81?= =?UTF-8?q?=E5=88=86=E7=B1=BB=E9=A1=B5=E9=9D=A2=E6=9D=A1=E7=9B=AE=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E6=97=B6=E6=8E=92=E5=BA=8F=E6=8C=89=E9=92=AEUI?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + package.json | 1 + public/css/style.css | 26 ++++--- .../scripts/controllers/menus-controller.js | 2 +- .../controllers/settings-controller.js | 27 ++++++++ public/scripts/services/bookmark-service.js | 13 ++++ public/views/settings.html | 57 ++++++++-------- public/views/tags.html | 21 ++++-- routes/api.js | 67 ++++++++++++++++++- 9 files changed, 171 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index adc2b2f..26611ed 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ my-bookmark/ ``` "body-parser": bodyParser用于解析客户端请求的body中的内容,内部使用JSON编码处理 "connect-mongo": 用于将session存入MongoDB +"cheerio": 用于后端的jQuery "cookie-parser": 处理每一个请求的cookie "crypto": 加密模块,主要用来加密用户的密码 "debug": 这个好像没用到,看名字好像调试的。 diff --git a/package.json b/package.json index 25a9a19..a580345 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ }, "dependencies": { "body-parser": "~1.15.1", + "cheerio": "^1.0.0-rc.1", "connect-mongo": "^1.3.2", "cookie-parser": "~1.4.3", "crypto": "0.0.3", diff --git a/public/css/style.css b/public/css/style.css index 01c7552..c9bab93 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -144,7 +144,7 @@ img.operator { .urlSpan { word-wrap: break-word; word-break: break-all; - cursor:default; + cursor: default; } .ui.sortable.table thead th.forbid_sorted:hover { @@ -156,16 +156,24 @@ img.operator { border-radius: 0; } -.js-p-info p{ - margin-bottom:5px; +.js-p-info p { + margin-bottom: 5px; font-size: 16px; } -.note-content{ +.note-content { font: 15px "Lucida Grande", Helvetica, Arial, sans-serif; - white-space:pre-wrap; - white-space:-moz-pre-wrap; - white-space:-pre-wrap; - white-space:-o-pre-wrap; - word-wrap:break-word; + white-space: pre-wrap; + white-space: -moz-pre-wrap; + white-space: -pre-wrap; + white-space: -o-pre-wrap; + word-wrap: break-word; +} + +.fontgreen { + color: RGB(33, 186, 69); +} + +.fontred { + color: #F00; } diff --git a/public/scripts/controllers/menus-controller.js b/public/scripts/controllers/menus-controller.js index f6cc807..c364844 100644 --- a/public/scripts/controllers/menus-controller.js +++ b/public/scripts/controllers/menus-controller.js @@ -207,7 +207,7 @@ app.controller('menuCtr', ['$scope', '$stateParams', '$state', '$window', '$time title: '操作提示', position: 'bottom center', variation: "very wide", - html: '特别提示:如果功能不正常,请先尝试清除浏览器缓存!点击查看更新日志!
1、在任意页面,按A键添加备忘录。
2、在热门收藏页面,按R键随机查看热门收藏。
3、在任意页面,按数字键切换菜单栏。
4、在书签页面鼠标放在书签上,按C复制书签链接
5、在书签页面鼠标放在书签上,按E编辑书签
6、在书签页面鼠标放在书签上,按D删除书签
7、在书签页面鼠标放在书签上,按I查看书签详情
8、在任意页面,按INSERT做添加书签
9、在任意页面,按ESC退出弹窗
' + html: "特别提示:对照更新日志,如果功能不正常,请先尝试清除浏览器缓存!
点击该按钮即可查看更新日志!

1、在任意页面,按A键添加备忘录。
2、在热门收藏页面,按R键随机查看热门收藏。
3、在任意页面,按数字键切换菜单栏。
4、在书签页面鼠标放在书签上,按C复制书签链接
5、在书签页面鼠标放在书签上,按E编辑书签
6、在书签页面鼠标放在书签上,按D删除书签
7、在书签页面鼠标放在书签上,按I查看书签详情
8、在任意页面,按INSERT做添加书签
9、在任意页面,按ESC退出弹窗
" }); }, 1000) diff --git a/public/scripts/controllers/settings-controller.js b/public/scripts/controllers/settings-controller.js index 21ac041..8c9c6eb 100644 --- a/public/scripts/controllers/settings-controller.js +++ b/public/scripts/controllers/settings-controller.js @@ -14,11 +14,30 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ $scope.key = ''; $scope.url = ''; $scope.quickUrl = {}; + $scope.updateLogs = []; + $scope.logsUrl = 'https://github.com/luchenqun/my-bookmark/commits/master'; + $scope.getUpdateLog = function(url) { + console.log(url); + $scope.updateLogs = []; + bookmarkService.getUpdateLog({ + url: url + }) + .then((data) => { + $scope.updateLogs = data.updateLogs; + $scope.logsUrl = data.oldUrl; + console.log(data); + }) + .catch((err) => { + toastr.error('获取更新日志失败。错误信息:' + JSON.stringify(err), "错误"); + }); + } + $scope.changeForm = function(index) { console.log("changeForm = ", index); $scope.form = $scope.form.map(() => false); $scope.form[index] = true; + $scope.updateLogs = []; if (index == 0 || index == 1 || index == 4) { $scope.loadShowStyle = true; @@ -53,6 +72,10 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ console.log('getTags err', err); }); } + + if (index == 5) { + $scope.getUpdateLog($scope.logsUrl); + } } $scope.changeForm($scope.form.indexOf(true)); // 马上调用一次 @@ -170,6 +193,10 @@ app.controller('settingsCtr', ['$scope', '$stateParams', '$filter', '$state', '$ saveQuickUrl(); } + $scope.jumpCommit = function(url) { + $window.open(url, '_blank'); + } + function updateShowStyle(showStyle) { setTimeout(function() { if (showStyle) { diff --git a/public/scripts/services/bookmark-service.js b/public/scripts/services/bookmark-service.js index e3ffafe..a9776c1 100644 --- a/public/scripts/services/bookmark-service.js +++ b/public/scripts/services/bookmark-service.js @@ -14,6 +14,19 @@ app.factory('bookmarkService', ['$http', '$q', function($http, $q) { }); return def.promise; }, + getUpdateLog: function(params) { + var def = $q.defer(); + $http.post('/api/getUpdateLog/', { + params: params + }) + .success(function(data) { + def.resolve(data); + }) + .error(function(data) { + def.reject('getUpdateLog error'); + }); + return def.promise; + }, login: function(params) { var def = $q.defer(); $http.post('/api/login/', { diff --git a/public/views/settings.html b/public/views/settings.html index e2ba54a..dff1494 100644 --- a/public/views/settings.html +++ b/public/views/settings.html @@ -165,6 +165,22 @@ {{key}}:{{value}}

+
+
+
+ + +
+
+ + +
+
+
确定
+
+
+
+
@@ -183,38 +199,23 @@
-
-
-
-
- - -
-
- - -
-
-
确定
-
-
-
-

更新日志

-
-
2017-06-16
-
    -
  • 修改书签操作页面选择分类的逻辑。由以前在下拉列表选分类,改为更直观地选标签。
  • -
+ +
+
正在从Github获取提交日志(大概需要30s)。。。
-
-
2017-06-14
-
    -
  • 打开mybookmark.cn,默认跳转到分类页面。
  • -
  • 移除书签栏目的标签选项,将功能移到分类页面里面的分类定制。
  • -
+
+
{{ updateLog.date }}
+
    +
  • + {{log.commit}} +
  • +
+
diff --git a/public/views/tags.html b/public/views/tags.html index 70bb5eb..3693f56 100644 --- a/public/views/tags.html +++ b/public/views/tags.html @@ -130,12 +130,23 @@
-
- - - +
+
+
+ + 点击次数 +
+
+ + 添加日期 +
+
+ + 最后点击 +
+
-
+
diff --git a/routes/api.js b/routes/api.js index 18b4000..b55a1bf 100644 --- a/routes/api.js +++ b/routes/api.js @@ -9,6 +9,7 @@ var multer = require('multer'); var webshot = require('webshot'); var fs = require('fs'); var request = require('request'); +var cheerio = require('cheerio'); var storage = multer.diskStorage({ destination: function(req, file, cb) { @@ -1051,6 +1052,68 @@ api.post('/getArticle', function(req, res) { }); }) +api.post('/getUpdateLog', function(req, res) { + console.log("getArticle username = ", req.session.username); + var params = req.body.params; + var defaultUrl = 'https://github.com/luchenqun/my-bookmark/commits/master' + var url = params.url || defaultUrl; + + request(url, function(error, response, body) { + console.log("HotBookmarks request ", error, response && response.statusCode); + if (response && response.statusCode == 200) { + const $ = cheerio.load(body); + var data = []; + $('.commit-group-title').each(function() { + var updateLogs = {}; + + var dateMap = { + 'Jan': 1, + 'Feb': 2, + 'Mar': 3, + 'Apr': 4, + 'May': 5, + 'Jun': 6, + 'Jul': 7, + 'Aug': 8, + 'Sep': 9, + 'Oct': 10, + 'Nov': 11, + 'Dec': 12, + } + var date = $(this).text().replace(/(^\s*)|(\s*$)/g, '').replace(/\s+/g, ' '); // 去除前后空格得到字符串 Commits on Jun 16, 2017; + var dateArray = date.replace(',', '').replace('Commits on ', '').split(' '); + + updateLogs.date = dateArray[2] + '-' + (dateMap[dateArray[0]] || dateArray[0]) + '-' + dateArray[1]; + updateLogs.logs = []; + + $(this).next().children('li').each(function() { + var $log = $(this).children('.table-list-cell').eq(1).children('p').children('a'); + var commit = $log.text() + var href = 'https://github.com' + $log.attr('href'); + + updateLogs.logs.push({ + commit: commit, + href: href, + }) + }) + data.push(updateLogs) + }) + + var oldUrl = $('.paginate-container .pagination a').attr('href'); + if (oldUrl) { + oldUrl = 'https://github.com' + oldUrl; + } + + res.json({ + updateLogs: data, + oldUrl: oldUrl || defaultUrl + }); + } else { + console.log("HotBookmarks request is error", error, response && response.statusCode); + } + }); +}) + api.checkSnapFaviconState = function() { db.getBookmarks() .then((bookmarks) => { @@ -1297,6 +1360,8 @@ api.getHotBookmarksByTimer = function() { }, timeout); } + + api.post('/addNote', function(req, res) { console.log("addNote username = ", req.session.username); if (!req.session.user) { @@ -1311,7 +1376,7 @@ api.post('/addNote', function(req, res) { .then((insertId) => { res.json({ retCode: 0, - insertId:insertId, + insertId: insertId, msg: "添加备忘成功 ", }) console.log('addNote insertId ', insertId)