8000 Update index.js · bootstrap-vue/bootstrap-vue@a910295 · GitHub
[go: up one dir, main page]

Skip to content

Commit a910295

Browse files
committed
Update index.js
1 parent 41ff28b commit a910295

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

docs/utils/index.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,23 @@ export const getComponentName = component => kebabCase(component).replace(/{/g,
1919
export const getCleanComponentName = component => getComponentName(component).replace(/({|})/g, '')
2020

2121
export const parseUrl = value => {
22-
const anchor = document.createElement('a')
23-
anchor.href = value
22+
const $anchor = document.createElement('a')
23+
$anchor.href = value
2424

2525
// We need to add the anchor to the document to make sure the
2626
// `pathname` is correctly detected in any browser
27-
document.body.appendChild(anchor)
27+
document.body.appendChild($anchor)
2828

2929
const result = ['hash', 'host', 'hostname', 'pathname', 'port', 'protocol', 'search'].reduce(
3030
(result, prop) => {
31-
result[prop] = anchor[prop] || null
31+
result[prop] = $anchor[prop] || null
3232
return result
3333
},
3434
{}
3535
)
3636

3737
// Make sure to remove the anchor from document as soon as possible
38-
document.body.removeChild(anchor)
38+
document.body.removeChild($anchor)
3939

4040
// Normalize port
4141
if (!result.port && result.protocol) {
@@ -146,31 +146,31 @@ export const updateMetaTOC = (tocData = {}, meta = null) => {
146146
return tocData
147147
}
148148

149-
export const importAll = r => {
150-
const obj = {}
151-
152-
r.keys()
153-
.map(r)
154-
.map(m => m.meta || m)
155-
.map(m => ({
156-
slug:
157-
typeof m.slug === 'undefined' ? (m.title || '').replace(' ', '-').toLowerCase() : m.slug,
158-
...m
159-
}))
160-
.sort((a, b) => {
161-
if (a.slug < b.slug) return -1
162-
else if (a.slug > b.slug) return 1
163-
return 0
164-
})
165-
.forEach(m => {
166-
if (m.components) {
167-
// Normalize `meta.components` to array of objects form
168-
m.components = m.components.map(c => (typeof c === 'string' ? { component: c } : c))
169-
}
170-
obj[m.slug] = m
171-
})
172-
173-
return obj
149+
export const importAll = context => {
150+
// Get array of datas by keys from context
151+
const datas = context.keys().map(context)
152+
153+
return (
154+
datas
155+
// Filter out private datas
156+
.filter(data => !data.private)
157+
// Map meta information
158+
.map(data => data.meta || data)
159+
// Normalize meta information
160+
.map(meta => ({
161+
...meta,
162+
slug:
163+
meta.slug === undefined ? (meta.title || '').replace(' ', '-').toLowerCase() : meta.slug
164+
}))
165+
// Sort by slug
166+
.sort((a, b) => {
167+
if (a.slug < b.slug) return -1
168+
else if (a.slug > b.slug) return 1
169+
return 0
170+
})
171+
// Build one object keyed by slug
172+
.reduce((result, meta) => ({ ...result, [meta.slug]: meta }), {})
173+
)
174174
}
175175

176176
// Smooth Scroll handler methods

0 commit comments

Comments
 (0)
0