diff --git a/.vitepress/theme/Layout.vue b/.vitepress/theme/Layout.vue index 59c86e9..a274a4e 100644 --- a/.vitepress/theme/Layout.vue +++ b/.vitepress/theme/Layout.vue @@ -5,6 +5,8 @@ import useTerminal from './useTerminal' import titleArt from './titles' import { data as pages } from './pages.data' +import type { Uri } from './Config' + const { site, page } = useData() const enhancedReadability = ref(false) // TODO! @@ -26,21 +28,28 @@ function parsedContent(src: string) { return content.join('\n\n') } +type Page = { + title: string + titleArt: string + content: string + uris: Uri[] +} + function getCurrentPage(title: string) { const page = pages.find(p => p.frontmatter.title === title) - console.log('getting page', title, page) if (!page) { - console.error('current page not found') + console.error('☠️ current page not found in the list. This should never happen.') return { title: 'not_found', titleArt: getTitleArt('not_found'), content: 'The page could not be found.', + uris: [], } } const titleArt = page.frontmatter.titleArt ?? getTitleArt(title) const content = parsedContent(page.src) - return { title, titleArt, content } + return { title, titleArt, content, uris: page.frontmatter.uris ?? [] } } onMounted(() => { @@ -49,11 +58,12 @@ onMounted(() => { return } - const { addText, addLine, clear, footerLinks } = useTerminal(textArea.value, commands.value, pages) + const { addText, addLine, clear, footerLinks, setFooter } = useTerminal(textArea.value, commands.value, pages) watch(page, () => { - const { title, titleArt, content } = getCurrentPage(page.value.title) + const { title, titleArt, content, uris } = getCurrentPage(page.value.title) addText(`${titleArt}\n${title}\n\n${content}`) + setFooter(uris) }, { immediate: true }) watch(footerLinks, () => { diff --git a/.vitepress/theme/useTerminal.ts b/.vitepress/theme/useTerminal.ts index 8f2a9b7..b9c07f3 100644 --- a/.vitepress/theme/useTerminal.ts +++ b/.vitepress/theme/useTerminal.ts @@ -2,15 +2,15 @@ import { ref } from 'vue' import type { SimpleCommand, Uri } from './Config' import { useRouter } from 'vitepress' -type PageInfo = { +type VitePressPage = { frontmatter: Record src: string url: string } -export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: PageInfo[]) { +export default function useTerminal(inputEl: HTMLTextAreaElement, commands: SimpleCommand[], pages: VitePressPage[]) { const prompt = '\n$> ' - const footerLinks = ref([]) + const footerLinks = ref([]) const router = useRouter() @@ -88,6 +88,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp } function setFooter(uris: Uri[]) { + console.log('setting footer links', uris) footerLinks.value = uris } @@ -185,5 +186,5 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp inputEl.addEventListener('click', () => moveCursorToEnd()) inputEl.addEventListener('keydown', handleInput) - return { addText, addLine, setFocus, clear, footerLinks } + return { addText, addLine, setFocus, clear, footerLinks, setFooter } }