重构框架,增加比赛功能

This commit is contained in:
masnn committed 2020-04-11 20:37:47 +08:00
1 parent 0e590ebe0d
commit 9bf3343a64
54 files changed
+1196 -868

No files matched your search

+2 -2
View File
@@ -10,12 +10,12 @@ String.prototype.format = function (args) {
if (arguments.length == 1 && typeof (args) == 'object') {
for (var key in args)
if (args[key] != undefined) {
let reg = new RegExp('({' + key + '})', 'g');
let reg = new RegExp('(\\{' + key + '\\})', 'g');
result = result.replace(reg, args[key]);
}
} else for (var i = 0; i < arguments.length; i++)
if (arguments[i] != undefined) {
let reg = new RegExp('({)' + i + '(})', 'g');
let reg = new RegExp('(\\{)' + i + '(\\})', 'g');
result = result.replace(reg, arguments[i]);
}
}
+22
View File
@@ -0,0 +1,22 @@
const
hljs = require('highlight.js'),
MarkdownIt = require('markdown-it'),
katex = require('markdown-it-katex');
class Markdown extends MarkdownIt {
constructor() {
super({
linkify: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang))
try {
return hljs.highlight(lang, str).value;
} catch (__) { } // eslint-disable-line no-empty
return '';
}
});
this.linkify.tlds('.py', false);
this.use(katex);
}
}
module.exports = new Markdown();
+41
View File
@@ -0,0 +1,41 @@
const
path = require('path'),
nunjucks = require('nunjucks'),
markdown = require('./markdown'),
options = require('../options'),
perm = require('../permission'),
builtin = require('../model/builtin'),
model = require('../model'),
misc = require('../lib/misc');
class Nunjucks extends nunjucks.Environment {
constructor() {
super(
new nunjucks.FileSystemLoader(path.resolve(options.template.path)),
{ autoescape: true, trimBlocks: true }
);
this.addFilter('json', function (self) {
return JSON.stringify(self);
}, false);
this.addFilter('assign', function (self, data) {
return Object.assign(self, data);
});
this.addFilter('markdown', function (self) {
return markdown.render(self);
});
this.addFilter('gravatar_url', misc.gravatar_url);
this.addFilter('format_size', misc.format_size);
this.addGlobal('typeof', o => typeof o);
this.addGlobal('console', console);
this.addGlobal('static_url', str => `/${str}`);
this.addGlobal('reverse_url', str => str);
this.addGlobal('datetime_span', misc.datetime_span);
this.addGlobal('paginate', misc.paginate);
this.addGlobal('perm', perm);
this.addGlobal('status', builtin.STATUS);
this.addGlobal('model', model);
}
}
let env = new Nunjucks();
module.exports = env;