From 29fbb08b4b034f7c2a55721da691a8c81c1adb51 Mon Sep 17 00:00:00 2001 From: panda Date: Sat, 19 Mar 2022 15:58:37 +0800 Subject: [PATCH] ui: Add problem_detail lang tab (#319) --- packages/ui-default/backendlib/template.js | 12 +++++++++++ .../ui-default/pages/problem_detail.page.styl | 20 +++++++++++++++++++ .../ui-default/templates/problem_detail.html | 15 +++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 packages/ui-default/pages/problem_detail.page.styl diff --git a/packages/ui-default/backendlib/template.js b/packages/ui-default/backendlib/template.js index 07faee7f3..6c97c61b9 100644 --- a/packages/ui-default/backendlib/template.js +++ b/packages/ui-default/backendlib/template.js @@ -96,6 +96,18 @@ class Nunjucks extends nunjucks.Environment { if (s instanceof Array) s = buildContent(s, html ? 'html' : 'markdown', (str) => str.translate(language)); return ensureTag(html ? xss.process(s) : markdown.render(s)); }); + this.addFilter('contentLang', (content) => { + let s = ''; + try { + s = JSON.parse(content); + } catch { + s = content; + } + if (typeof s === 'object' && !(s instanceof Array)) { + return Object.keys(s); + } + return []; + }); this.addFilter('log', (self) => { console.log(self); return self; diff --git a/packages/ui-default/pages/problem_detail.page.styl b/packages/ui-default/pages/problem_detail.page.styl new file mode 100644 index 000000000..814020d97 --- /dev/null +++ b/packages/ui-default/pages/problem_detail.page.styl @@ -0,0 +1,20 @@ +.page--problem_detail + .section__tab-header + padding-top: 0; + + .section__tab-container + .section__body + padding-top: 0 + + .section__tab-header-item + border-top: 3px solid transparent; + transition: border-color 0.2s, background 0.2s, color 0.2s; + transition-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1); + margin-right: 0; + color: #182026 !important; + + &:hover + border-color: #5f9fd6; + background: #f8f8f8; + + &.tab--active + border-color: #ed5f82; \ No newline at end of file diff --git a/packages/ui-default/templates/problem_detail.html b/packages/ui-default/templates/problem_detail.html index f3aa33e11..126aa8b89 100644 --- a/packages/ui-default/templates/problem_detail.html +++ b/packages/ui-default/templates/problem_detail.html @@ -75,6 +75,19 @@

{{ pdoc.title }}

+ {% if pdoc.content|contentLang %} +
+
+ +
+
+ {% endif %}
{% if not pdoc.data.length and not pdoc.reference %}
@@ -91,7 +104,7 @@

{{ _('You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.') }}

{% endif %} - {{ pdoc.content|content(handler.user.viewLang or handler.session.viewLang, pdoc.html)|safe }} + {{ pdoc.content|content(handler.request.query.lang or handler.user.viewLang or handler.session.viewLang, pdoc.html)|safe }}