core: buildContent: add background field

This commit is contained in:
undefined committed 2026-01-05 18:14:45 +08:00
1 parent 6f1a6c8fc8
commit 4fc7b815b7
4 files changed
+26 -25

No files matched your search

+2 -1
View File
@@ -9,7 +9,7 @@ import { load as loadOptions } from '../options';
import { MongoService } from '../service/db';
import { SettingService } from '../settings';
import {
addon, builtinModel, model, service,
addon, builtinModel, locale, model, service,
} from './common';
const argv = cac().parse();
@@ -110,6 +110,7 @@ export async function load(ctx: Context) {
require('../service/bus').apply(ctx);
const pending = global.addons;
const fail = [];
await locale(pending, fail);
await ctx.plugin(MongoService, loadOptions() || {});
await ctx.plugin(SettingService);
await ctx.plugin(SystemModel.Service);
+18 -20
View File
@@ -1,4 +1,5 @@
export interface ProblemSource {
background?: string;
description?: string;
input?: string;
output?: string;
@@ -43,36 +44,33 @@ export function buildContent(source: ProblemSource, type: 'markdown' | 'html' =
'',
]).join('\n');
}
return type === 'html'
? [
...source.description ? [`<h2>${_('Description')}</h2>`, source.description] : [],
...source.input ? [`<h2>${_('Input Format')}</h2>`, source.input] : [],
...source.output ? [`<h2>${_('Output Format')}</h2>`, source.output] : [],
...(source.samples || []).map((sample, i) => [
const line = (title: string, s: string) => s ? (type === 'html' ? [`<h2>${_(title)}</h2>`, s] : [`## ${_(title)}`, '', s, '']) : [];
return [
line('Background', source.background),
line('Problem Description', source.description),
line('Input Format', source.input),
line('Output Format', source.output),
type === 'html'
? (source.samples || []).map((sample, i) => [
`<pre><code class="language-input${i + 1}">`,
sample[0],
`</code></pre><pre><code class="language-output${i + 1}">`,
sample[1],
'</code></pre>',
].join('')),
...source.samplesRaw ? [source.samplesRaw] : [],
...source.hint ? [`<h2>${_('Hint')}</h2>`, source.hint] : [],
...source.source ? [`<h2>${_('Source')}</h2>`, source.source] : [],
].join('\n')
: [
...source.description ? [`## ${_('Description')}`, '', source.description, ''] : [],
...source.input ? [`## ${_('Input Format')}`, '', source.input, ''] : [],
...source.output ? [`## ${_('Output Format')}`, '', source.output, ''] : [],
...(source.samples || []).flatMap((sample, i) => [
].join(''))
: (source.samples || []).flatMap((sample, i) => [
'',
`\`\`\`input${i + 1}`,
sample[0],
'```',
'',
`\`\`\`output${i + 1}`,
sample[1],
'```',
'',
]),
...source.samplesRaw ? [source.samplesRaw] : [],
...source.hint ? [`## ${_('Hint')}`, '', source.hint, ''] : [],
...source.source ? [`## ${_('Source')}`, '', source.source, ''] : [],
].join('\n');
...source.samplesRaw ? [source.samplesRaw] : [],
line('Hint', source.hint),
line('Source', source.source),
].flat().join('\n');
}