mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: drop array-style problem content (#882)
This commit is contained in:
1 parent
23dfcbeeae
commit
6ae902d3ca
9 files changed
+120
-180
No files matched your search
@@ -1,8 +1,7 @@
|
||||
import * as status from '@hydrooj/utils/lib/status';
|
||||
import { findFileSync } from '@hydrooj/utils/lib/utils';
|
||||
import {
|
||||
avatar, buildContent, Context,
|
||||
fs, PERM, PRIV, STATUS, yaml,
|
||||
avatar, Context, fs, PERM, PRIV, STATUS, yaml,
|
||||
} from 'hydrooj';
|
||||
import jsesc from 'jsesc';
|
||||
import nunjucks from 'nunjucks';
|
||||
@@ -86,14 +85,13 @@ class Nunjucks extends nunjucks.Environment {
|
||||
} catch {
|
||||
s = content;
|
||||
}
|
||||
if (typeof s === 'object' && !(s instanceof Array)) {
|
||||
if (typeof s === 'object') {
|
||||
const langs = Object.keys(s);
|
||||
const f = langs.filter((i) => i.startsWith(language));
|
||||
if (s[language]) s = s[language];
|
||||
else if (f.length) s = s[f[0]];
|
||||
else s = s[langs[0]];
|
||||
}
|
||||
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) => {
|
||||
@@ -103,9 +101,7 @@ class Nunjucks extends nunjucks.Environment {
|
||||
} catch {
|
||||
s = content;
|
||||
}
|
||||
if (typeof s === 'object' && !(s instanceof Array)) {
|
||||
return Object.keys(s);
|
||||
}
|
||||
if (typeof s === 'object') return Object.keys(s);
|
||||
return [];
|
||||
});
|
||||
this.addFilter('log', (self) => {
|
||||
|
||||
Reference in new issue
Block a user