修复一些小错误

This commit is contained in:
masnn committed 2020-05-13 13:02:49 +08:00
1 parent 8cd84f29e8
commit a596231a06
15 files changed
+125 -124

No files matched your search

+24 -14
View File
@@ -1,16 +1,26 @@
global.Hydro.lib.html2md = module.exports = function html2md(str) {
const RE_IMG = /<img.*?src="(.*?)".*?>(.*?)<\/img>/i;
const RE_A = /<a.*?href="(.*?)".*?>(.*?)<\/a>/i;
const RE_BLOCKQUOTE = /<blockquote.*?>(.*?)<\/blockquote>/i;
function replacer(RE, cb) { // eslint-disable-line no-unused-vars
// eslint-disable-next-line no-eval
return eval(`(substr)=>{
const s = RE.exec(substr);
return cb(s);
}`);
}
function html2md(str) {
return str.replace(/<p>/gmi, '').replace(/<\/p>/gmi, ' ')
.replace(/<h1>/gmi, '# ')
.replace(/<h2>/gmi, '## ')
.replace(/<h3>/gmi, '### ')
.replace(/<h4>/gmi, '#### ')
.replace(/<h5>/gmi, '##### ')
.replace(/<h6>/gmi, '###### ')
.replace(/<\/?code>/, '\n```\n')
.replace(/<img.*?src=".*?".*?>.*?<\/img>/gmi, (substr) => {
const RE_IMG = /<img.*?src="(.*?)".*?>(.*?)<\/img>/i;
const res = RE_IMG.exec(substr);
return `[${res[2]}](${res[1]})`;
.replace(/<h[1-6]>/gmi, (substr) => {
const s = /<h[1-6]>/i.exec(substr);
return `${'#'.repeat(parseInt(s[1]))} `;
})
.replace(/<\/h[0-6]>/, '\n');
};
.replace(/<\/h[0-6]>/, '\n')
.replace(/<\/?code>/, '\n```\n')
.replace(/<img.*?src=".*?".*?>.*?<\/img>/gmi, replacer(RE_IMG, (s) => `![${s[2]}](${s[1]})`))
.replace(/<a.*?href=".*?".*?>.*?<\/a>/gmi, replacer(RE_A, (s) => `[${s[2]}](${s[1]})`))
.replace(/<blockquote.*?>.*?<\/blockquote>/gmi, replacer(RE_BLOCKQUOTE, (s) => `> ${s[1]}`));
}
global.Hydro.lib.html2md = module.exports = html2md;
+69 -65
View File
@@ -2,6 +2,7 @@
const Mongo = global.Hydro.nodeModules.mongodb;
const { ObjectID } = global.Hydro.nodeModules.bson;
const dst = global.Hydro.service.db;
const { problem } = global.Hydro.model.problem;
function parseSolution(doc) {
return {
@@ -12,72 +13,75 @@ function parseSolution(doc) {
};
}
async function problem(src, report) {
let count = await src.collection('document').find({ doc_type: 10 }).count();
await report({ progress: 1, message: `Found ${count} problems.` });
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 10 })
.skip(i * 50).limit(50)
.toArray();
const problems = [];
for (const doc of docs) {
problems.push({
_id: doc._id,
pid: doc.doc_id || new ObjectID(),
title: doc.title,
content: doc.content,
owner: doc.owner_uid,
data: doc.data,
category: doc.category,
tag: doc.tag,
nSubmit: doc.num_submit,
nAccept: doc.num_accept,
});
const tasks = {
async problem(src, report) {
let count = await src.collection('document').find({ doc_type: 10 }).count();
await report({ progress: 1, message: `Found ${count} problems.` });
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 10 })
.skip(i * 50).limit(50)
.toArray();
const problems = [];
for (const doc of docs) {
problems.push({
_id: doc._id,
pid: doc.doc_id || new ObjectID(),
title: doc.title,
content: doc.content,
owner: doc.owner_uid,
data: doc.data,
category: doc.category,
tag: doc.tag,
nSubmit: doc.num_submit,
nAccept: doc.num_accept,
});
}
await dst.collection('problem').insertMany(problems);
}
await dst.collection('problem').insertMany(problems);
}
count = await src.collection('document.status').find({ doc_type: 10 }).count();
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document.status').find({ doc_type: 10 })
.skip(i * 50).limit(50)
.toArray();
const problems = [];
for (const doc of docs) {
problems.push({
pid: doc.pid,
rid: doc.rid,
});
count = await src.collection('document.status').find({ doc_type: 10 }).count();
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document.status').find({ doc_type: 10 })
.skip(i * 50).limit(50)
.toArray();
const problems = [];
for (const doc of docs) {
problems.push({
pid: await problem.get(doc.pid),
rid: doc.rid,
uid: doc.uid,
status: doc.status,
});
}
await dst.collection('problem.status').insertMany(problems);
}
await dst.collection('problem.status').insertMany(problems);
}
await report({ progress: 1, message: `Found ${count} problems.` });
}
async function contest(src, report) {
const RULES = ['', 'oi', 'acm'];
const count = await src.collection('document').find({ doc_type: 30 }).count();
await report({ progress: 1, message: `Found ${count} contests.` });
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 30 })
.skip(i * 50).limit(50)
.toArray();
const contests = [];
for (const doc of docs) {
contests.push({
_id: doc._id,
title: doc.title,
content: doc.content,
owner: doc.owner_uid,
rule: RULES[doc.rule],
beginAt: doc.begin_at,
endAt: doc.end_at,
pids: doc.pids,
attend: doc.attend,
});
await report({ progress: 1, message: `Found ${count} problems.` });
},
async contest(src, report) {
const RULES = ['', 'oi', 'acm'];
const count = await src.collection('document').find({ doc_type: 30 }).count();
await report({ progress: 1, message: `Found ${count} contests.` });
for (let i = 0; i <= Math.floor(count / 50); i++) {
const docs = await src.collection('document').find({ doc_type: 30 })
.skip(i * 50).limit(50)
.toArray();
const contests = [];
for (const doc of docs) {
contests.push({
_id: doc._id,
title: doc.title,
content: doc.content,
owner: doc.owner_uid,
rule: RULES[doc.rule],
beginAt: doc.begin_at,
endAt: doc.end_at,
pids: doc.pids,
attend: doc.attend,
});
}
await dst.collection('contest').insertMany(contests);
}
await dst.collection('contests').insertMany(contests);
}
}
},
};
async function migrateVijos({
host, port, name, username, password,
@@ -95,8 +99,8 @@ async function migrateVijos({
value: (await src.collection('system').findOne({ _id: 'user_counter' })).value,
});
await report({ progress: 1, message: 'Collection:system done.' });
await problem(src, report);
await contest(src, report);
await tasks.problem(src, report);
await tasks.contest(src, report);
}
global.Hydro.script.migrateVijos = module.exports = migrateVijos;
@@ -0,0 +1,3 @@
[
"introduction"
]
@@ -0,0 +1,11 @@
# Introduction
为什么使用 Hydro ?
- 安全:使用 cgroup 进行隔离,杜绝卡评测;
- 高效:Hydro 使用了沙箱复用技术,拥有极高的评测效率;
- 扩展:Hydro 支持安装额外模块进行扩展;
- 强大:配合 Judger 模块(或 HydroJudger 独立评测机),可支持 spj,交互题,提交答案题,文件IO等多种特性;
- 简便:提供了多种迁移脚本,可从 Vijos 等快速升级至 Hydro;
- 自定:所有权限节点均可自由设置;
- 社区:Hydro 正在持续维护中;
+1
View File
@@ -19,6 +19,7 @@
<ol class="menu">
{{ sidemenu.render_item('info', 'wiki_about', '/wiki/about') }}
{{ sidemenu.render_item('help', 'wiki_help', '/wiki/help') }}
{{ sidemenu.render_item('help', 'wiki_gettingstarted', '/wiki/gettingstarted') }}
{{ sidemenu.render_item('help', 'wiki_development', '/wiki/development') }}
</ol>
</div>