Browse Source

Add notice manage; fix hitokoto

pull/6/head
Menci 7 years ago
parent
commit
04357a930a
  1. 14
      config-example.json
  2. 6
      models/article.js
  3. 1
      modules/discussion.js
  4. 17
      modules/index.js
  5. 4
      static/style.css
  6. 5
      utility.js
  7. 48
      views/article.ejs
  8. 7
      views/article_edit.ejs
  9. 10
      views/index.ejs
  10. 5
      views/problem_data.ejs

14
config-example.json

@ -142,26 +142,12 @@
"editor": "vbscript"
}
},
"notices": [
{
"type": "// article",
"id": 1,
"comment": "Specify the id if you want to show a article"
},
{
"type": "// link",
"url": "",
"date": "",
"comment": "Specify the url and date if you want to show any link"
}
],
"links": [
{
"title": "LibreOJ",
"url": "https://loj.ac/"
}
],
"announcement": "Here is the announcement",
"session_secret": "233",
"judge_token": "233"
}

6
models/article.js

@ -38,6 +38,8 @@ let model = db.define('article', {
comments_num: { type: Sequelize.INTEGER },
allow_comment: { type: Sequelize.BOOLEAN },
is_notice: { type: Sequelize.BOOLEAN }
}, {
timestamps: false,
tableName: 'article',
@ -65,7 +67,9 @@ class Article extends Model {
sort_time: 0,
comments_num: 0,
allow_comment: true
allow_comment: true,
is_notice: false
}, val)));
}

1
modules/discussion.js

