Skip to content

Commit 76c95d8

Browse files
committed
feat: improve components and add breadcrumb text humanization
- Fix NqCard icon sizing for row layout - Update NqHeadline alignment logic based on layout - Add text humanization for breadcrumbs
1 parent 2134727 commit 76c95d8

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

packages/nimiq-vitepress-theme/src/components/NqCard.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const iconClasses = computed(() => {
3636
}
3737
3838
if (!iconClass.value) {
39-
classes.push('f-size-120/160')
39+
classes.push(layout.value === 'row' ? 'f-size-48/48' : 'f-size-120/160')
4040
classes.push(layout.value === 'row' ? 'shrink-0' : 'absolute right--12')
4141
}
4242
else if (layout.value === 'row') {

packages/nimiq-vitepress-theme/src/components/NqHeadline.vue

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const {
66
title: userTitle,
77
description: userDescription,
88
h1 = true,
9-
align = 'center',
9+
align,
1010
} = defineProps<{
1111
title: string
1212
description: string
@@ -19,19 +19,24 @@ const { frontmatter } = useData()
1919
2020
const title = computed(() => userTitle || frontmatter.value.title)
2121
const description = computed(() => userDescription || frontmatter.value.description)
22+
const computedAlign = computed(() => {
23+
if (align)
24+
return align
25+
return frontmatter.value.layout === 'home' ? 'center' : 'left'
26+
})
2227
</script>
2328

2429
<template>
2530
<div
2631
flex="~ col" nq-component="headline"
27-
:class="{ 'items-start': align === 'left',
28-
'items-center': align === 'center',
32+
:class="{ 'items-start': computedAlign === 'left',
33+
'items-center': computedAlign === 'center',
2934
'f-mt-2xl': !h1 }" class="nq-raw"
3035
f-mb-2xl
3136
>
3237
<div
3338
v-if="label" outline="~ 1.5 neutral-600" bg="neutral/3" px-12 py-6 rounded-full nq-label
34-
:class="align === 'left' ? 'text-left' : 'text-center'"
39+
:class="computedAlign === 'left' ? 'text-left' : 'text-center'"
3540
>
3641
{{ label }}
3742
</div>
@@ -40,7 +45,7 @@ const description = computed(() => userDescription || frontmatter.value.descript
4045
'f-mt-xs': label,
4146
},
4247
h1 ? 'f-text-4xl font-bold' : 'f-text-3xl font-semibold',
43-
align === 'left' ? 'text-left' : 'text-center',
48+
computedAlign === 'left' ? 'text-left' : 'text-center',
4449
]" text-neutral mb-0
4550
>
4651
{{ title }}
@@ -49,7 +54,7 @@ const description = computed(() => userDescription || frontmatter.value.descript
4954
:class="[{
5055
'mt-0 f-text-2xl': h1,
5156
'f-mt-2xs f-text-xl': !h1,
52-
}, align === 'left' ? 'text-left' : 'text-center']"
57+
}, computedAlign === 'left' ? 'text-left' : 'text-center']"
5358
>
5459
{{ description }}
5560
</p>

packages/nimiq-vitepress-theme/src/layout/PageContent.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import CopyButtonGroup from '../components/CopyButtonGroup.vue'
33
import { useBreadcrumbs } from '../composables/useBreadcrumbs'
44
import { useSecondarySidebar } from '../composables/useSecondarySidebar'
55
import { useSourceCode } from '../composables/useSourceCode'
6+
import { humanizeText } from '../utils/textUtils'
67
import DocNavigation from './DocNavigation.vue'
78
import '../assets/code-blocks.css'
89
import '../assets/typography.css'
@@ -31,7 +32,7 @@ const { showSourceCode, showCopyMarkdown, editUrl, sourceCodeUrl, sourceCodeLabe
3132
<ul v-if="showBreadcrumbs" flex="~ items-center gap-12">
3233
<li v-for="({ text, icon }, i) in breadcrumbs" :key="text" contents w-max>
3334
<div v-if="icon" :class="icon" />
34-
<span nq-label f-text-2xs w-max>{{ text }}</span>
35+
<span nq-label f-text-2xs w-max>{{ humanizeText(text) }}</span>
3536
<div v-if="i < breadcrumbs.length - 1" i-nimiq:chevron-right text="neutral-700 9" />
3637
</li>
3738
</ul>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Humanizes text by removing backticks and converting camelCase/snake_case to readable format with proper capitalization
3+
*/
4+
export function humanizeText(text: string): string {
5+
// Remove backticks
6+
let result = text.replace(/`/g, '')
7+
8+
// Convert camelCase to readable format
9+
// Insert space before uppercase letters that follow lowercase letters
10+
result = result.replace(/([a-z])([A-Z])/g, '$1 $2')
11+
12+
// Convert snake_case and kebab-case to readable format
13+
result = result.replace(/[_-]+/g, ' ')
14+
15+
// Clean up multiple spaces and trim
16+
result = result.replace(/\s+/g, ' ').trim()
17+
18+
// Capitalize each word
19+
result = result.replace(/\b\w/g, char => char.toUpperCase())
20+
21+
return result
22+
}

0 commit comments

Comments
 (0)