@life-and-dev/mdsite 0.0.12 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
<v-container class="d-flex justify-center align-center">
|
|
9
9
|
<div class="footer-links">
|
|
10
10
|
<v-btn
|
|
11
|
+
v-if="hasAboutPage"
|
|
11
12
|
:href="aboutLink"
|
|
12
13
|
variant="text"
|
|
13
14
|
color="on-surface-appbar"
|
|
@@ -16,9 +17,10 @@
|
|
|
16
17
|
About
|
|
17
18
|
</v-btn>
|
|
18
19
|
|
|
19
|
-
<v-divider vertical class="mx-2" />
|
|
20
|
+
<v-divider v-if="hasAboutPage && hasDisclaimerPage" vertical class="mx-2" />
|
|
20
21
|
|
|
21
22
|
<v-btn
|
|
23
|
+
v-if="hasDisclaimerPage"
|
|
22
24
|
:href="disclaimerLink"
|
|
23
25
|
variant="text"
|
|
24
26
|
color="on-surface-appbar"
|
|
@@ -27,7 +29,7 @@
|
|
|
27
29
|
Disclaimer
|
|
28
30
|
</v-btn>
|
|
29
31
|
|
|
30
|
-
<v-divider v-if="
|
|
32
|
+
<v-divider v-if="showEditDivider" vertical class="mx-2" />
|
|
31
33
|
|
|
32
34
|
<v-btn
|
|
33
35
|
v-if="editUrl"
|
|
@@ -47,15 +49,26 @@
|
|
|
47
49
|
|
|
48
50
|
<script setup lang="ts">
|
|
49
51
|
import { useSourceEdit } from '~/composables/useSourceEdit';
|
|
52
|
+
import { useSearchIndex } from '~/composables/useSearchIndex'
|
|
50
53
|
import { withBasePath } from '../../utils/base-url'
|
|
51
54
|
|
|
52
55
|
const appBaseURL = useRuntimeConfig().app.baseURL
|
|
53
56
|
const { getEditUrl } = useSourceEdit()
|
|
57
|
+
const { loadSearchIndex } = useSearchIndex()
|
|
58
|
+
const footerPagePaths = ref<string[]>([])
|
|
54
59
|
|
|
55
60
|
// Generate links to root content files
|
|
56
61
|
const aboutLink = computed(() => withBasePath('/about', appBaseURL))
|
|
57
62
|
const disclaimerLink = computed(() => withBasePath('/disclaimer', appBaseURL))
|
|
58
63
|
const editUrl = computed(() => getEditUrl())
|
|
64
|
+
const hasAboutPage = computed(() => footerPagePaths.value.includes('/about'))
|
|
65
|
+
const hasDisclaimerPage = computed(() => footerPagePaths.value.includes('/disclaimer'))
|
|
66
|
+
const showEditDivider = computed(() => editUrl.value && (hasAboutPage.value || hasDisclaimerPage.value))
|
|
67
|
+
|
|
68
|
+
onMounted(async () => {
|
|
69
|
+
const searchIndex = await loadSearchIndex()
|
|
70
|
+
footerPagePaths.value = searchIndex.map(entry => entry.path)
|
|
71
|
+
})
|
|
59
72
|
</script>
|
|
60
73
|
|
|
61
74
|
<style scoped>
|
|
@@ -48,6 +48,8 @@ export default defineNuxtConfig({
|
|
|
48
48
|
|
|
49
49
|
vite: {
|
|
50
50
|
build: {
|
|
51
|
+
// Disable esbuild CSS minify because it drops semicolons from nested Vuetify @layer rules, causing noisy warnings.
|
|
52
|
+
cssMinify: false,
|
|
51
53
|
rollupOptions: {
|
|
52
54
|
external: ['fs/promises', 'path']
|
|
53
55
|
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import fs from 'node:fs/promises'
|
|
2
|
+
import os from 'node:os'
|
|
3
|
+
import path from 'node:path'
|
|
4
|
+
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
|
6
|
+
|
|
7
|
+
import { generateNavigationJson, generateSearchIndexJson } from './generate-indices.js'
|
|
8
|
+
|
|
9
|
+
describe('generated content indices', () => {
|
|
10
|
+
const originalEnv = { ...process.env }
|
|
11
|
+
let tempDir: string
|
|
12
|
+
let contentDir: string
|
|
13
|
+
let publicDir: string
|
|
14
|
+
|
|
15
|
+
beforeEach(async () => {
|
|
16
|
+
process.env = { ...originalEnv }
|
|
17
|
+
tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'mdsite-indices-'))
|
|
18
|
+
contentDir = path.join(tempDir, 'content')
|
|
19
|
+
publicDir = path.join(tempDir, 'public')
|
|
20
|
+
await fs.mkdir(contentDir, { recursive: true })
|
|
21
|
+
process.env.CONTENT_DIR = contentDir
|
|
22
|
+
process.env.MDSITE_PUBLIC_DIR = publicDir
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
afterEach(async () => {
|
|
26
|
+
process.env = { ...originalEnv }
|
|
27
|
+
await fs.rm(tempDir, { force: true, recursive: true })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('falls back to markdown files when no menu exists', async () => {
|
|
31
|
+
await fs.writeFile(path.join(contentDir, 'index.md'), '# Home\n\nWelcome home.', 'utf8')
|
|
32
|
+
await fs.writeFile(path.join(contentDir, 'guide.md'), '# Guide\n\nUseful guide.', 'utf8')
|
|
33
|
+
|
|
34
|
+
await generateNavigationJson()
|
|
35
|
+
|
|
36
|
+
const navigation = JSON.parse(await fs.readFile(path.join(publicDir, '_navigation.json'), 'utf8'))
|
|
37
|
+
expect(navigation).toEqual(expect.arrayContaining([
|
|
38
|
+
expect.objectContaining({ path: '/', title: 'Home' }),
|
|
39
|
+
expect.objectContaining({ path: '/guide', title: 'Guide' }),
|
|
40
|
+
]))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('writes searchable markdown pages with excerpts', async () => {
|
|
44
|
+
await fs.writeFile(path.join(contentDir, 'guide.md'), '# Guide\n\nUseful guide content for search.', 'utf8')
|
|
45
|
+
|
|
46
|
+
await generateSearchIndexJson()
|
|
47
|
+
|
|
48
|
+
const searchIndex = JSON.parse(await fs.readFile(path.join(publicDir, '_search-index.json'), 'utf8'))
|
|
49
|
+
expect(searchIndex).toEqual([
|
|
50
|
+
expect.objectContaining({
|
|
51
|
+
excerpt: 'Useful guide content for search.',
|
|
52
|
+
path: '/guide',
|
|
53
|
+
title: 'Guide',
|
|
54
|
+
}),
|
|
55
|
+
])
|
|
56
|
+
})
|
|
57
|
+
})
|
|
@@ -31,6 +31,7 @@ function getSourceDir(): string {
|
|
|
31
31
|
* Get target public directory
|
|
32
32
|
*/
|
|
33
33
|
function getTargetDir(): string {
|
|
34
|
+
if (process.env.MDSITE_PUBLIC_DIR) return process.env.MDSITE_PUBLIC_DIR
|
|
34
35
|
return path.resolve(__dirname, '..', 'public')
|
|
35
36
|
}
|
|
36
37
|
|
|
@@ -325,6 +326,29 @@ function countNodes(nodes: MinimalTreeNode[]): number {
|
|
|
325
326
|
return count
|
|
326
327
|
}
|
|
327
328
|
|
|
329
|
+
async function buildFallbackNavigationTree(sourceDir: string): Promise<MinimalTreeNode[]> {
|
|
330
|
+
const markdownFiles = await getAllMarkdownFiles(sourceDir)
|
|
331
|
+
const nodes: MinimalTreeNode[] = []
|
|
332
|
+
|
|
333
|
+
for (const [order, filePath] of markdownFiles.sort().entries()) {
|
|
334
|
+
const content = await fs.readFile(filePath, 'utf-8')
|
|
335
|
+
const metadata = extractMarkdownMetadata(content)
|
|
336
|
+
const urlPath = filePathToUrlPath(filePath, sourceDir)
|
|
337
|
+
const title = metadata.title ?? path.basename(filePath, '.md')
|
|
338
|
+
|
|
339
|
+
nodes.push({
|
|
340
|
+
id: `${urlPath.split('/').filter(Boolean).pop() || 'home'}-${order}`,
|
|
341
|
+
title,
|
|
342
|
+
path: urlPath,
|
|
343
|
+
type: 'link',
|
|
344
|
+
description: metadata.description,
|
|
345
|
+
isPrimary: true
|
|
346
|
+
})
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
return nodes
|
|
350
|
+
}
|
|
351
|
+
|
|
328
352
|
/**
|
|
329
353
|
* Generate navigation JSON file
|
|
330
354
|
*/
|
|
@@ -343,9 +367,11 @@ export async function generateNavigationJson() {
|
|
|
343
367
|
try {
|
|
344
368
|
if (await fs.pathExists(menuPath)) {
|
|
345
369
|
const menuContent = await fs.readFile(menuPath, 'utf-8')
|
|
346
|
-
const menuItems = parseYaml(menuContent) as MenuItemType[]
|
|
347
|
-
|
|
348
|
-
|
|
370
|
+
const menuItems = parseYaml(menuContent) as MenuItemType[] | null
|
|
371
|
+
if (Array.isArray(menuItems) && menuItems.length > 0) {
|
|
372
|
+
const result = await processMenuItems(menuItems, '/')
|
|
373
|
+
tree = result.nodes
|
|
374
|
+
}
|
|
349
375
|
} else {
|
|
350
376
|
console.warn('⚠️ No _menu.yml or _menu.yaml found at:', menuPath)
|
|
351
377
|
}
|
|
@@ -353,6 +379,10 @@ export async function generateNavigationJson() {
|
|
|
353
379
|
console.error('Error building navigation tree:', error)
|
|
354
380
|
}
|
|
355
381
|
|
|
382
|
+
if (tree.length === 0) {
|
|
383
|
+
tree = await buildFallbackNavigationTree(sourceDir)
|
|
384
|
+
}
|
|
385
|
+
|
|
356
386
|
const targetDir = getTargetDir()
|
|
357
387
|
const outputPath = path.join(targetDir, '_navigation.json')
|
|
358
388
|
|