| Server IP : 185.208.173.17 / Your IP : 87.236.161.98 Web Server : Microsoft-IIS/10.0 System : Windows NT SRV8576125506 10.0 build 26100 (Windows Server 2016) AMD64 User : IUSR ( 0) PHP Version : 7.4.13 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/inetpub/wwwroot/parsmega.nuxt/node_modules/@nuxtjs/sitemap/lib/ |
Upload File : |
const { Minimatch } = require('minimatch')
/**
* Exclude routes by matching glob patterns on url
*
* @param {string[]} patterns
* @param {Array} routes
* @returns {Array}
*/
function excludeRoutes(patterns, routes) {
patterns.forEach((pattern) => {
const minimatch = new Minimatch(pattern)
minimatch.negate = true
routes = routes.filter(({ url }) => minimatch.match(url))
})
return routes
}
/**
* Get static routes from Nuxt router and ignore dynamic routes
*
* @param {Object} router
* @returns {Array}
*/
function getStaticRoutes(router) {
return flattenStaticRoutes(router)
}
/**
* Recursively flatten all static routes and their nested routes
*
* @param {Object} router
* @param {string} path
* @param {Array} routes
* @returns {Array}
*/
function flattenStaticRoutes(router, path = '', routes = []) {
router.forEach((route) => {
// Skip dynamic routes
if ([':', '*'].some((c) => route.path.includes(c))) {
return
}
// Nested routes
if (route.children) {
return flattenStaticRoutes(route.children, path + route.path + '/', routes)
}
// Normalize url (without trailing slash)
route.url = path.length && !route.path.length ? path.slice(0, -1) : path + route.path
routes.push(route)
})
return routes
}
module.exports = { excludeRoutes, getStaticRoutes }