优化预缓存,接入ServerLog

This commit is contained in:
eshengsky
2019-06-23 17:52:14 +08:00
parent f7a9940286
commit 55eacd8dd7
28 changed files with 133 additions and 165 deletions

View File

@@ -1,16 +1,19 @@
# iBlog2 # iBlog2
基于 Node.js 的开源个人博客系统,采用响应式布局,支持手机访问,功能全面,美观大方 基于 Node.js 的开源个人博客系统,现代化的 UI 和用户体验。采用响应式布局,支持手机访问,支持离线访问
**不仅仅是博客,更是 Demo**,是适合新人入门学习的完整项目。 **不仅仅是博客,更是 Demo**,是适合新人入门学习的完整项目。
(基于 ASP.NET 的版本见 [这里](https://github.com/eshengsky/iBlog/)) (基于 ASP.NET 的版本见 [这里](https://github.com/eshengsky/iBlog/))
## 界面预览 ## 界面预览
* 前台 * PC模式
![image](https://raw.githubusercontent.com/eshengsky/iBlog2/master/public/images/preview1.png) ![image](https://raw.githubusercontent.com/eshengsky/iBlog2/master/public/images/preview1.png)
* 后台 * 手机模式 + [ServerLog](https://github.com/eshengsky/ServerLog/)查看日志
![image](https://raw.githubusercontent.com/eshengsky/iBlog2/master/public/images/preview2.png) ![image](https://raw.githubusercontent.com/eshengsky/iBlog2/master/public/images/preview2.png)
* 管理后台
![image](https://raw.githubusercontent.com/eshengsky/iBlog2/master/public/images/preview3.png)
## 在线实例 ## 在线实例
我的博客 [https://skysun.name/](https://skysun.name/) 我的博客 [https://skysun.name/](https://skysun.name/)
@@ -28,7 +31,7 @@
* 关于 * 关于
* 后台管理 * 后台管理
* 网站统计 * 网站统计
* 博客管理 - 新的文章 (支持 UEditor 和 Markdown 编辑器) * 博客管理 - 新的文章 (支持 [UEditor](https://ueditor.baidu.com/website/index.html) 和 Markdown 编辑器)
* 博客管理 - 分类管理 * 博客管理 - 分类管理
* 博客管理 - 文章管理 * 博客管理 - 文章管理
* 评论管理 * 评论管理
@@ -47,7 +50,7 @@
* Web字体 [Font Awesome](https://fontawesome.com/) * Web字体 [Font Awesome](https://fontawesome.com/)
* 持久化 [MongoDB](https://www.mongodb.org/) * 持久化 [MongoDB](https://www.mongodb.org/)
* 缓存(可选) [Redis](http://redis.io/) * 缓存(可选) [Redis](http://redis.io/)
* 日志 [winston](https://github.com/winstonjs/winston/) * 日志 [ServerLog](https://github.com/eshengsky/ServerLog/)
* 多语言 [i18n](https://github.com/mashpie/i18n-node) * 多语言 [i18n](https://github.com/mashpie/i18n-node)
* 身份验证 [Passport](http://www.passportjs.org/) * 身份验证 [Passport](http://www.passportjs.org/)
* Service Worker库 [Workbox](https://github.com/GoogleChrome/workbox/) * Service Worker库 [Workbox](https://github.com/GoogleChrome/workbox/)
@@ -185,13 +188,19 @@ $ NODE_ENV=production pm2 start bin/www -i 0
#### 使用noginx #### 使用noginx
[noginx](https://github.com/eshengsky/noginx) 是基于 Node.js 的 HTTP 及反向代理服务器(类似 nginx如果你有多台 iBlog2 服务器实例,你可以使用 [noginx](https://github.com/eshengsky/noginx) 进行代理转发和负载均衡。 [noginx](https://github.com/eshengsky/noginx) 是基于 Node.js 的 HTTP 及反向代理服务器(类似 nginx如果你有多台 iBlog2 服务器实例,你可以使用 [noginx](https://github.com/eshengsky/noginx) 进行代理转发和负载均衡。
## 日志查看
* 本地开发环境,直接在终端中查看日志。
* 使用 `pm2` 部署时,使用 `pm2 logs` 查看日志。
* 使用 Chrome 扩展程序 [chrome-extension-server-log](https://github.com/eshengsky/ServerLog/tree/master/chrome-extension-server-log) 在开发者工具 (F12) 中查看日志。
## 贡献者们 ## 贡献者们
感谢给 iBlog2 项目贡献代码的朋友,感谢他们的支持,详情 [点击这里](https://github.com/eshengsky/iBlog2/graphs/contributors)。 感谢给 iBlog2 项目贡献代码的朋友,感谢他们的支持,详情 [点击这里](https://github.com/eshengsky/iBlog2/graphs/contributors)。
## 许可协议 ## 许可协议
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2016 Sky Copyright (c) 2019 Sky.Sun
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

30
app.js
View File

@@ -13,23 +13,34 @@ const auth = require('./routes/auth');
const admin = require('./routes/admin'); const admin = require('./routes/admin');
const locale = require('./routes/locale'); const locale = require('./routes/locale');
const ue = require('./routes/ue'); const ue = require('./routes/ue');
const logger = require('./utility/logger'); const tool = require('./utility/tool');
const passport = require('passport'); const passport = require('passport');
const i18n = require('./models/i18n'); const i18n = require('./models/i18n');
const serverlog = require('serverlog-node');
serverlog.config({
extension: {
enable: true,
key: 'iblog2_server_log_key'
}
});
const logger = serverlog.getLogger('app');
const log = require('./proxy/log');
const app = express(); const app = express();
/** /**
* 记录未捕获异常 * 记录未捕获异常
*/ */
process.on('uncaughtException', err => { process.on('uncaughtException', err => {
logger.errLogger(err); log.store('Error', err);
logger.error(err);
}); });
/** /**
* 记录未处理的Promise失败 * 记录未处理的Promise失败
*/ */
process.on('unhandledRejection', reason => { process.on('unhandledRejection', reason => {
logger.errLogger(reason); log.store('Error', reason);
logger.error(reason);
}); });
// 设置模板引擎 // 设置模板引擎
@@ -42,9 +53,12 @@ app.locals.staticPrefix = app.get('env') === 'production' ? '/static/dist' : '/s
// 增加安全性头部 // 增加安全性头部
app.use(helmet()); app.use(helmet());
// 注册 ServerLog 中间件以注入 req 对象给日志
app.use(serverlog.middleware());
// 记录所有请求 // 记录所有请求
app.use((req, res, next) => { app.use((req, res, next) => {
logger.info(`${req.method.toUpperCase()}: ${req.protocol}://${req.get('Host')}${req.originalUrl}`); logger.info(`${req.method.toUpperCase()} ${tool.getFullUrl(req)}`);
next(); next();
}); });
@@ -75,12 +89,14 @@ app.use(passport.session());
// 静态文件 // 静态文件
app.use('/static', express.static(path.join(__dirname, 'public'))); app.use('/static', express.static(path.join(__dirname, 'public')));
app.use('/uploads', express.static(path.join(__dirname, 'public', 'uploads')));
app.use('/nodeModules', express.static(path.join(__dirname, 'node_modules'))); app.use('/nodeModules', express.static(path.join(__dirname, 'node_modules')));
// Service Worker // Service Worker
app.get('/sw.js', (req, res) => { app.get('/sw.js', (req, res) => {
fs.readFile(path.resolve(__dirname, './sw.js'), (err, data) => { fs.readFile(path.resolve(__dirname, './sw.js'), (err, data) => {
if (err) { if (err) {
logger.error(err);
throw err; throw err;
} }
res.writeHead(200, { res.writeHead(200, {
@@ -106,7 +122,8 @@ app.use('/admin', require('connect-ensure-login')
app.use((req, res) => { app.use((req, res) => {
const err = new Error(`Not Found! URL: ${req.originalUrl}`); const err = new Error(`Not Found! URL: ${req.originalUrl}`);
err.status = 404; err.status = 404;
logger.errLogger(err, req); log.store('Warn', err);
logger.warn(`Not Found! URL: ${req.originalUrl}`);
res.status(404) res.status(404)
.render('./shared/error', { .render('./shared/error', {
code: 404, code: 404,
@@ -118,7 +135,8 @@ app.use((req, res) => {
app.use((err, req, res) => { app.use((err, req, res) => {
const code = err.status || 500; const code = err.status || 500;
err.status = code; err.status = code;
logger.errLogger(err, req); log.store('Error', err);
logger.error(err);
res.status(code) res.status(code)
.render('./shared/error', { .render('./shared/error', {
code, code,

View File

@@ -1,6 +1,7 @@
const app = require('../app'); const app = require('../app');
const ssl = require('../config.json').ssl; const ssl = require('../config.json').ssl;
const logger = require('../utility/logger'); const serverlog = require('serverlog-node');
const logger = serverlog.getLogger('www');
const port = normalizePort(process.env.PORT || '3000'); const port = normalizePort(process.env.PORT || '3000');
app.set('port', port); app.set('port', port);

View File

@@ -4,8 +4,7 @@ const mongoose = require('mongoose');
const extend = require('mongoose-schema-extend'); const extend = require('mongoose-schema-extend');
const i18n = require('./i18n'); const i18n = require('./i18n');
// use custom mongodb url or localhost mongoose.connect(dbPath);
mongoose.connect(dbPath || 'mongodb://localhost/blogrift');
const db = mongoose.connection; const db = mongoose.connection;
db.on('error', err => { db.on('error', err => {
console.error(i18n.__('error.db_1') + err); console.error(i18n.__('error.db_1') + err);

View File

@@ -3,7 +3,7 @@ const mongoose = db.mongoose;
const logSchema = new mongoose.Schema({ const logSchema = new mongoose.Schema({
// 唯一键 // 唯一键
_id: { type: mongoose.Schema.Types.ObjectId }, _id: { type: String, unique: true },
// 异常信息 // 异常信息
message: { type: String }, message: { type: String },

35
package-lock.json generated
View File

@@ -993,7 +993,6 @@
"version": "3.2.1", "version": "3.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
"dev": true,
"requires": { "requires": {
"color-convert": "1.9.3" "color-convert": "1.9.3"
} }
@@ -1641,7 +1640,6 @@
"version": "2.4.2", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", "resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", "integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
"dev": true,
"requires": { "requires": {
"ansi-styles": "3.2.1", "ansi-styles": "3.2.1",
"escape-string-regexp": "1.0.5", "escape-string-regexp": "1.0.5",
@@ -1870,7 +1868,6 @@
"version": "1.9.3", "version": "1.9.3",
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
"dev": true,
"requires": { "requires": {
"color-name": "1.1.3" "color-name": "1.1.3"
} }
@@ -1878,8 +1875,7 @@
"color-name": { "color-name": {
"version": "1.1.3", "version": "1.1.3",
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
"integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU="
"dev": true
}, },
"color-support": { "color-support": {
"version": "1.1.3", "version": "1.1.3",
@@ -2559,8 +2555,7 @@
"escape-string-regexp": { "escape-string-regexp": {
"version": "1.0.5", "version": "1.0.5",
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
"integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ="
"dev": true
}, },
"eslint": { "eslint": {
"version": "5.16.0", "version": "5.16.0",
@@ -4321,8 +4316,7 @@
"has-flag": { "has-flag": {
"version": "3.0.0", "version": "3.0.0",
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
"dev": true
}, },
"has-gulplog": { "has-gulplog": {
"version": "0.1.0", "version": "0.1.0",
@@ -5025,6 +5019,11 @@
"integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=", "integrity": "sha1-nbe1lJatPzz+8wp1FC0tkwrXJlE=",
"dev": true "dev": true
}, },
"json-stringify-safe": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz",
"integrity": "sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus="
},
"json5": { "json5": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz", "resolved": "https://registry.npmjs.org/json5/-/json5-2.1.0.tgz",
@@ -5369,6 +5368,11 @@
"yallist": "2.1.2" "yallist": "2.1.2"
} }
}, },
"lz-string": {
"version": "1.4.4",
"resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.4.4.tgz",
"integrity": "sha1-wNjq82BZ9wV5bh40SBHPTEmNOiY="
},
"make-dir": { "make-dir": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-1.3.0.tgz",
@@ -7198,6 +7202,18 @@
"send": "0.16.2" "send": "0.16.2"
} }
}, },
"serverlog-node": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/serverlog-node/-/serverlog-node-1.0.2.tgz",
"integrity": "sha512-Q4R4g+R55rUOn1y6saku4qx/tAirSZqWw4/9mnEzwYticbfBMOm2ym3LH/Njft6LPCb8dZnaSjTawOaOGlvWog==",
"requires": {
"chalk": "2.4.2",
"json-stringify-safe": "5.0.1",
"lz-string": "1.4.4",
"moment": "2.24.0",
"shortid": "2.2.14"
}
},
"set-blocking": { "set-blocking": {
"version": "2.0.0", "version": "2.0.0",
"resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz",
@@ -7681,7 +7697,6 @@
"version": "5.5.0", "version": "5.5.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
"dev": true,
"requires": { "requires": {
"has-flag": "3.0.0" "has-flag": "3.0.0"
} }

View File

@@ -43,6 +43,7 @@
"scrollnav": "git+https://github.com/jimmynotjim/scrollNav.git#v2.7.3", "scrollnav": "git+https://github.com/jimmynotjim/scrollNav.git#v2.7.3",
"semver": "^5.5.0", "semver": "^5.5.0",
"serve-favicon": "^2.5.0", "serve-favicon": "^2.5.0",
"serverlog-node": "^1.0.2",
"shortid": "^2.2.4", "shortid": "^2.2.4",
"showdown": "^1.8.6", "showdown": "^1.8.6",
"simplemde": "^1.11.2", "simplemde": "^1.11.2",

View File

@@ -1,3 +1,4 @@
const shortid = require('shortid');
const logModel = require('../models/log') const logModel = require('../models/log')
.LogModel; .LogModel;
@@ -44,3 +45,21 @@ exports.getAllCount = () => {
}); });
}); });
}; };
/**
* 持久化日志
*/
exports.store = (level, err) => {
const newLog = new logModel({
_id: shortid.generate(),
level,
message: err.message || '未知错误',
meta: err,
timestamp: new Date()
});
newLog.save(err => {
if (err) {
return console.error(err);
}
});
}

View File

@@ -2,6 +2,8 @@ const postModel = require('../models/post')
.PostModel; .PostModel;
const redisClient = require('../utility/redisClient'); const redisClient = require('../utility/redisClient');
const tool = require('../utility/tool'); const tool = require('../utility/tool');
const serverlog = require('serverlog-node');
const logger = serverlog.getLogger('post');
/** /**
* 为首页数据查询构建条件对象 * 为首页数据查询构建条件对象
@@ -78,6 +80,8 @@ exports.getPosts = params => {
if (posts) { if (posts) {
redisClient.setItem(cache_key, posts, redisClient.defaultExpired); redisClient.setItem(cache_key, posts, redisClient.defaultExpired);
} }
logger.infoE('构建的查询对象:', query, '数据库返回结果:', posts)
return resolve(posts); return resolve(posts);
}); });
}, err => { }, err => {

View File

@@ -1 +1 @@
.home-loading{position:fixed;left:0;top:0;right:0;bottom:0;width:100%;height:100%;background:#f3f3f4;z-index:9999}.home-loading .loading-con{position:absolute;left:50%;top:50%;margin-left:-50px;margin-top:-60px}.home-loading .loading-con img{position:absolute;top:8px;left:8px;width:80px;height:80px;-webkit-border-radius:50%;-moz-border-radius:50%;-o-border-radius:50%;-ms-border-radius:50%;border-radius:50%}.home-loading .loading-circle{box-sizing:content-box;width:80px;height:80px;border-top:8px solid #11994b;border-right:8px solid #f2a808;border-bottom:8px solid #2399e7;border-left:8px solid #c0392b;-webkit-border-radius:50%;-moz-border-radius:50%;-o-border-radius:50%;-ms-border-radius:50%;border-radius:50%;-webkit-animation:spin 1s infinite linear;-moz-animation:spin 1s infinite linear;-o-animation:spin 1s infinite linear;-ms-animation:spin 1s infinite linear;animation:spin 1s infinite linear}.loading-con p{position:relative;left:-3px;top:5px;color:#555}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(360deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(360deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(360deg)}} .home-loading{position:fixed;left:0;top:0;right:0;bottom:0;width:100%;height:100%;background:#f3f3f4;z-index:9999}.home-loading .loading-con{position:absolute;left:50%;top:50%;margin-left:-50px;margin-top:-64px}.home-loading .loading-con img{position:absolute;top:8px;left:8px;width:80px;height:80px;-webkit-border-radius:50%;-moz-border-radius:50%;-o-border-radius:50%;-ms-border-radius:50%;border-radius:50%}.home-loading .loading-circle{box-sizing:content-box;width:80px;height:80px;border-top:8px solid #11994b;border-right:8px solid #f2a808;border-bottom:8px solid #2399e7;border-left:8px solid #c0392b;-webkit-border-radius:50%;-moz-border-radius:50%;-o-border-radius:50%;-ms-border-radius:50%;border-radius:50%;-webkit-animation:spin 1s infinite linear;-moz-animation:spin 1s infinite linear;-o-animation:spin 1s infinite linear;-ms-animation:spin 1s infinite linear;animation:spin 1s infinite linear}.loading-con p{position:relative;top:13px;color:#555;font-size:13px}@keyframes spin{0%{transform:rotate(0)}100%{transform:rotate(360deg)}}@-moz-keyframes spin{0%{-moz-transform:rotate(0)}100%{-moz-transform:rotate(360deg)}}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0)}100%{-webkit-transform:rotate(360deg)}}@-o-keyframes spin{0%{-o-transform:rotate(0)}100%{-o-transform:rotate(360deg)}}@-ms-keyframes spin{0%{-ms-transform:rotate(0)}100%{-ms-transform:rotate(360deg)}}

View File

@@ -1 +1 @@
.post-copyright{position:relative;margin-bottom:1rem;padding:.5rem .8rem;border:1px solid #eee;-webkit-transition:box-shadow .3s ease-in-out;-moz-transition:box-shadow .3s ease-in-out;-o-transition:box-shadow .3s ease-in-out;-ms-transition:box-shadow .3s ease-in-out;transition:box-shadow .3s ease-in-out}.post-copyright::before{position:absolute;top:.5rem;right:.5rem;width:.8rem;height:.8rem;border-radius:.8rem;background:#49b1f5;content:""}.hljs{border:0;font-family:Consulas,"Courier New",Courier,mono,serif;font-size:12px;background:0 0;display:block;padding:1px;margin:0;width:100%;font-weight:200;color:#333;white-space:pre-wrap}.hljs ul{list-style:none;padding:0;padding-left:0!important}.hljs ul li{list-style:none;font-family:Consulas,"Courier New",Courier,mono,serif;font-weight:200;font-size:12px;padding-left:5px!important;margin:0!important;line-height:14px;word-break:break-all;word-wrap:break-word}.hljs ul li:nth-of-type(even){color:inherit}code.hljs{background:0 0}.hljs ul{list-style-type:none;margin-left:0}.hljs ul li{counter-increment:customlistcounter}.hljs ul li:before{content:counter(customlistcounter) " ";float:left;width:3em;margin-right:10px;color:#999;border-right:3px solid #6ce26c!important}.hljs ul :first-child{counter-reset:customlistcounter} .post-copyright{position:relative;margin-bottom:1rem;padding:.5rem .8rem;border:1px solid #eee;-webkit-transition:box-shadow .3s ease-in-out;-moz-transition:box-shadow .3s ease-in-out;-o-transition:box-shadow .3s ease-in-out;-ms-transition:box-shadow .3s ease-in-out;transition:box-shadow .3s ease-in-out}.post-copyright::before{position:absolute;top:.5rem;right:.5rem;width:.8rem;height:.8rem;border-radius:.8rem;background:#49b1f5;content:""}

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 103 KiB

After

Width:  |  Height:  |  Size: 97 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 104 KiB

After

Width:  |  Height:  |  Size: 180 KiB

BIN
public/images/preview3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

View File

@@ -12,10 +12,10 @@
.home-loading .loading-con { .home-loading .loading-con {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 50%; top: 50%;
margin-left: -50px; margin-left: -50px;
margin-top: -60px; margin-top: -64px;
} }
.home-loading .loading-con img { .home-loading .loading-con img {
@@ -53,9 +53,9 @@
.loading-con p { .loading-con p {
position: relative; position: relative;
left: -3px; top: 13px;
top: 5px;
color: #555; color: #555;
font-size: 13px;
} }
@keyframes spin { @keyframes spin {

View File

@@ -19,60 +19,3 @@
background: #49b1f5; background: #49b1f5;
content: ""; content: "";
} }
.hljs {
border: 0;
font-family: "Consulas", "Courier New", Courier, mono, serif;
font-size: 12px;
background: transparent;
display: block;
padding: 1px;
margin: 0;
width: 100%;
font-weight: 200;
color: #333;
white-space: pre-wrap
}
.hljs ul {
list-style: none;
padding: 0px;
padding-left: 0em!important;
}
.hljs ul li {
list-style: none;
font-family: "Consulas", "Courier New", Courier, mono, serif;
font-weight: 200;
font-size: 12px;
padding-left: 5px!important;
margin: 0 !important;
line-height: 14px;
word-break: break-all;
word-wrap: break-word;
}
.hljs ul li:nth-of-type(even) {
color: inherit;
}
code.hljs{
background: transparent;
}
.hljs ul {
list-style-type: none;
margin-left: 0;
}
.hljs ul li {
counter-increment: customlistcounter;
}
.hljs ul li:before {
content: counter(customlistcounter) " ";
/*font-weight: bold;*/
float: left;
width: 3em;
margin-right: 10px;
color: #999;
border-right: 3px solid #6ce26c !important;
}
.hljs ul :first-child {
counter-reset: customlistcounter;
}

View File

@@ -14,11 +14,11 @@ html, body {
body { body {
font-family: -apple-system, BlinkMacSystemFont, "PingFang SC","Helvetica Neue",STHeiti,"Microsoft Yahei",Tahoma,Simsun,sans-serif; font-family: -apple-system, BlinkMacSystemFont, "PingFang SC","Helvetica Neue",STHeiti,"Microsoft Yahei",Tahoma,Simsun,sans-serif;
font-size: 14px; font-size: 14px;
display: none; transition: opacity .3s;
} }
body.shown { body.shown {
display: block; opacity: 1;
} }
body.mCustomScrollbar .mCSB_scrollTools .mCSB_draggerContainer { body.mCustomScrollbar .mCSB_scrollTools .mCSB_draggerContainer {

View File

@@ -1,4 +0,0 @@
//代码高亮自定义
$("code").each(function(){
$(this).html("<ul><li>" + $(this).html().replace(/\n/g,"\n</li><li>") +"\n</li></ul>");
});

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@@ -5,7 +5,9 @@ const path = require('path');
const passport = require('passport'); const passport = require('passport');
const Strategy = require('passport-local') const Strategy = require('passport-local')
.Strategy; .Strategy;
const logger = require('../utility/logger'); const serverlog = require('serverlog-node');
const logger = serverlog.getLogger('auth');
const log = require('../proxy/log');
passport.use(new Strategy({ passport.use(new Strategy({
// 页面上的用户名字段的name属性值 // 页面上的用户名字段的name属性值
@@ -57,7 +59,8 @@ router.post('/login', (req, res, next) => {
if (err) { if (err) {
next(err); next(err);
} else if (!user) { } else if (!user) {
logger.errLogger(new Error(res.__('auth.wrong_info')), req); log.store('Error', new Error(res.__('auth.wrong_info')));
logger.error('尝试登录出错!');
res.json({ res.json({
valid: false, valid: false,
message: res.__('auth.wrong_info') message: res.__('auth.wrong_info')

View File

@@ -153,7 +153,7 @@ router.get('/:category/:article', (req, res, next) => {
res.redirect(util.format('/blog/%s/%s', trueCateAlias, alias)); res.redirect(util.format('/blog/%s/%s', trueCateAlias, alias));
} }
const labels = article.Labels; let labels = article.Labels;
const labelList = []; const labelList = [];
if (labels) { if (labels) {
labels = JSON.parse(labels); labels = JSON.parse(labels);

32
sw.js
View File

@@ -43,7 +43,7 @@ if (workbox) {
}, },
{ {
"url": "/static/dist/css/home-loading.css", "url": "/static/dist/css/home-loading.css",
"revision": "0040777e852deb1657e343e5a483a672" "revision": "d8d57135f44a3ca78e3b0b945a5d99bf"
}, },
{ {
"url": "/static/dist/css/icon-font.css", "url": "/static/dist/css/icon-font.css",
@@ -55,7 +55,7 @@ if (workbox) {
}, },
{ {
"url": "/static/dist/css/posts_style_custom.css", "url": "/static/dist/css/posts_style_custom.css",
"revision": "c1873b2be213829f17c7869ba875c797" "revision": "e0cc4825c1e0787844c849596cc2c581"
}, },
{ {
"url": "/static/dist/css/selectlist.css", "url": "/static/dist/css/selectlist.css",
@@ -67,7 +67,7 @@ if (workbox) {
}, },
{ {
"url": "/static/dist/css/site.css", "url": "/static/dist/css/site.css",
"revision": "68283ca50b966c109182c7edb5a90af8" "revision": "b9af29af14ca66646db81b4924d72ec5"
}, },
{ {
"url": "/static/dist/js/about.js", "url": "/static/dist/js/about.js",
@@ -171,11 +171,15 @@ if (workbox) {
}, },
{ {
"url": "/static/images/preview1.png", "url": "/static/images/preview1.png",
"revision": "621700a2a57bbe582a936990810223fa" "revision": "3a69a936b49612c2d7094c03dac4fc5f"
}, },
{ {
"url": "/static/images/preview2.png", "url": "/static/images/preview2.png",
"revision": "e668889e93d0193946e6bc163a1edeb2" "revision": "2fb815f85212a5d3a952baea77c57d56"
},
{
"url": "/static/images/preview3.png",
"revision": "2649fa08b9721e2a7352a819ec933da1"
}, },
{ {
"url": "/static/images/s1.jpg", "url": "/static/images/s1.jpg",
@@ -235,7 +239,7 @@ if (workbox) {
}, },
{ {
"url": "/static/src/css/home-loading.css", "url": "/static/src/css/home-loading.css",
"revision": "f07362ac7a8e5a35108b34761c23330e" "revision": "b65e14aca9079b322da083198c33b590"
}, },
{ {
"url": "/static/src/css/icon-font.css", "url": "/static/src/css/icon-font.css",
@@ -247,7 +251,7 @@ if (workbox) {
}, },
{ {
"url": "/static/src/css/posts_style_custom.css", "url": "/static/src/css/posts_style_custom.css",
"revision": "22211a68383fcc12c4a25b5d25e17c4a" "revision": "f90dd10040b94d222d315af5e1814725"
}, },
{ {
"url": "/static/src/css/selectlist.css", "url": "/static/src/css/selectlist.css",
@@ -259,7 +263,7 @@ if (workbox) {
}, },
{ {
"url": "/static/src/css/site.css", "url": "/static/src/css/site.css",
"revision": "a7b643d0c7e0befb1101674480bce4ef" "revision": "d867e43098e168aa47d70cc2fcb211f1"
}, },
{ {
"url": "/static/src/js/about.js", "url": "/static/src/js/about.js",
@@ -313,10 +317,6 @@ if (workbox) {
"url": "/static/src/js/guestbook.js", "url": "/static/src/js/guestbook.js",
"revision": "c5440a16034df3ae132aa391cc5e5c92" "revision": "c5440a16034df3ae132aa391cc5e5c92"
}, },
{
"url": "/static/src/js/highlight_line_number.js",
"revision": "46e28b74d69247b91c80b056398aa0f0"
},
{ {
"url": "/static/src/js/index.js", "url": "/static/src/js/index.js",
"revision": "94c5e685de18bbd298e0ee5fd6063c12" "revision": "94c5e685de18bbd298e0ee5fd6063c12"
@@ -349,6 +349,14 @@ if (workbox) {
"url": "/static/uploads/415gQEpsx/img/zhr_VJH5Q4asx.jpg", "url": "/static/uploads/415gQEpsx/img/zhr_VJH5Q4asx.jpg",
"revision": "cc21e17dd614e359b6223f0dea7d482c" "revision": "cc21e17dd614e359b6223f0dea7d482c"
}, },
{
"url": "/static/uploads/QtcjVQ8GpE/img/品牌馆@3x_ChIGWeJkLb.png",
"revision": "c513d36d407f28668c8bf0d4126381ef"
},
{
"url": "/static/uploads/zQy02fdv4/img/prev_en_Nl4FDClFym.png",
"revision": "bb55cd09f52293a8aad365f0b4eb6c36"
},
{ {
"url": "/static/ZeroClipboard.swf", "url": "/static/ZeroClipboard.swf",
"revision": "a573941f02f4331f81046356ebb667eb" "revision": "a573941f02f4331f81046356ebb667eb"

View File

@@ -1,50 +0,0 @@
const winston = require('winston');
const dbPath = require('../config.json')
.mongoUrl;
const os = require('os');
require('winston-mongodb')
.MongoDB;
const logger = new winston.Logger({
transports: [
new (winston.transports.Console)({
colorize: true
}),
new (winston.transports.MongoDB)({
db: dbPath,
level: 'warn',
})
],
exitOnError: false
});
logger.errLogger = function (err, req) {
let obj = {},
message = err.message;
obj.process = {
pid: process.pid,
uid: process.getuid ? process.getuid() : null
};
obj.os = {
hostname: os.hostname()
};
obj.stack = err.stack && err.stack.split('\n');
obj.code = err.status || 500;
if (req) {
const query = {};
for (const q in req.query) {
query[q] = req.query[q];
}
obj.req = {
baseUrl: req.baseUrl,
originalUrl: req.originalUrl,
query,
body: req.body,
ip: req.ip,
route: req.route
};
}
logger.error(message, obj);
};
module.exports = logger;

View File

@@ -94,7 +94,6 @@ block content
script(type='text/javascript', src='/nodeModules/scrollnav/dist/jquery.scrollNav.min.js', charset='utf-8') script(type='text/javascript', src='/nodeModules/scrollnav/dist/jquery.scrollNav.min.js', charset='utf-8')
script(type='text/javascript', src='https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js', charset='utf-8') script(type='text/javascript', src='https://cdn.bootcss.com/highlight.js/9.12.0/highlight.min.js', charset='utf-8')
script(type='text/javascript', src=`${staticPrefix}/js/article.js`, charset='utf-8') script(type='text/javascript', src=`${staticPrefix}/js/article.js`, charset='utf-8')
script(type='text/javascript', src=`${staticPrefix}/js/highlight_line_number.js`, charset='utf-8')
script. script.
var expandMenu = '#{settings.ExpandMenu}'; var expandMenu = '#{settings.ExpandMenu}';
var logoPath = "#{settings.LogoPath}"; var logoPath = "#{settings.LogoPath}";

View File

@@ -29,6 +29,5 @@ p(style="max-width: 100%; min-height: 1em; color: rgb(62, 62, 62); font-size: 14
script. script.
url=window.location.href url=window.location.href
console.log(url)
document.getElementById("declaration_url").innerHTML=url; document.getElementById("declaration_url").innerHTML=url;
document.getElementById("declaration_url").href=url; document.getElementById("declaration_url").href=url;

View File

@@ -13,6 +13,10 @@ html(lang='zh-CN')
link(href='/nodeModules/@fortawesome/fontawesome-free/css/all.min.css', rel='stylesheet') link(href='/nodeModules/@fortawesome/fontawesome-free/css/all.min.css', rel='stylesheet')
link(href=`${staticPrefix}/css/share.css`, rel='stylesheet') link(href=`${staticPrefix}/css/share.css`, rel='stylesheet')
link(href=`${staticPrefix}/css/animate-custom.css`, rel='stylesheet') link(href=`${staticPrefix}/css/animate-custom.css`, rel='stylesheet')
style.
body {
opacity: 0;
}
title=title title=title
body.fuelux body.fuelux
#home-loading.home-loading(style='display: none;') #home-loading.home-loading(style='display: none;')