Add the website: Go server + Vue SPA in site/, with CI
A standalone container for web_server, shaped like job-tracker: serves /usaco/ with solved problems public and solving/skipped plus edits (status, link, notes) for the site admin. Git is the only store: the server clones adamf/usaco from Gitea, pulls on the push webhook, and commits edits back. CI builds the image only when site/ changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
<script setup>
|
||||
/**
|
||||
* One problem: its solution files, sample input, saved tests, notes and git
|
||||
* history. The admin also gets the status buttons and the link/notes editor;
|
||||
* each edit is a commit the server pushes, and the response is the problem
|
||||
* as it is afterwards, so the page just takes it.
|
||||
*/
|
||||
import { computed, ref, watch } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
import MarkdownIt from "markdown-it";
|
||||
import CodeBlock from "@/components/CodeBlock.vue";
|
||||
import { getMe, getProblem, setStatus, updateMeta } from "@/api";
|
||||
import { LANG_LABELS, STATUS_LABELS, formatDate, title } from "@/format";
|
||||
|
||||
const props = defineProps({ name: { type: String, required: true } });
|
||||
|
||||
// html: false — notes are rendered as markdown only, never as raw HTML.
|
||||
const md = new MarkdownIt({ html: false, linkify: true });
|
||||
|
||||
const problem = ref(null);
|
||||
const admin = ref(false);
|
||||
const loading = ref(true);
|
||||
const error = ref("");
|
||||
const activeFile = ref(0);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
error.value = "";
|
||||
activeFile.value = 0;
|
||||
try {
|
||||
const [p, me] = await Promise.all([getProblem(props.name), getMe().catch(() => ({ admin: false }))]);
|
||||
problem.value = p;
|
||||
admin.value = me.admin;
|
||||
} catch (e) {
|
||||
problem.value = null;
|
||||
error.value = e.status === 404 ? "No such problem." : e.message;
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
watch(() => props.name, load, { immediate: true });
|
||||
|
||||
const notesHtml = computed(() => (problem.value?.notes ? md.render(problem.value.notes) : ""));
|
||||
const file = computed(() => problem.value?.files[activeFile.value]);
|
||||
|
||||
// ---- admin edits ----
|
||||
const saving = ref(false);
|
||||
const editError = ref("");
|
||||
const editing = ref(false);
|
||||
const draftUrl = ref("");
|
||||
const draftNotes = ref("");
|
||||
|
||||
function startEdit() {
|
||||
draftUrl.value = problem.value.url || "";
|
||||
draftNotes.value = problem.value.notes || "";
|
||||
editError.value = "";
|
||||
editing.value = true;
|
||||
}
|
||||
|
||||
async function run(action) {
|
||||
saving.value = true;
|
||||
editError.value = "";
|
||||
try {
|
||||
problem.value = await action();
|
||||
return true;
|
||||
} catch (e) {
|
||||
editError.value = e.message;
|
||||
return false;
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function saveMeta() {
|
||||
if (await run(() => updateMeta(props.name, { url: draftUrl.value, notes: draftNotes.value }))) {
|
||||
editing.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const moves = computed(() => {
|
||||
const s = problem.value?.status;
|
||||
return [
|
||||
{ to: "solved", label: "Mark solved" },
|
||||
{ to: "skipped", label: "Skip" },
|
||||
{ to: "solving", label: "Reopen" },
|
||||
].filter((m) => m.to !== s);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<p v-if="loading" class="muted">Loading…</p>
|
||||
<div v-else-if="error">
|
||||
<p class="error">{{ error }}</p>
|
||||
<RouterLink to="/">Back to the list</RouterLink>
|
||||
</div>
|
||||
|
||||
<article v-else-if="problem" class="page">
|
||||
<header class="head">
|
||||
<RouterLink to="/" class="back">← All problems</RouterLink>
|
||||
<h1>{{ title(problem.name) }}</h1>
|
||||
<div class="facts">
|
||||
<span class="badge" :class="problem.status">{{ STATUS_LABELS[problem.status] }}</span>
|
||||
<a v-if="problem.url" :href="problem.url" target="_blank" rel="noopener noreferrer">
|
||||
{{ problem.source || "Problem statement" }} ↗
|
||||
</a>
|
||||
<span v-if="problem.solvedAt" class="muted">Solved {{ formatDate(problem.solvedAt) }}</span>
|
||||
<span v-else-if="problem.firstSeen" class="muted">Started {{ formatDate(problem.firstSeen) }}</span>
|
||||
<span v-if="problem.io" class="muted">File I/O: <code>{{ problem.io }}.in</code></span>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<section v-if="admin" class="admin card">
|
||||
<div class="admin-row">
|
||||
<span class="muted">Admin</span>
|
||||
<button v-for="m in moves" :key="m.to" class="btn" :disabled="saving" @click="run(() => setStatus(problem.name, m.to))">
|
||||
{{ m.label }}
|
||||
</button>
|
||||
<button v-if="!editing" class="btn" :disabled="saving" @click="startEdit">Edit link and notes</button>
|
||||
<span v-if="saving" class="muted">Saving to git…</span>
|
||||
</div>
|
||||
<form v-if="editing" class="editor" @submit.prevent="saveMeta">
|
||||
<label>
|
||||
Problem link
|
||||
<input v-model="draftUrl" type="url" placeholder="https://usaco.org/index.php?page=viewproblem2&cpid=…" />
|
||||
</label>
|
||||
<label>
|
||||
Notes (markdown)
|
||||
<textarea v-model="draftNotes" rows="8" placeholder="Approach, complexity, what tripped you up…"></textarea>
|
||||
</label>
|
||||
<div class="admin-row">
|
||||
<button class="btn primary" type="submit" :disabled="saving">Save</button>
|
||||
<button class="btn" type="button" :disabled="saving" @click="editing = false">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
<p v-if="editError" class="error">{{ editError }}</p>
|
||||
</section>
|
||||
|
||||
<section v-if="notesHtml" class="notes card prose" v-html="notesHtml"></section>
|
||||
|
||||
<section>
|
||||
<h2>Solution</h2>
|
||||
<p v-if="!problem.files.length" class="muted">No solution file yet.</p>
|
||||
<template v-else>
|
||||
<div v-if="problem.files.length > 1" class="file-tabs" role="tablist">
|
||||
<button
|
||||
v-for="(f, i) in problem.files"
|
||||
:key="f.name"
|
||||
role="tab"
|
||||
:aria-selected="i === activeFile"
|
||||
:class="{ on: i === activeFile }"
|
||||
@click="activeFile = i"
|
||||
>
|
||||
{{ f.name }} <span class="muted">{{ LANG_LABELS[f.lang] || f.lang }}</span>
|
||||
</button>
|
||||
</div>
|
||||
<p v-else class="filename muted">{{ file.name }}</p>
|
||||
<CodeBlock :key="file.name" :content="file.content" :lang="file.lang" :truncated="file.truncated" />
|
||||
</template>
|
||||
</section>
|
||||
|
||||
<section v-if="problem.sample">
|
||||
<h2>Sample input</h2>
|
||||
<p class="filename muted">{{ problem.sample.name }}</p>
|
||||
<CodeBlock :content="problem.sample.content" :truncated="problem.sample.truncated" />
|
||||
</section>
|
||||
|
||||
<section v-if="problem.testCases.length">
|
||||
<h2>Tests</h2>
|
||||
<details v-for="t in problem.testCases" :key="t.name" class="test card">
|
||||
<summary>Test {{ t.name }}</summary>
|
||||
<div class="io">
|
||||
<div>
|
||||
<p class="filename muted">Input</p>
|
||||
<CodeBlock :content="t.input.content" :truncated="t.input.truncated" />
|
||||
</div>
|
||||
<div>
|
||||
<p class="filename muted">Expected output</p>
|
||||
<CodeBlock v-if="t.output" :content="t.output.content" :truncated="t.output.truncated" />
|
||||
<p v-else class="muted">Not saved.</p>
|
||||
</div>
|
||||
</div>
|
||||
</details>
|
||||
</section>
|
||||
|
||||
<section v-if="problem.history.length">
|
||||
<h2>History</h2>
|
||||
<ol class="history">
|
||||
<li v-for="c in problem.history" :key="c.hash">
|
||||
<time :datetime="c.date" class="muted">{{ formatDate(c.date) }}</time>
|
||||
<span>{{ c.subject }}</span>
|
||||
<code class="muted">{{ c.hash.slice(0, 7) }}</code>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
</article>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.page {
|
||||
display: grid;
|
||||
gap: 28px;
|
||||
min-width: 0;
|
||||
}
|
||||
.page > section {
|
||||
min-width: 0;
|
||||
}
|
||||
.back {
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-ink-muted);
|
||||
text-decoration: none;
|
||||
}
|
||||
.back:hover {
|
||||
color: var(--color-ink);
|
||||
}
|
||||
h1 {
|
||||
font-size: 2.75rem;
|
||||
margin: 6px 0 10px;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
h2 {
|
||||
font-size: 1.6rem;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.facts {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px 16px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.facts code,
|
||||
.history code {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.85em;
|
||||
}
|
||||
.admin {
|
||||
padding: 12px 16px;
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
.admin-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
.editor {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
.editor label {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-ink-muted);
|
||||
}
|
||||
.editor input,
|
||||
.editor textarea {
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: 4px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.85rem;
|
||||
color: var(--color-ink);
|
||||
background: var(--color-paper);
|
||||
}
|
||||
.notes {
|
||||
padding: 16px 20px;
|
||||
}
|
||||
.file-tabs {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.file-tabs button {
|
||||
padding: 4px 12px;
|
||||
border: 1px solid var(--color-line-soft);
|
||||
border-radius: 4px;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
cursor: pointer;
|
||||
}
|
||||
.file-tabs button.on {
|
||||
border-color: var(--color-ink);
|
||||
background: var(--color-paper);
|
||||
}
|
||||
.filename {
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8rem;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.test {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.test summary {
|
||||
padding: 8px 14px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.io {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
|
||||
gap: 12px;
|
||||
padding: 0 14px 14px;
|
||||
min-width: 0;
|
||||
}
|
||||
.io > div {
|
||||
min-width: 0;
|
||||
}
|
||||
.history {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
.history li {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 12px;
|
||||
}
|
||||
.history time {
|
||||
min-width: 7.5em;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user