update vitepress to v1.0
This commit is contained in:
36
.vitepress/theme/components/Author.vue
Normal file
36
.vitepress/theme/components/Author.vue
Normal file
@@ -0,0 +1,36 @@
|
||||
<template>
|
||||
<div class="author">
|
||||
<img class="photo" :src="'/avatars/' + name + '.svg'" alt="avatar" />
|
||||
<div class="intro">
|
||||
<span class="name">{{ name }}</span>
|
||||
<span class="title">{{ title }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
interface Props {
|
||||
name: string
|
||||
title: string
|
||||
}
|
||||
defineProps<Props>()
|
||||
</script>
|
||||
<style scoped>
|
||||
.author {
|
||||
display: inline-flex;
|
||||
margin: 2rem 4rem 0 0;
|
||||
}
|
||||
|
||||
.photo {
|
||||
width: 3rem;
|
||||
height: 3rem;
|
||||
margin-right: 1rem;
|
||||
}
|
||||
|
||||
.intro {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.name {
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>
|
||||
37
.vitepress/theme/components/BVideo.vue
Normal file
37
.vitepress/theme/components/BVideo.vue
Normal file
@@ -0,0 +1,37 @@
|
||||
<template>
|
||||
<div class="video">
|
||||
<iframe :src="url"></iframe>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue"
|
||||
interface Props {
|
||||
src: string
|
||||
p?: number
|
||||
}
|
||||
|
||||
const props = defineProps<Props>()
|
||||
const url = computed(() => {
|
||||
let url = `https://player.bilibili.com/player.html?bvid=${props.src}`
|
||||
if (props.p) {
|
||||
url += `&page=${props.p}`
|
||||
}
|
||||
return url
|
||||
})
|
||||
</script>
|
||||
<style scoped>
|
||||
.video {
|
||||
position: relative;
|
||||
width: 100%;
|
||||
padding-bottom: calc(56.25% + 68px);
|
||||
}
|
||||
|
||||
.video > iframe {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: none;
|
||||
}
|
||||
</style>
|
||||
115
.vitepress/theme/components/CodeEditor.vue
Normal file
115
.vitepress/theme/components/CodeEditor.vue
Normal file
@@ -0,0 +1,115 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from "vue"
|
||||
import { useData } from "vitepress"
|
||||
import { VPButton } from "vitepress/theme"
|
||||
import Codemirror from "vue-codemirror6"
|
||||
import { cpp } from "@codemirror/lang-cpp"
|
||||
import { python } from "@codemirror/lang-python"
|
||||
import { indentUnit } from "@codemirror/language"
|
||||
import { EditorView } from "@codemirror/view"
|
||||
import { createSubmission } from "../judge"
|
||||
import { smoothy } from "../cm-themes/smoothy"
|
||||
import { oneDark } from "../cm-themes/oneDark"
|
||||
|
||||
interface Props {
|
||||
code: string
|
||||
readonly?: boolean
|
||||
lang?: "python" | "c"
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
lang: "python",
|
||||
readonly: false,
|
||||
})
|
||||
|
||||
const { isDark } = useData()
|
||||
|
||||
const lang = computed(() => {
|
||||
if (props.lang === "python") {
|
||||
return python()
|
||||
}
|
||||
return cpp()
|
||||
})
|
||||
|
||||
const styleTheme = EditorView.baseTheme({
|
||||
"& .cm-scroller": {
|
||||
"font-family": "Monaco",
|
||||
border: "2px solid var(--vp-c-divider)",
|
||||
},
|
||||
"&.cm-editor.cm-focused": {
|
||||
outline: "none",
|
||||
},
|
||||
"&.cm-editor .cm-tooltip.cm-tooltip-autocomplete ul": {
|
||||
"font-family": "Monaco",
|
||||
},
|
||||
})
|
||||
|
||||
const code = ref(props.code.trim())
|
||||
const input = ref("")
|
||||
const output = ref("")
|
||||
|
||||
async function run() {
|
||||
output.value = ""
|
||||
const result = await createSubmission(
|
||||
{ value: code.value, language: props.lang },
|
||||
input.value,
|
||||
)
|
||||
output.value = result.output
|
||||
}
|
||||
|
||||
function reset() {
|
||||
code.value = props.code.trim()
|
||||
output.value = ""
|
||||
}
|
||||
</script>
|
||||
<template>
|
||||
<ClientOnly>
|
||||
<div :class="$style.container">
|
||||
<p :class="$style.title">代码区</p>
|
||||
<Codemirror
|
||||
v-model="code"
|
||||
:lang="lang"
|
||||
basic
|
||||
tab
|
||||
:tab-size="4"
|
||||
:readonly="props.readonly"
|
||||
:extensions="[
|
||||
styleTheme,
|
||||
isDark ? oneDark : smoothy,
|
||||
indentUnit.of(' '),
|
||||
]"
|
||||
/>
|
||||
<p :class="$style.title">输入框</p>
|
||||
<Codemirror
|
||||
v-model="input"
|
||||
minimal
|
||||
:extensions="[styleTheme, isDark ? oneDark : smoothy]"
|
||||
/>
|
||||
<div :class="$style.actions">
|
||||
<VPButton :class="$style.run" @click="run" text="运行"></VPButton>
|
||||
<VPButton @click="reset" theme="alt" text="重置"></VPButton>
|
||||
</div>
|
||||
<p :class="$style.title" v-if="output.length">运行结果</p>
|
||||
<pre :class="$style.output">{{ output }}</pre>
|
||||
</div>
|
||||
</ClientOnly>
|
||||
</template>
|
||||
<style module>
|
||||
.container {
|
||||
background-color: var(--vp-code-block-bg);
|
||||
padding: 8px 16px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
.title {
|
||||
font-weight: bold;
|
||||
}
|
||||
.actions {
|
||||
margin-top: 20px;
|
||||
}
|
||||
.run {
|
||||
margin-right: 20px;
|
||||
}
|
||||
.output {
|
||||
font-family: Monaco;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user