feat(Config): 支持多语言 README 文档展示
This commit is contained in:
@@ -1,18 +1,36 @@
|
||||
<script setup lang='ts'>
|
||||
import markdownit from 'markdown-it'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import readmeEn from '@/../public/readme-en.md?raw'
|
||||
import readmeZh from '@/../public/readme-zhCn.md?raw'
|
||||
import i18n from '@/locales/i18n'
|
||||
import markdownit from 'markdown-it'
|
||||
import { onMounted, ref, watch } from 'vue'
|
||||
|
||||
const md = markdownit()
|
||||
const readmeHtml = ref('')
|
||||
function readMd() {
|
||||
fetch(`/log-lottery/${i18n.global.t('data.readmeName')}`)
|
||||
.then(res => res.text())
|
||||
.then((res) => {
|
||||
readmeHtml.value = md.render(res)
|
||||
})
|
||||
}
|
||||
|
||||
function getReadmeContent() {
|
||||
const locale = i18n.global.locale.value
|
||||
if (locale === 'zhCn') {
|
||||
return readmeZh
|
||||
}
|
||||
else {
|
||||
return readmeEn
|
||||
}
|
||||
}
|
||||
function readMd() {
|
||||
try {
|
||||
const content = getReadmeContent()
|
||||
readmeHtml.value = md.render(content)
|
||||
}
|
||||
catch (error) {
|
||||
console.error('Failed to load readme:', error)
|
||||
readmeHtml.value = '<p>Failed to load README content.</p>'
|
||||
}
|
||||
}
|
||||
// 监听语言变化
|
||||
watch(() => i18n.global.locale.value, () => {
|
||||
readMd()
|
||||
})
|
||||
onMounted(() => {
|
||||
readMd()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user