feat: generated ascii art headers

Norman Köhring 5 months ago
parent 29ad0f3b71
commit a3febe4e85

@ -2,7 +2,7 @@
import { ref, reactive, computed, onMounted, watch } from 'vue' import { ref, reactive, computed, onMounted, watch } from 'vue'
import { useData } from 'vitepress' import { useData } from 'vitepress'
import useTerminal from './useTerminal' import useTerminal from './useTerminal'
import titleArt from './titles' import useFiglet from './useFiglet'
import { data as pages } from './pages.data' import { data as pages } from './pages.data'
import type { Uri } from './Config' import type { Uri } from './Config'
@ -16,9 +16,10 @@ const prompt = '\n$> '
const textArea = ref<HTMLTextAreaElement | null>(null) const textArea = ref<HTMLTextAreaElement | null>(null)
const footer = ref([]) const footer = ref([])
function getTitleArt(key: string) { const figlet = useFiglet()
const art = titleArt[key] ?? titleArt['not_found']
return art.join('\n') function getHeaderArt(header: string, font: string) {
return figlet.render(header, font)
} }
function parsedContent(src: string) { function parsedContent(src: string) {
@ -30,7 +31,7 @@ function parsedContent(src: string) {
type Page = { type Page = {
title: string title: string
titleArt: string headerArt: string
content: string content: string
uris: Uri[] uris: Uri[]
} }
@ -41,15 +42,16 @@ function getCurrentPage(title: string) {
console.error('☠️ current page not found in the list. This should never happen.') 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'), headerArt: getTitleArt('not_found'),
content: 'The page could not be found.', content: 'The page could not be found.',
uris: [], uris: [],
} }
} }
const titleArt = page.frontmatter.titleArt ?? getTitleArt(title) const { header, headerFont, uris } = page.frontmatter
const headerArt = getHeaderArt(header, headerFont ?? 'chunky')
const content = parsedContent(page.src) const content = parsedContent(page.src)
return { title, titleArt, content, uris: page.frontmatter.uris ?? [] } return { title, headerArt, content, uris: uris ?? [] }
} }
onMounted(() => { onMounted(() => {
@ -61,8 +63,8 @@ onMounted(() => {
const { addText, addLine, clear, footerLinks, setFooter } = 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, uris } = getCurrentPage(page.value.title) const { title, headerArt, content, uris } = getCurrentPage(page.value.title)
addText(`${titleArt}\n${title}\n\n${content}`) addText(`${headerArt}\n${title}\n\n${content}`)
setFooter(uris) setFooter(uris)
}, { immediate: true }) }, { immediate: true })

@ -1,29 +0,0 @@
export default {
index: [
" ________ __ ",
"| | | |.-----.| |.----.-----.--------.-----.",
"| | | || -__|| || __| _ | | -__|",
"|________||_____||__||____|_____|__|__|__|_____|",
],
aboutMe: [
" _______ __ __ _______ ",
"| _ | |--.-----.--.--.| |_ | | |.-----.",
"| | _ | _ | | || _| | || -__|",
"|___|___|_____|_____|_____||____| |__|_|__||_____|",
],
resume: [
" ______ ",
"| __ \.-----.-----.--.--.--------.-----.",
"| <| -__|__ --| | | | -__|",
"|___|__||_____|_____|_____|__|__|__|_____|",
],
not_found: [
" _____ ______ _____ ",
"| | || | | | ",
"|__ | -- |__ |",
" |__||______| |__| ",
]
}

@ -0,0 +1,31 @@
import { FLFParser, FontLayoutManager } from '@figlet-ts/lib'
import * as fonts from '@figlet-ts/fonts/dist/fonts'
function findFont(needle: string) {
needle = needle.toLowerCase()
for (let categoryName in fonts) {
const category = fonts[categoryName]
for (let name in category) {
if (name.toLowerCase() === needle) return category[name]
}
}
}
function getFont(name: string) {
const font = findFont(name)
if (!font) throw new Error(`Cannot find font "${name}"!`)
const flf = FLFParser.parse(atob(font._contents))
return flf.font
}
export default function useFiglet() {
const flm = new FontLayoutManager()
function render(text: string, fontName: string) {
const figFont = getFont(fontName)
const output = flm.renderText(text, figFont)
return output
}
return { render }
}

@ -1,5 +1,6 @@
--- ---
title: 'index' title: 'index'
header: 'Welcome'
uris: [ uris: [
{ label: 'Click here for a more classical version', uri: 'https://koehr.in/' }, { label: 'Click here for a more classical version', uri: 'https://koehr.in/' },
] ]

@ -9,6 +9,8 @@
"vue": "^3.3.10" "vue": "^3.3.10"
}, },
"dependencies": { "dependencies": {
"@figlet-ts/fonts": "^0.5.0",
"@figlet-ts/lib": "^0.5.0",
"@fontsource/vt323": "^5.0.8" "@fontsource/vt323": "^5.0.8"
} }
} }

@ -5,6 +5,12 @@ settings:
excludeLinksFromLockfile: false excludeLinksFromLockfile: false
dependencies: dependencies:
'@figlet-ts/fonts':
specifier: ^0.5.0
version: 0.5.0
'@figlet-ts/lib':
specifier: ^0.5.0
version: 0.5.0
'@fontsource/vt323': '@fontsource/vt323':
specifier: ^5.0.8 specifier: ^5.0.8
version: 5.0.8 version: 5.0.8
@ -421,6 +427,14 @@ packages:
dev: true dev: true
optional: true optional: true
/@figlet-ts/fonts@0.5.0:
resolution: {integrity: sha512-9O5kbxsGReBtUl7Sa7Z9Bq5hZMfBpPDqQbGjDoERL8NTphrSq9Na0Iziv3lO54nq+mVVpfMGO4WpHseKXEASOA==}
dev: false
/@figlet-ts/lib@0.5.0:
resolution: {integrity: sha512-Mwkqns5Tul9hx1d33A55OpELZPl3xx+jKit72t95h7ma745uwtbbT7giiPPU0VoJFPIZHHfs4qAvxE3gfQcfHQ==}
dev: false
/@fontsource/vt323@5.0.8: /@fontsource/vt323@5.0.8:
resolution: {integrity: sha512-WU1qtqHObNqH2Tq6NmzwpO2Gyu3E4nqEOdrSMs0j9mwtRRSHf9FeM+iYVdbA1rhJDDZSw0ZSZakGAZxOJNTTdw==} resolution: {integrity: sha512-WU1qtqHObNqH2Tq6NmzwpO2Gyu3E4nqEOdrSMs0j9mwtRRSHf9FeM+iYVdbA1rhJDDZSw0ZSZakGAZxOJNTTdw==}
dev: false dev: false

@ -1,5 +1,7 @@
--- ---
title: 'resume' title: 'resume'
header: 'Resume'
headerFont: 'Broadway'
uris: [ uris: [
{ label: 'CodeGaia', uri: 'https://codegaia.io/' }, { label: 'CodeGaia', uri: 'https://codegaia.io/' },
{ label: 'Coursedog', uri: 'https://coursedog.com/' }, { label: 'Coursedog', uri: 'https://coursedog.com/' },

Loading…
Cancel
Save