@docsector/docsector-reader 1.7.1 → 2.0.1

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.
@@ -1,59 +1,144 @@
1
- import pages from 'pages'
1
+ import { books } from 'virtual:docsector-books'
2
2
  import boot from 'pages/boot'
3
3
 
4
- const pagesRoutes = []
5
- for (const [path, page] of Object.entries(pages)) {
6
- const config = page.config
7
- if (config === null) {
8
- continue
4
+ const normalizeInternalLink = (linkTo) => {
5
+ const normalized = String(linkTo || '').trim()
6
+ if (normalized.length === 0) {
7
+ return '/'
9
8
  }
10
9
 
11
- const topPage = config.type ?? 'manual'
10
+ return normalized.startsWith('/') ? normalized : `/${normalized}`
11
+ }
12
12
 
13
- // @ Construct children
14
- const children = [
15
- {
16
- path: '',
17
- redirect: (to) => `${to.path.replace(/\/$/, '')}/overview/`
18
- },
19
- {
20
- path: 'overview',
21
- component: () => import('components/DSubpage.vue'),
22
- meta: {
23
- status: config.status
24
- }
13
+ const normalizeRoutePath = (path) => {
14
+ const normalized = String(path || '')
15
+ .trim()
16
+ .replace(/^\/+/, '/')
17
+ .replace(/\/+$/, '')
18
+
19
+ if (normalized === '') {
20
+ return '/'
21
+ }
22
+
23
+ return normalized.startsWith('/') ? normalized : `/${normalized}`
24
+ }
25
+
26
+ const resolveInternalLinkBasePath = (linkTo) => {
27
+ const normalized = normalizeInternalLink(linkTo)
28
+ const withoutTrailingSlash = normalized.replace(/\/+$/, '')
29
+ const withoutSubpage = withoutTrailingSlash.replace(/\/(overview|showcase|vs)$/i, '')
30
+
31
+ return normalizeRoutePath(withoutSubpage || '/')
32
+ }
33
+
34
+ const routeConfigByPath = new Map()
35
+ for (const [bookId, book] of Object.entries(books || {})) {
36
+ const bookRoutes = book?.routes || {}
37
+
38
+ for (const [path, page] of Object.entries(bookRoutes)) {
39
+ const config = page?.config
40
+ if (config === null) {
41
+ continue
25
42
  }
26
- ]
27
- if (config?.subpages?.showcase === true) {
28
- children.push({
29
- path: 'showcase',
30
- component: () => import('components/DSubpage.vue'),
31
- meta: {
32
- status: config.status
33
- }
34
- })
43
+
44
+ const topPage = config?.book ?? config?.type ?? bookId ?? 'manual'
45
+ const routePath = normalizeRoutePath('/' + topPage + path)
46
+
47
+ routeConfigByPath.set(routePath, config || {})
35
48
  }
36
- if (config?.subpages?.vs === true) {
37
- children.push({
38
- path: 'vs',
39
- component: () => import('components/DSubpage.vue'),
49
+ }
50
+
51
+ const pagesRoutes = []
52
+ for (const [bookId, book] of Object.entries(books || {})) {
53
+ const bookRoutes = book?.routes || {}
54
+
55
+ for (const [path, page] of Object.entries(bookRoutes)) {
56
+ const rawConfig = page.config
57
+ if (rawConfig === null) {
58
+ continue
59
+ }
60
+
61
+ const config = rawConfig || {}
62
+ const menu = (typeof config.menu === 'object' && config.menu !== null) ? config.menu : {}
63
+ const subpages = {
64
+ showcase: config?.subpages?.showcase === true,
65
+ vs: config?.subpages?.vs === true
66
+ }
67
+
68
+ const topPage = config.book ?? config.type ?? bookId ?? 'manual'
69
+ const hasInternalLink = typeof config?.link?.to === 'string' && config.link.to.trim().length > 0
70
+ const internalLinkTo = hasInternalLink ? normalizeInternalLink(config.link.to) : null
71
+ const linkedConfig = hasInternalLink
72
+ ? routeConfigByPath.get(resolveInternalLinkBasePath(config.link.to))
73
+ : null
74
+ const icon = config.icon ?? linkedConfig?.icon
75
+ const status = typeof config.status === 'string'
76
+ ? config.status
77
+ : (typeof linkedConfig?.status === 'string' ? linkedConfig.status : 'done')
78
+
79
+ // @ Construct children
80
+ const children = hasInternalLink
81
+ ? [
82
+ {
83
+ path: '',
84
+ redirect: () => internalLinkTo
85
+ },
86
+ {
87
+ path: 'overview',
88
+ redirect: () => internalLinkTo
89
+ }
90
+ ]
91
+ : [
92
+ {
93
+ path: '',
94
+ redirect: (to) => `${to.path.replace(/\/$/, '')}/overview/`
95
+ },
96
+ {
97
+ path: 'overview',
98
+ component: () => import('components/DSubpage.vue'),
99
+ meta: {
100
+ status
101
+ }
102
+ }
103
+ ]
104
+
105
+ if (!hasInternalLink && subpages.showcase === true) {
106
+ children.push({
107
+ path: 'showcase',
108
+ component: () => import('components/DSubpage.vue'),
109
+ meta: {
110
+ status
111
+ }
112
+ })
113
+ }
114
+ if (!hasInternalLink && subpages.vs === true) {
115
+ children.push({
116
+ path: 'vs',
117
+ component: () => import('components/DSubpage.vue'),
118
+ meta: {
119
+ status
120
+ }
121
+ })
122
+ }
123
+
124
+ // @ Push route to pageRoutes
125
+ pagesRoutes.push({
126
+ path: '/' + topPage + path,
127
+ component: () => import('layouts/DefaultLayout.vue'),
40
128
  meta: {
41
- status: config.status
42
- }
129
+ ...config,
130
+ icon,
131
+ status,
132
+ menu,
133
+ subpages,
134
+ data: page.data,
135
+ book: topPage,
136
+ // legacy compatibility
137
+ type: topPage
138
+ },
139
+ children
43
140
  })
44
141
  }
45
-
46
- // @ Push route to pageRoutes
47
- pagesRoutes.push({
48
- path: '/' + topPage + path,
49
- component: () => import('layouts/DefaultLayout.vue'),
50
- meta: {
51
- ...config,
52
- data: page.data,
53
- type: topPage
54
- },
55
- children
56
- })
57
142
  }
58
143
 
59
144
  const routes = [
@@ -67,6 +152,7 @@ const routes = [
67
152
  icon: 'home',
68
153
  menu: {},
69
154
  status: 'done',
155
+ book: 'home',
70
156
  type: 'home',
71
157
  subpages: {
72
158
  showcase: false,