Browse Source

Show latest updates in main page

pull/6/head
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_output_name: { type: Sequelize.TEXT },
create_time: { type: Sequelize.DATE },
last_update: { type: Sequelize.DATE },
type: {
type: Sequelize.ENUM,
values: ['traditional', 'submit-answer', 'interaction']
}
}, {
timestamps: false,
timestamps: true,
createdAt: 'create_time',
updatedAt: 'last_update',
tableName: 'problem',
indexes: [
{
@ -257,7 +262,13 @@ let model = db.define('problem', {
},
{
fields: ['user_id'],
}
},
{
fields: ['create_time'],
},
{
fields: ['last_update'],
},
]
});

17
modules/index.js

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

1
package.json

@ -38,6 +38,7 @@
"file-size": "^1.0.0",
"fs-extra": "^4.0.1",
"gravatar": "^1.5.2",
"javascript-time-ago": "^1.0.30",
"js-yaml": "^3.9.0",
"jsonwebtoken": "^7.4.3",
"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="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; display: none; " id="hitokoto-from"></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) {
let color;

Loading…
Cancel
Save