Browse Source

Show latest updates in main page

master
hewenyang 7 years ago
parent
commit
4d68579806
  1. 7
      libs/timeago/index.js
  2. 53
      libs/timeago/long.json
  3. 53
      libs/timeago/narrow.json
  4. 53
      libs/timeago/short.json
  5. 15
      models/problem.js
  6. 17
      modules/index.js
  7. 1
      package.json
  8. 21
      views/index.ejs

7
libs/timeago/index.js

@ -0,0 +1,7 @@
module.exports =
{
locale: 'zh',
long: require('./long.json'),
short: require('./short.json'),
narrow: require('./narrow.json')
}

53
libs/timeago/long.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒钟前",
"future": "{0} 秒钟后"
},
"now": "现在"
}

53
libs/timeago/narrow.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒前",
"future": "{0} 秒后"
},
"now": "现在"
}

53
libs/timeago/short.json

@ -0,0 +1,53 @@
{
"year": {
"previous": "去年",
"current": "今年",
"next": "明年",
"past": "{0} 年前",
"future": "{0} 年后"
},
"quarter": {
"previous": "上季度",
"current": "本季度",
"next": "下季度",
"past": "{0} 个季度前",
"future": "{0} 个季度后"
},
"month": {
"previous": "上个月",
"current": "本月",
"next": "下个月",
"past": "{0} 个月前",
"future": "{0} 个月后"
},
"week": {
"previous": "上周",
"current": "本周",
"next": "下周",
"past": "{0} 周前",
"future": "{0} 周后"
},
"day": {
"previous": "昨天",
"current": "今天",
"next": "明天",
"past": "{0} 天前",
"future": "{0} 天后"
},
"hour": {
"current": "这一时间 / 此时",
"past": "{0} 小时前",
"future": "{0} 小时后"
},
"minute": {
"current": "此刻",
"past": "{0} 分钟前",
"future": "{0} 分钟后"
},
"second": {
"current": "现在",
"past": "{0} 秒前",
"future": "{0} 秒后"
},
"now": "现在"
}

15
models/problem.js

@ -244,12 +244,17 @@ let model = db.define('problem', {
file_io_input_name: { type: Sequelize.TEXT }, file_io_input_name: { type: Sequelize.TEXT },
file_io_output_name: { type: Sequelize.TEXT }, file_io_output_name: { type: Sequelize.TEXT },
create_time: { type: Sequelize.DATE },
last_update: { type: Sequelize.DATE },
type: { type: {
type: Sequelize.ENUM, type: Sequelize.ENUM,
values: ['traditional', 'submit-answer', 'interaction'] values: ['traditional', 'submit-answer', 'interaction']
} }
}, { }, {
timestamps: false, timestamps: true,
createdAt: 'create_time',
updatedAt: 'last_update',
tableName: 'problem', tableName: 'problem',
indexes: [ indexes: [
{ {
@ -257,7 +262,13 @@ let model = db.define('problem', {
}, },
{ {
fields: ['user_id'], fields: ['user_id'],
} },
{
fields: ['create_time'],
},
{
fields: ['last_update'],
},
] ]
}); });

17
modules/index.js

@ -22,7 +22,12 @@
let User = syzoj.model('user'); let User = syzoj.model('user');
let Article = syzoj.model('article'); let Article = syzoj.model('article');
let Contest = syzoj.model('contest'); let Contest = syzoj.model('contest');
let Problem = syzoj.model('problem');
let Divine = require('syzoj-divine'); let Divine = require('syzoj-divine');
let TimeAgo = require('javascript-time-ago');
let zh = require('../libs/timeago');
TimeAgo.locale(zh);
const timeAgo = new TimeAgo('zh-CN');
app.get('/', async (req, res) => { app.get('/', async (req, res) => {
try { try {
@ -40,16 +45,20 @@ app.get('/', async (req, res) => {
fortune = Divine(res.locals.user.username, res.locals.user.sex); fortune = Divine(res.locals.user.username, res.locals.user.sex);
} }
let where; let contests = await Contest.query([1, 5], { is_public: true }, [['start_time', 'desc']]);
if (res.locals.user && await res.locals.user.is_admin) where = {}
else where = { is_public: true }; let problems = (await Problem.query([1, 5], { is_public: true }, [['last_update', 'desc']])).map(problem => ({
let contests = await Contest.query([1, 5], where, [['start_time', 'desc']]); id: problem.id,
title: problem.title,
time: timeAgo.format(new Date(problem.last_update)),
}));
res.render('index', { res.render('index', {
ranklist: ranklist, ranklist: ranklist,
notices: notices, notices: notices,
fortune: fortune, fortune: fortune,
contests: contests, contests: contests,
problems: problems,
links: syzoj.config.links links: syzoj.config.links
}); });
} catch (e) { } catch (e) {

1
package.json

@ -38,6 +38,7 @@
"file-size": "^1.0.0", "file-size": "^1.0.0",
"fs-extra": "^4.0.1", "fs-extra": "^4.0.1",
"gravatar": "^1.5.2", "gravatar": "^1.5.2",
"javascript-time-ago": "^1.0.30",
"js-yaml": "^3.9.0", "js-yaml": "^3.9.0",
"jsonwebtoken": "^7.4.3", "jsonwebtoken": "^7.4.3",
"moemark-renderer": "^1.2.6", "moemark-renderer": "^1.2.6",

21
views/index.ejs

@ -92,6 +92,27 @@
<div style="font-size: 1em; line-height: 1.5em; display: none; " id="hitokoto-content"></div> <div style="font-size: 1em; line-height: 1.5em; display: none; " id="hitokoto-content"></div>
<div style="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; display: none; " id="hitokoto-from"></div> <div style="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; display: none; " id="hitokoto-from"></div>
</div> </div>
<h4 class="ui top attached block header">最新更新</h4>
<div class="ui bottom attached segment">
<table class="ui very basic center aligned table">
<thead>
<tr>
<th>题目</th>
<th>更新时间</th>
</tr>
</thead>
<tbody>
<%
for (let problem of problems) {
%>
<tr>
<td><a href="<%= syzoj.utils.makeUrl(['problem', problem.id]) %>"><%= problem.title %></a></td>
<td><%= problem.time %></td>
</tr>
<% } %>
</tbody>
</table>
</div>
<% <%
if (fortune) { if (fortune) {
let color; let color;

Loading…
Cancel
Save