Skip to content

Commit fed5a83

Browse files
committed
feat: add configurable footer suggestChanges
1 parent 84155da commit fed5a83

File tree

7 files changed

+80
-3
lines changed

7 files changed

+80
-3
lines changed

docs/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export default defineConfig(() => ({
2626
...NimiqVitepressVitePlugin({
2727
repoURL: 'https://github.com/onmax/nimiq-ui',
2828
contentPath: 'docs',
29+
suggestChanges: ctx => `Edit [${ctx.path}](https://github.com/onmax/nimiq-ui/blob/main/docs/${ctx.path})`,
2930
}),
3031
],
3132
}))
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { useData } from 'vitepress'
2+
import { computed } from 'vue'
3+
import { useNimiqConfig } from './useNimiqConfig'
4+
import { useSourceCode } from './useSourceCode'
5+
6+
export function useFooter() {
7+
const { page, frontmatter } = useData()
8+
const nimiqConfig = useNimiqConfig()
9+
const { editUrl } = useSourceCode()
10+
11+
const suggestChangesText = computed(() => {
12+
// Frontmatter takes priority
13+
const fmValue = frontmatter.value.suggestChanges
14+
if (fmValue === false)
15+
return null
16+
17+
if (typeof fmValue === 'string')
18+
return fmValue
19+
20+
// Check global config
21+
const configValue = nimiqConfig.suggestChanges
22+
if (configValue === false)
23+
return null
24+
25+
if (typeof configValue === 'string')
26+
return configValue
27+
28+
if (typeof configValue === 'function') {
29+
const result = configValue({ path: page.value.filePath })
30+
return result || null
31+
}
32+
33+
// Default fallback
34+
return 'Suggest changes on this page'
35+
})
36+
37+
return {
38+
suggestChangesText,
39+
editUrl,
40+
}
41+
}

packages/nimiq-vitepress-theme/src/composables/useNimiqConfig.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
declare const __NIMIQ_VITEPRESS_CONFIG__: {
22
repoURL?: string
33
contentPath?: string
4+
suggestChanges?: false | string | ((options: { path: string }) => string)
45
} | undefined
56

67
export interface NimiqVitepressConfig {
78
repoURL?: string
89
contentPath?: string
10+
suggestChanges?: false | string | ((options: { path: string }) => string)
911
}
1012

1113
export function useNimiqConfig(): NimiqVitepressConfig {
@@ -18,5 +20,6 @@ export function useNimiqConfig(): NimiqVitepressConfig {
1820
return {
1921
repoURL: undefined,
2022
contentPath: '',
23+
suggestChanges: undefined,
2124
}
2225
}

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
<script setup lang="ts">
2+
import { computed } from 'vue'
23
import { useBreadcrumbs } from '../composables/useBreadcrumbs'
4+
import { useFooter } from '../composables/useFooter'
35
import { useSecondarySidebar } from '../composables/useSecondarySidebar'
46
import { useSourceCode } from '../composables/useSourceCode'
7+
import { parseInlineMarkdown } from '../utils/markdownUtils'
58
import { humanizeText } from '../utils/textUtils'
69
import DocNavigation from './DocNavigation.vue'
710
import '../assets/code-blocks.css'
@@ -12,7 +15,13 @@ const { breadcrumbs, showBreadcrumbs } = useBreadcrumbs()
1215
1316
const { showSecondarySidebar } = useSecondarySidebar()
1417
15-
const { showSourceCode, editUrl, sourceCodeUrl, sourceCodeLabel } = useSourceCode()
18+
const { showSourceCode, sourceCodeUrl, sourceCodeLabel } = useSourceCode()
19+
20+
const { suggestChangesText, editUrl } = useFooter()
21+
22+
const parsedSuggestChanges = computed(() =>
23+
suggestChangesText.value ? parseInlineMarkdown(suggestChangesText.value) : null,
24+
)
1625
</script>
1726

1827
<template>
@@ -58,10 +67,11 @@ const { showSourceCode, editUrl, sourceCodeUrl, sourceCodeLabel } = useSourceCod
5867
<DocNavigation />
5968

6069
<div flex="~ justify-between items-center" f-mt-lg f-text-xs>
61-
<a :href="editUrl" target="_blank" rel="noopener" op-70 hover:opacity-100 transition-opacity flex="~ items-center gap-3">
62-
<span>Suggest changes on this page</span>
70+
<a v-if="parsedSuggestChanges" :href="editUrl" target="_blank" rel="noopener" op-70 hover:opacity-100 transition-opacity flex="~ items-center gap-3">
71+
<span v-html="parsedSuggestChanges" />
6372
<div i-nimiq:arrow-right text="neutral-700 12" />
6473
</a>
74+
<div v-else />
6575
<span text-neutral-600 font-normal>Built with the <a href="https://onmax.github.io/nimiq-ui/vitepress-theme/" un-text-neutral-700 target="_blank" rel="noopener" underline hover:text-neutral-800 transition-colors>Nimiq Vitepress Theme</a></span>
6676
</div>
6777
</div>

packages/nimiq-vitepress-theme/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface NimiqVitepressFrontmatter {
7171
copyMarkdown?: boolean
7272
wide?: boolean
7373
inlineActions?: boolean
74+
suggestChanges?: false | string
7475
}
7576

7677
export interface DefineThemeNqVpOptions {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function parseInlineMarkdown(text: string): string {
2+
return text
3+
// Links: [text](url)
4+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener" class="underline hover:text-neutral-800 transition-colors">$1</a>')
5+
// Bold: **text**
6+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
7+
// Italic: *text*
8+
.replace(/\*([^*]+)\*/g, '<em>$1</em>')
9+
// Code: `text`
10+
.replace(/`([^`]+)`/g, '<code>$1</code>')
11+
}

packages/nimiq-vitepress-theme/src/vite/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ export interface NimiqVitepressVitePluginOptions {
2020
*/
2121
contentPath?: string
2222

23+
/**
24+
* Customize the "Suggest changes" footer text
25+
* - false: hide the footer link
26+
* - string: use custom text (supports markdown)
27+
* - function: dynamic text based on page path
28+
*/
29+
suggestChanges?: false | string | ((options: { path: string }) => string)
30+
2331
/**
2432
* Git changelog configuration
2533
* If not provided, will use repoURL as default
@@ -31,6 +39,7 @@ export interface NimiqVitepressVitePluginOptions {
3139
export function NimiqVitepressVitePlugin({
3240
repoURL,
3341
contentPath = '',
42+
suggestChanges,
3443
gitChangelog,
3544
}: NimiqVitepressVitePluginOptions): Plugin[] {
3645
const { resolveId, configureServer, load, transform } = groupIconVitePlugin()
@@ -49,6 +58,7 @@ export function NimiqVitepressVitePlugin({
4958
const nimiqConfig = {
5059
repoURL,
5160
contentPath,
61+
suggestChanges,
5262
}
5363

5464
const plugins: Plugin[] = [

0 commit comments

Comments
 (0)