From ebc6c246c7a83590f381881faebcf66c84ee12b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20K=C3=B6hring?= Date: Sun, 10 Dec 2023 16:12:44 +0100 Subject: [PATCH] fix: changing from one to another non-existing page --- .vitepress/theme/Layout.vue | 14 +++++++++++--- .vitepress/theme/useTerminal.ts | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.vitepress/theme/Layout.vue b/.vitepress/theme/Layout.vue index 867eb13..7a01a57 100644 --- a/.vitepress/theme/Layout.vue +++ b/.vitepress/theme/Layout.vue @@ -57,13 +57,21 @@ onMounted(() => { } figlet.setInputElement(textArea.value) - const { addText, addLine, clear, footerLinks, setFooter } = useTerminal(textArea.value, commands.value, pages) - watch(page, () => { + function handlePageChange() { const { title, headerArt, content, uris } = getCurrentPage(page.value.title) addText(`${headerArt}\n${title}\n\n${content}`) setFooter(uris) - }, { immediate: true }) + } + + const { + addText, + addLine, + clear, + footerLinks, + setFooter + } = useTerminal(textArea.value, commands.value, pages, handlePageChange) + handlePageChange() watch(footerLinks, () => { footer.value = footerLinks.value diff --git a/.vitepress/theme/useTerminal.ts b/.vitepress/theme/useTerminal.ts index b9c07f3..33c8f04 100644 --- a/.vitepress/theme/useTerminal.ts +++ b/.vitepress/theme/useTerminal.ts @@ -8,7 +8,7 @@ type VitePressPage = { url: string } -export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: VitePressPage[]) { +export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: VitePressPage[], pageChangeCallback: () => void) { const prompt = '\n$> ' const footerLinks = ref([]) @@ -88,7 +88,6 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp } function setFooter(uris: Uri[]) { - console.log('setting footer links', uris) footerLinks.value = uris } @@ -133,6 +132,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp async function openPage(page: string) { await router.go(page) + if (pageChangeCallback) pageChangeCallback(page) } function handleCurrentCommand() { @@ -162,7 +162,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp case 'open': addText('\n', false) if (!args.length) addText('USAGE: go page_name') - else router.go(args[0]) + else openPage(args[0]) break default: execUserCommand(cmd)