(config, vm)
| 240 | } |
| 241 | |
| 242 | export function init(config, vm) { |
| 243 | const isAuto = config.paths === 'auto'; |
| 244 | const paths = isAuto ? getAllPaths(vm.router) : config.paths; |
| 245 | |
| 246 | let namespaceSuffix = ''; |
| 247 | |
| 248 | // only in auto mode |
| 249 | if (paths.length && isAuto && config.pathNamespaces) { |
| 250 | const path = paths[0]; |
| 251 | |
| 252 | if (Array.isArray(config.pathNamespaces)) { |
| 253 | namespaceSuffix = |
| 254 | config.pathNamespaces.filter( |
| 255 | prefix => path.slice(0, prefix.length) === prefix |
| 256 | )[0] || namespaceSuffix; |
| 257 | } else if (config.pathNamespaces instanceof RegExp) { |
| 258 | const matches = path.match(config.pathNamespaces); |
| 259 | |
| 260 | if (matches) { |
| 261 | namespaceSuffix = matches[0]; |
| 262 | } |
| 263 | } |
| 264 | const isExistHome = paths.indexOf(namespaceSuffix + '/') === -1; |
| 265 | const isExistReadme = paths.indexOf(namespaceSuffix + '/README') === -1; |
| 266 | if (isExistHome && isExistReadme) { |
| 267 | paths.unshift(namespaceSuffix + '/'); |
| 268 | } |
| 269 | } else if (paths.indexOf('/') === -1 && paths.indexOf('/README') === -1) { |
| 270 | paths.unshift('/'); |
| 271 | } |
| 272 | |
| 273 | const expireKey = resolveExpireKey(config.namespace) + namespaceSuffix; |
| 274 | const indexKey = resolveIndexKey(config.namespace) + namespaceSuffix; |
| 275 | |
| 276 | const isExpired = localStorage.getItem(expireKey) < Date.now(); |
| 277 | |
| 278 | INDEXS = JSON.parse(localStorage.getItem(indexKey)); |
| 279 | |
| 280 | if (isExpired) { |
| 281 | INDEXS = {}; |
| 282 | } else if (!isAuto) { |
| 283 | return; |
| 284 | } |
| 285 | |
| 286 | const len = paths.length; |
| 287 | let count = 0; |
| 288 | |
| 289 | paths.forEach(path => { |
| 290 | if (INDEXS[path]) { |
| 291 | return count++; |
| 292 | } |
| 293 | |
| 294 | Docsify.get(vm.router.getFile(path), false, vm.config.requestHeaders).then( |
| 295 | result => { |
| 296 | INDEXS[path] = genIndex(path, result, vm.router, config.depth); |
| 297 | len === ++count && saveData(config.maxAge, expireKey, indexKey); |
| 298 | } |
| 299 | ); |
nothing calls this directly
no test coverage detected
searching dependent graphs…