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,109 @@
|
||||
<script setup>
|
||||
/**
|
||||
* A file with line numbers, highlighting and a copy button. Only the
|
||||
* languages the workspace uses are registered, which keeps highlight.js to a
|
||||
* few kilobytes instead of the full bundle.
|
||||
*/
|
||||
import { computed, ref } from "vue";
|
||||
import hljs from "highlight.js/lib/core";
|
||||
import cpp from "highlight.js/lib/languages/cpp";
|
||||
import python from "highlight.js/lib/languages/python";
|
||||
|
||||
hljs.registerLanguage("cpp", cpp);
|
||||
hljs.registerLanguage("c", cpp);
|
||||
hljs.registerLanguage("python", python);
|
||||
|
||||
const props = defineProps({
|
||||
content: { type: String, required: true },
|
||||
lang: { type: String, default: "" },
|
||||
truncated: { type: Boolean, default: false },
|
||||
});
|
||||
|
||||
// highlight.js escapes the source itself, so v-html on its output is safe.
|
||||
const html = computed(() => {
|
||||
const text = props.content.replace(/\n$/, "");
|
||||
if (props.lang && hljs.getLanguage(props.lang)) {
|
||||
return hljs.highlight(text, { language: props.lang }).value;
|
||||
}
|
||||
return text.replace(/[&<>]/g, (c) => ({ "&": "&", "<": "<", ">": ">" })[c]);
|
||||
});
|
||||
const lines = computed(() => props.content.replace(/\n$/, "").split("\n").length);
|
||||
|
||||
const copied = ref(false);
|
||||
async function copy() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(props.content);
|
||||
copied.value = true;
|
||||
setTimeout(() => (copied.value = false), 1500);
|
||||
} catch {
|
||||
// Clipboard access refused (insecure context or permissions): nothing to do.
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="code">
|
||||
<button class="copy" type="button" @click="copy">{{ copied ? "Copied" : "Copy" }}</button>
|
||||
<div class="scroll">
|
||||
<pre class="gutter" aria-hidden="true">{{ Array.from({ length: lines }, (_, i) => i + 1).join("\n") }}</pre>
|
||||
<pre class="hljs src"><code v-html="html"></code></pre>
|
||||
</div>
|
||||
<p v-if="truncated" class="cut muted">Cut short: the file is larger than the site shows.</p>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.code {
|
||||
position: relative;
|
||||
background: var(--color-paper);
|
||||
border: 1px solid var(--color-line-soft);
|
||||
border-radius: 6px;
|
||||
}
|
||||
.scroll {
|
||||
display: flex;
|
||||
overflow-x: auto;
|
||||
font-family: var(--font-mono);
|
||||
font-size: 0.8125rem;
|
||||
line-height: 1.55;
|
||||
}
|
||||
pre {
|
||||
margin: 0;
|
||||
padding: 12px 0;
|
||||
font-family: inherit;
|
||||
}
|
||||
.gutter {
|
||||
padding: 12px 10px 12px 12px;
|
||||
text-align: right;
|
||||
color: var(--color-ink-faint);
|
||||
user-select: none;
|
||||
border-right: 1px solid var(--color-line-soft);
|
||||
position: sticky;
|
||||
left: 0;
|
||||
background: var(--color-paper);
|
||||
}
|
||||
.src {
|
||||
padding-left: 12px;
|
||||
padding-right: 64px;
|
||||
}
|
||||
.copy {
|
||||
position: absolute;
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
z-index: 1;
|
||||
padding: 2px 10px;
|
||||
font-size: 0.75rem;
|
||||
border: 1px solid var(--color-line);
|
||||
border-radius: 4px;
|
||||
background: var(--color-paper);
|
||||
color: var(--color-ink-muted);
|
||||
cursor: pointer;
|
||||
}
|
||||
.copy:hover {
|
||||
color: var(--color-ink);
|
||||
}
|
||||
.cut {
|
||||
padding: 6px 12px;
|
||||
font-size: 0.8rem;
|
||||
border-top: 1px solid var(--color-line-soft);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user