@ -124,6 +124,7 @@ app.post('/article/:id/edit', async (req, res) => {
article.title = req.body.title;
article.content = req.body.content;
article.update_time = time;
article.is_notice = res.locals.user && res.locals.user.is_admin && req.body.is_notice === 'on';
await article.save();

17
modules/index.js

@ -29,18 +29,11 @@ app.get('/', async (req, res) => {
let ranklist = await User.query([1, 10], { is_show: true }, [['ac_num', 'desc']]);
await ranklist.forEachAsync(async x => x.renderInformation());
let notices = await syzoj.config.notices.mapAsync(async notice => {
if (notice.type === 'link') return notice;
else if (notice.type === 'article') {
let article = await Article.fromID(notice.id);
if (!article) throw new ErrorMessage(`无此帖子:${notice.id}`);
return {
title: article.title,
url: syzoj.utils.makeUrl(['article', article.id]),
date: syzoj.utils.formatDate(article.public_time, 'L')
};
}
});
let notices = (await Article.query(null, { is_notice: true }, [['public_time', 'desc']])).map(article => ({
title: article.title,
url: syzoj.utils.makeUrl(['article', article.id]),
date: syzoj.utils.formatDate(article.public_time, 'L')
}));
let fortune = null;
if (res.locals.user) {

4
static/style.css

@ -349,6 +349,10 @@ table.center.aligned ul, table.center.aligned ol {
text-align: left;
}
body > .ui.page.dimmer {
position: fixed !important;
}
/* status color */
/*

5
utility.js

@ -315,11 +315,10 @@ module.exports = {
try {
let request = require('request-promise');
let res = await request({
uri: 'http://api.hitokoto.us/rand',
uri: 'https://sslapi.hitokoto.cn',
timeout: 1500,
qs: {
encode: 'json',
cat: 'a'
c: 'a'
},
json: true
});

48
views/article.ejs

@ -1,17 +1,36 @@
<% this.title = article.title + ' - 帖子'; %>
<% include header %>
<style type="text/css" xmlns:style="http://www.w3.org/1999/xhtml">
.small{
font-size: 0.7em;
}
.small{
font-size: 0.7em;
}
</style>
<div class="padding">
<h1><%= article.title %></h1>
<p style="font_size: 0.7em"><img style="vertical-align: middle;" src="<%= syzoj.utils.gravatar(article.user.email, 64) %>" width="32" height="32">
<a href="<%= syzoj.utils.makeUrl(['user', article.user_id]) %>"><%= article.user.username %></a><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %> 于 <%= syzoj.utils.formatDate(article.public_time) %> 发表,<%= syzoj.utils.formatDate(article.update_time) %> 最后更新
<% if (article.allowedEdit) { %>
<a class="ui mini red button" href="<%= syzoj.utils.makeUrl(['article', article.id, 'delete']) %>">删除文章</a>
<a class="ui mini red button" onclick="$('#modal-delete').modal('show')">删除文章</a>
<a class="ui mini button" href="<%= syzoj.utils.makeUrl(['article', article.id, 'edit']) %>">编辑文章</a>
<div class="ui basic modal" id="modal-delete">
<div class="ui icon header">
<i class="trash icon"></i>
<p style="margin-top: 15px; ">删除文章</p>
</div>
<div class="content" style="text-align: center; ">
<p>确认删除这篇文章吗?</p>
</div>
<div class="actions">
<div class="ui red basic cancel inverted button">
<i class="remove icon"></i>
</div>
<a class="ui green ok inverted button" href="<%= syzoj.utils.makeUrl(['article', article.id, 'delete']) %>">
<i class="checkmark icon"></i>
</a>
</div>
</div>
<% } %>
</p>
<div class="ui existing segment">
@ -32,7 +51,26 @@
</div>
<div class="text font-content"><%- comment.content %></div>
<% if (comment.allowedEdit) { %>
<div class="actions"><a href="<%= syzoj.utils.makeUrl(['article', article.id, 'comment', comment.id, 'delete']) %>">删除</a></div>
<div class="actions"><a onclick="$('#modal-delete-<%= comment.id %>').modal('show')">删除</a></div>
<div class="ui basic modal" id="modal-delete-<%= comment.id %>">
<div class="ui icon header">
<i class="trash icon"></i>
<p style="margin-top: 15px; ">删除评论</p>
</div>
<div class="content" style="text-align: center; ">
<p>确认删除这条评论吗?</p>
</div>
<div class="actions">
<div class="ui red basic cancel inverted button">
<i class="remove icon"></i>
</div>
<a class="ui green ok inverted button" href="<%= syzoj.utils.makeUrl(['article', article.id, 'comment', comment.id, 'delete']) %>">
<i class="checkmark icon"></i>
</a>
</div>
</div>
<% } %>
</div>
</div>

7
views/article_edit.ejs

@ -17,6 +17,13 @@
<input type="text" id="title" name="title" value="<%= article.title %>">
<label for="content">内容</label>
<textarea rows="15" id="content" name="content" class="font-content"><%= article.content %></textarea>
<% if (user && user.is_admin) { %>
<div class="ui <% if (article.is_notice) { %>checked <% } %>checkbox" style="margin-top: 15px; ">
<input <% if (article.is_notice) { %>checked=""<% } %> name="is_notice" type="checkbox">
<label><strong>公告</strong></label>
<p style="margin-top: 5px; ">选择后将显示在首页公告栏。</p>
</div>
<% } %>
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="preview">

10
views/index.ejs

@ -80,7 +80,7 @@
<h4 class="ui top attached block header">一言(ヒトコト)</h4>
<div class="ui bottom attached center aligned segment">
<div style="font-size: 1em; line-height: 1.5em; "><%= hitokoto.hitokoto %></div>
<% if (hitokoto.source) { %><div style="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; ">——<%= hitokoto.source %></div><% } %>
<% if (hitokoto.from) { %><div style="text-align: right; margin-top: 15px; font-size: 0.9em; color: #666; ">——<%= hitokoto.from %></div><% } %>
</div>
<% } %>
<%
@ -182,14 +182,6 @@
</table>
<% } %>
</div>
<h4 class="ui top attached block header font-content">信息栏</h4>
<div class="ui bottom attached <% if (!syzoj.config.announcement) { %>center aligned <% } %>segment">
<% if (!syzoj.config.announcement) { %>
无任何信息
<% } else { %>
<p><%- syzoj.config.announcement %></p>
<% } %>
</div>
<% if (typeof links !== 'undefined' && links) { %>
<h4 class="ui top attached block header font-content">友情链接</h4>
<div class="ui bottom attached segment">

5
views/problem_data.ejs

@ -35,11 +35,6 @@ function getIcon(filename) {
}
%>
<% include header %>
<style>
.ui.page.dimmer {
position: fixed;
}
</style>
<div class="padding">
<div class="ui grid">
<div class="seven wide column">

Loading…
Cancel
Save