mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
feat: separate Markdown to a component
This commit is contained in:
1 parent
abaacf7ee7
commit
8f31e4f2cd
3 files changed
+55
-41
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, computed } from 'vue'
|
import { ref, watch } from 'vue'
|
||||||
import sessionStore from '../store/session'
|
import sessionStore from '../store/session'
|
||||||
import markdown2HTML from '../utils/markdown'
|
import MarkdownText from './MarkdownText.vue'
|
||||||
|
|
||||||
const current = ref(-1)
|
const current = ref(-1)
|
||||||
watch(
|
watch(
|
||||||
@@ -23,12 +23,6 @@ const right = () => {
|
|||||||
current.value += 1
|
current.value += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const hints = computed(() => {
|
|
||||||
return sessionStore.session.hints.map((stageHints) =>
|
|
||||||
stageHints.map(markdown2HTML)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -57,13 +51,13 @@ const hints = computed(() => {
|
|||||||
<p class="inline text-text font-xl w-1/14 p-2 m-1">{{ current + 1 }}</p>
|
<p class="inline text-text font-xl w-1/14 p-2 m-1">{{ current + 1 }}</p>
|
||||||
<p class="inline text-text font-xl w-1/14 p-2 m-1">/</p>
|
<p class="inline text-text font-xl w-1/14 p-2 m-1">/</p>
|
||||||
<p class="inline text-text font-xl w-1/14 p-2 m-1">
|
<p class="inline text-text font-xl w-1/14 p-2 m-1">
|
||||||
{{ hints.length }}
|
{{ sessionStore.session.hints.length }}
|
||||||
</p>
|
</p>
|
||||||
<button
|
<button
|
||||||
class="p-2 m-1 w-1/8"
|
class="p-2 m-1 w-1/8"
|
||||||
id="Rbutton"
|
id="Rbutton"
|
||||||
@click="right"
|
@click="right"
|
||||||
:disabled="current === hints.length - 1"
|
:disabled="current === sessionStore.session.hints.length - 1"
|
||||||
>
|
>
|
||||||
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
|
<font-awesome-icon :icon="['fas', 'arrow-right']" class="text-text" />
|
||||||
</button>
|
</button>
|
||||||
@@ -72,11 +66,12 @@ const hints = computed(() => {
|
|||||||
<div id="hint" class="bg-bg flex flex-wrap p-8">
|
<div id="hint" class="bg-bg flex flex-wrap p-8">
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
<li
|
||||||
v-for="hint in hints[current]"
|
v-for="hint in sessionStore.session.hints[current]"
|
||||||
:key="hint"
|
:key="hint"
|
||||||
class="text-text font-xl whitespace-pre-wrap"
|
class="text-text font-xl whitespace-pre-wrap"
|
||||||
v-html="hint"
|
>
|
||||||
></li>
|
<MarkdownText :content="hint" />
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br />
|
<br />
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<script setup>
|
||||||
|
import { computed, defineProps } from 'vue'
|
||||||
|
import markdown2HTML from '../utils/markdown'
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
content: {
|
||||||
|
type: String,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
const html = computed(() => {
|
||||||
|
return markdown2HTML(props.content)
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="markdown-content" v-html="html"></div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.markdown-content {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
line-height: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.markdown-content :deep(ol) {
|
||||||
|
list-style: decimal;
|
||||||
|
padding-left: 1em;
|
||||||
|
}
|
||||||
|
.markdown-content :deep(code) {
|
||||||
|
background-color: #282a33;
|
||||||
|
border-radius: 0.25rem;
|
||||||
|
padding: 0.25rem;
|
||||||
|
font-size: 0.875rem;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,11 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { computed } from 'vue'
|
import { computed } from 'vue'
|
||||||
|
import MarkdownText from './MarkdownText.vue'
|
||||||
import sessionStore from '../store/session'
|
import sessionStore from '../store/session'
|
||||||
import markdown2HTML from '../utils/markdown'
|
|
||||||
|
|
||||||
const instruction = computed(() => {
|
|
||||||
return markdown2HTML(sessionStore.quest.instruction)
|
|
||||||
})
|
|
||||||
|
|
||||||
const tasks = computed(() => {
|
const tasks = computed(() => {
|
||||||
return sessionStore.session.tasks.map((task) => {
|
return sessionStore.session.tasks.map((task) => {
|
||||||
@@ -14,7 +10,7 @@ const tasks = computed(() => {
|
|||||||
return {
|
return {
|
||||||
...task,
|
...task,
|
||||||
class: `${color} markdown-content`,
|
class: `${color} markdown-content`,
|
||||||
content: markdown2HTML(`${prefix} ${task.name}`),
|
content: `${prefix} ${task.name}`,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -28,37 +24,22 @@ const tasks = computed(() => {
|
|||||||
<br />
|
<br />
|
||||||
<div>
|
<div>
|
||||||
<div v-if="sessionStore.quest" class="whitespace-pre-wrap">
|
<div v-if="sessionStore.quest" class="whitespace-pre-wrap">
|
||||||
<p class="text-text markdown-content" v-html="instruction"></p>
|
<MarkdownText
|
||||||
|
class="text-text markdown-content"
|
||||||
|
:content="sessionStore.quest.instruction"
|
||||||
|
/>
|
||||||
<br />
|
<br />
|
||||||
<p id="tasks" class="text-text">
|
<p id="tasks" class="text-text">
|
||||||
<!-- Tasks: -->
|
<!-- Tasks: -->
|
||||||
任務:
|
任務:
|
||||||
</p>
|
</p>
|
||||||
<ul v-if="sessionStore.session">
|
<ul v-if="sessionStore.session">
|
||||||
<li
|
<li v-for="task in tasks" :key="task.id">
|
||||||
v-for="task in tasks"
|
<MarkdownText :class="task.class" :content="task.content" />
|
||||||
:key="task.id"
|
</li>
|
||||||
:class="task.class"
|
|
||||||
v-html="task.content"
|
|
||||||
></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
<p class="text-text" v-else>Loading...</p>
|
<p class="text-text" v-else>Loading...</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped>
|
|
||||||
.markdown-content :deep(p) {
|
|
||||||
margin: 0;
|
|
||||||
color: 'red';
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.markdown-content :deep(code) {
|
|
||||||
background-color: #282a33;
|
|
||||||
border-radius: 0.25rem;
|
|
||||||
padding: 0.25rem;
|
|
||||||
font-size: 0.875rem;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Reference in new issue
Block a user