diff --git a/config-example.json b/config-example.json index b39106d..b7c4ffc 100644 --- a/config-example.json +++ b/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" } diff --git a/models/article.js b/models/article.js index 898ce41..03b65f5 100644 --- a/models/article.js +++ b/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))); } diff --git a/modules/discussion.js b/modules/discussion.js index 6756b9a..4296dd3 100644 --- a/modules/discussion.js +++ b/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(); diff --git a/modules/index.js b/modules/index.js index 770b295..388aed0 100644 --- a/modules/index.js +++ b/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) { diff --git a/static/style.css b/static/style.css index 944b0c5..adfb0bd 100644 --- a/static/style.css +++ b/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 */ /* diff --git a/utility.js b/utility.js index 6e24d16..c72a8ec 100644 --- a/utility.js +++ b/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 }); diff --git a/views/article.ejs b/views/article.ejs index af68cda..3083dc7 100644 --- a/views/article.ejs +++ b/views/article.ejs @@ -1,17 +1,36 @@ <% this.title = article.title + ' - 帖子'; %> <% include header %>

<%= article.title %>

<%= article.user.username %><% if (article.user.nameplate) { %><%- article.user.nameplate %><% } %> 于 <%= syzoj.utils.formatDate(article.public_time) %> 发表,<%= syzoj.utils.formatDate(article.update_time) %> 最后更新 <% if (article.allowedEdit) { %> - 删除文章 + 删除文章 编辑文章 +

<% } %>

@@ -32,7 +51,26 @@
<%- comment.content %>
<% if (comment.allowedEdit) { %> -
删除
+
删除
+ <% } %>
diff --git a/views/article_edit.ejs b/views/article_edit.ejs index 88b7e82..d696d24 100644 --- a/views/article_edit.ejs +++ b/views/article_edit.ejs @@ -17,6 +17,13 @@ + <% if (user && user.is_admin) { %> +
+ checked=""<% } %> name="is_notice" type="checkbox"> + +

选择后将显示在首页公告栏。

+
+ <% } %>
diff --git a/views/index.ejs b/views/index.ejs index 8a31305..fbcff94 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -80,7 +80,7 @@

一言(ヒトコト)

<%= hitokoto.hitokoto %>
- <% if (hitokoto.source) { %>
——<%= hitokoto.source %>
<% } %> + <% if (hitokoto.from) { %>
——<%= hitokoto.from %>
<% } %>
<% } %> <% @@ -182,14 +182,6 @@ <% } %>
-

信息栏

-
- <% if (!syzoj.config.announcement) { %> - 无任何信息 - <% } else { %> -

<%- syzoj.config.announcement %>

- <% } %> -
<% if (typeof links !== 'undefined' && links) { %>

友情链接

diff --git a/views/problem_data.ejs b/views/problem_data.ejs index c5f4c98..5ac4d87 100644 --- a/views/problem_data.ejs +++ b/views/problem_data.ejs @@ -35,11 +35,6 @@ function getIcon(filename) { } %> <% include header %> -