feat: allow per page URIs in the footer
This commit is contained in:
parent
7380bdec31
commit
d3598f0d89
2 changed files with 20 additions and 9 deletions
|
@ -5,6 +5,8 @@ import useTerminal from './useTerminal'
|
||||||
import titleArt from './titles'
|
import titleArt from './titles'
|
||||||
import { data as pages } from './pages.data'
|
import { data as pages } from './pages.data'
|
||||||
|
|
||||||
|
import type { Uri } from './Config'
|
||||||
|
|
||||||
const { site, page } = useData()
|
const { site, page } = useData()
|
||||||
const enhancedReadability = ref(false) // TODO!
|
const enhancedReadability = ref(false) // TODO!
|
||||||
|
|
||||||
|
@ -26,21 +28,28 @@ function parsedContent(src: string) {
|
||||||
return content.join('\n\n')
|
return content.join('\n\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Page = {
|
||||||
|
title: string
|
||||||
|
titleArt: string
|
||||||
|
content: string
|
||||||
|
uris: Uri[]
|
||||||
|
}
|
||||||
|
|
||||||
function getCurrentPage(title: string) {
|
function getCurrentPage(title: string) {
|
||||||
const page = pages.find(p => p.frontmatter.title === title)
|
const page = pages.find(p => p.frontmatter.title === title)
|
||||||
console.log('getting page', title, page)
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
console.error('current page not found')
|
console.error('☠️ current page not found in the list. This should never happen.')
|
||||||
return {
|
return {
|
||||||
title: 'not_found',
|
title: 'not_found',
|
||||||
titleArt: getTitleArt('not_found'),
|
titleArt: getTitleArt('not_found'),
|
||||||
content: 'The page could not be found.',
|
content: 'The page could not be found.',
|
||||||
|
uris: [],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const titleArt = page.frontmatter.titleArt ?? getTitleArt(title)
|
const titleArt = page.frontmatter.titleArt ?? getTitleArt(title)
|
||||||
const content = parsedContent(page.src)
|
const content = parsedContent(page.src)
|
||||||
|
|
||||||
return { title, titleArt, content }
|
return { title, titleArt, content, uris: page.frontmatter.uris ?? [] }
|
||||||
}
|
}
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
@ -49,11 +58,12 @@ onMounted(() => {
|
||||||
return
|
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, () => {
|
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}`)
|
addText(`${titleArt}\n${title}\n\n${content}`)
|
||||||
|
setFooter(uris)
|
||||||
}, { immediate: true })
|
}, { immediate: true })
|
||||||
|
|
||||||
watch(footerLinks, () => {
|
watch(footerLinks, () => {
|
||||||
|
|
|
@ -2,15 +2,15 @@ import { ref } from 'vue'
|
||||||
import type { SimpleCommand, Uri } from './Config'
|
import type { SimpleCommand, Uri } from './Config'
|
||||||
import { useRouter } from 'vitepress'
|
import { useRouter } from 'vitepress'
|
||||||
|
|
||||||
type PageInfo = {
|
type VitePressPage = {
|
||||||
frontmatter: Record<string, string>
|
frontmatter: Record<string, string>
|
||||||
src: string
|
src: string
|
||||||
url: 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 prompt = '\n$> '
|
||||||
const footerLinks = ref([])
|
const footerLinks = ref<Uri[]>([])
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
|
@ -88,6 +88,7 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFooter(uris: Uri[]) {
|
function setFooter(uris: Uri[]) {
|
||||||
|
console.log('setting footer links', uris)
|
||||||
footerLinks.value = uris
|
footerLinks.value = uris
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,5 +186,5 @@ export default function useTerminal(inputEl: HTMLTextAreaElement, commands: Simp
|
||||||
inputEl.addEventListener('click', () => moveCursorToEnd())
|
inputEl.addEventListener('click', () => moveCursorToEnd())
|
||||||
inputEl.addEventListener('keydown', handleInput)
|
inputEl.addEventListener('keydown', handleInput)
|
||||||
|
|
||||||
return { addText, addLine, setFocus, clear, footerLinks }
|
return { addText, addLine, setFocus, clear, footerLinks, setFooter }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue