mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
core: buildContent: add background field
This commit is contained in:
4 files changed
+26
-25
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
Reference in new issue
Block a user