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ACnF,KAGE,EAAQ,MAEV,KAAK,oBAAoB,CACvB,KAAM,EAAQ,SACd,OAAA,CAAS,EAAK,EAAK,GACjB,EAAM,IAAI,UACP,MAAK,GAAU,cAAc,EAAS,EAAQ,KAC9C,MAAK,GAAW,EAAQ,WACxB,MAAK,IACJ,EAAI,UAAU,eAAgB,sBAC9B,EAAI,UAAU,mBAAoB,QAClC,EAAI,IAAI,EAAI,IACX,OAAM,IACP,EAAK,EAAG,GAEd,IAKJ,KAAK,oBAAoB,CACvB,KAAM,EAAQ,KACd,OAAA,CAAS,EAAK,EAAK,GACjB,EAAM,IAAI,UACP,MAAK,GAAU,cAAc,EAAS,EAAQ,KAC9C,MAAK,GAAW,EAAQ,UACxB,MAAK,IACJ,EAAI,UAAU,eAAgB,mBAC9B,EAAI,IAAI,EAAG,IACV,OAAM,IACP,EAAK,EAAG,GAEd,GAEJ,CACF,EAoHA,OAAO,QAAQ,KAAO,QAAQ","file":"/npm/@ax2/sitemap-module@1.0.0/lib/module.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@ax2/sitemap-module@1.0.0/lib/module.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","const { Minimatch } = require('minimatch')\nconst sm = require('sitemap')\nconst isHTTPS = require('is-https')\nconst unionBy = require('lodash.unionby')\nconst path = require('path')\nconst fs = require('fs-extra')\nconst AsyncCache = require('async-cache')\nconst consola = require('consola')\nconst { promisify } = require('util')\nconst { hostname } = require('os')\n\nmodule.exports = function module (moduleOptions) {\n  const sitemaps = Array.isArray(this.options.sitemap) ? this.options.sitemap : [this.options.sitemap]\n\n  const defaults = {\n    path: 'sitemap.xml',\n    hostname: this.options.build.publicPath || undefined,\n    exclude: [],\n    routes: this.options.generate.routes || [],\n    cacheTime: 1000 * 60 * 15,\n    filter: undefined,\n    gzip: false,\n    defaults: {}\n  }\n\n  // test configuration to make sure pathnames are unique\n  if (sitemaps.length > 1) {\n    checkPathnamesValidity(sitemaps, defaults.path)\n  }\n\n  for (let i = 0; i < sitemaps.length; i++) {\n    const options = Object.assign({}, defaults, sitemaps[i], moduleOptions)\n    options.pathGzip = options.gzip ? `${options.path}.gz` : options.path\n\n    // sitemap-routes.json is written to dist dir on \"build\" mode\n    const jsonStaticRoutesPath = !this.options.dev ? path.resolve(this.options.buildDir, path.join('dist', 'sitemap-routes.json')) : null\n\n    let staticRoutes = fs.readJsonSync(jsonStaticRoutesPath, { throws: false })\n    let cache = null\n\n    // On run cmd \"start\" or \"generate [--no-build]\"\n    if (staticRoutes) {\n      // Create a cache for routes\n      cache = createCache(staticRoutes, options)\n\n      // On server ready, hydrate cache\n      this.nuxt.hook('listen', () => {\n        cache.get('routes')\n      })\n    }\n\n    // On extend routes\n    this.extendRoutes(routes => {\n      // Get all static routes and ignore dynamic routes\n      let staticRoutes = flattenRoutes(routes)\n        .filter(r => !r.includes(':') && !r.includes('*'))\n\n      // Exclude routes\n      options.exclude.forEach(pattern => {\n        const minimatch = new Minimatch(pattern)\n        minimatch.negate = true\n        staticRoutes = staticRoutes.filter(route => minimatch.match(route))\n      })\n\n      // Create a cache for routes\n      cache = createCache(staticRoutes, options)\n\n      if (!this.options.dev) {\n        // Save static routes\n        fs.ensureDirSync(path.resolve(this.options.buildDir, 'dist'))\n        fs.writeJsonSync(jsonStaticRoutesPath, staticRoutes)\n      }\n    })\n\n    if (options.generate) {\n      consola.warn('The option `sitemap.generate` isn\\'t needed anymore')\n    }\n\n    // Generate sitemap.xml in dist\n    this.nuxt.hook('generate:done', async () => {\n      consola.info('Generating sitemaps')\n      const routes = await cache.get('routes')\n      const sitemap = await createSitemap(options, routes)\n      const xml = await sitemap.toXML()\n      const xmlGeneratePath = path.resolve(this.options.generate.dir, options.path)\n      await fs.ensureFile(xmlGeneratePath)\n      await fs.writeFile(xmlGeneratePath, xml)\n      consola.success('Generated', xmlGeneratePath.replace(this.options.generate.dir, ''))\n      if (options.gzip) {\n        const gzip = await sitemap.toGzip()\n        const gzipGeneratePath = path.resolve(this.options.generate.dir, options.pathGzip)\n        await fs.ensureFile(gzipGeneratePath)\n        await fs.writeFile(gzipGeneratePath, gzip)\n        consola.success('Generated', gzipGeneratePath.replace(this.options.generate.dir, ''))\n      }\n    })\n\n    if (options.gzip) {\n      // Add server middleware for sitemap.xml.gz\n      this.addServerMiddleware({\n        path: options.pathGzip,\n        handler (req, res, next) {\n          cache.get('routes')\n            .then(routes => createSitemap(options, routes, req))\n            .then(sitemap => sitemap.toGzip())\n            .then(gzip => {\n              res.setHeader('Content-Type', 'application/x-gzip')\n              res.setHeader('Content-Encoding', 'gzip')\n              res.end(gzip)\n            }).catch(err => {\n              next(err)\n            })\n        }\n      })\n    }\n\n    // Add server middleware for sitemap.xml\n    this.addServerMiddleware({\n      path: options.path,\n      handler (req, res, next) {\n        cache.get('routes')\n          .then(routes => createSitemap(options, routes, req))\n          .then(sitemap => sitemap.toXML())\n          .then(xml => {\n            res.setHeader('Content-Type', 'application/xml')\n            res.end(xml)\n          }).catch(err => {\n            next(err)\n          })\n      }\n    })\n  }\n}\n\n// Initialize a AsyncCache instance for\nfunction createCache (staticRoutes, options) {\n  let cache = new AsyncCache({\n    maxAge: options.cacheTime,\n    load (_, callback) {\n      promisifyRoute(options.routes)\n        .then(routes => routesUnion(staticRoutes, routes))\n        .then(routes => {\n          callback(null, routes)\n        })\n        .catch(err => {\n          callback(err)\n        })\n    }\n  })\n  cache.get = promisify(cache.get)\n\n  return cache\n}\n\n// Initialize a fresh sitemap instance\nfunction createSitemap (options, routes, req) {\n  const sitemapConfig = {}\n\n  // Set sitemap hostname\n  sitemapConfig.hostname = options.hostname ||\n    (req && `${isHTTPS(req) ? 'https' : 'http'}://${req.headers.host}`) || `http://${hostname()}`\n\n  routes = routes.map(route => Object.assign({}, options.defaults, route))\n\n  // Enable filter function for each declared route\n  if (typeof options.filter === 'function') {\n    routes = options.filter({ routes, options: Object.assign({}, options, sitemapConfig) })\n  }\n\n  // Set urls and ensure they are unique\n  sitemapConfig.urls = [...new Set(routes)]\n\n  // Set cacheTime\n  sitemapConfig.cacheTime = options.cacheTime || 0\n\n  // Create promisified instance and return\n  const sitemap = sm.createSitemap(sitemapConfig)\n  sitemap.toXML = promisify(sitemap.toXML)\n\n  return sitemap\n}\n\n// Borrowed from nuxt/common/utils\nfunction promisifyRoute (fn) {\n  // If routes is an array\n  if (Array.isArray(fn)) {\n    return Promise.resolve(fn)\n  }\n  // If routes is a function expecting a callback\n  if (fn.length === 1) {\n    return new Promise((resolve, reject) => {\n      fn(function (err, routeParams) {\n        if (err) {\n          reject(err)\n        }\n        resolve(routeParams)\n      })\n    })\n  }\n  let promise = fn()\n  if (!promise || (!(promise instanceof Promise) && (typeof promise.then !== 'function'))) {\n    promise = Promise.resolve(promise)\n  }\n  return promise\n}\n\n// Throw Errors if sitemaps paths have mistakes\nfunction checkPathnamesValidity (sitemaps, defaultsPath = 'sitemap.xml') {\n  // Make sure that multiple sitemaps won't have pathname 'sitemap.xml'\n  if (sitemaps.filter(sitemap => !sitemap.path || sitemap.path === defaultsPath).length > 1) {\n    throw new Error('Please specify different pathnames for your sitemaps')\n  }\n  // Make sure that multiple sitemaps don't have the same pathname\n  for (let i = 0; i < sitemaps.length; i++) {\n    if (sitemaps.find(sitemap => {\n      return (sitemap.path === sitemaps[i].path) && sitemaps.indexOf(sitemap) !== i\n    })) {\n      throw new Error('Your sitemaps need unique pathnames')\n    }\n  }\n}\n// Join static and options-defined routes into single array\nfunction routesUnion (staticRoutes, optionsRoutes) {\n  // Make sure any routes passed as strings are converted to objects with url properties\n  staticRoutes = staticRoutes.map(ensureRouteIsObject)\n  optionsRoutes = optionsRoutes.map(ensureRouteIsObject)\n  // Add static routes to options routes, discarding any defined in options\n  return unionBy(optionsRoutes, staticRoutes, 'url')\n}\n\n// Make sure a passed route is an object\nfunction ensureRouteIsObject (route) {\n  return typeof route === 'object' ? route : { url: route }\n}\n\n// Recursively flatten all routes and their child-routes\nfunction flattenRoutes (router, path = '', routes = []) {\n  router.forEach(r => {\n    if (r.children) {\n      flattenRoutes(r.children, path + r.path + '/', routes)\n    }\n    if (r.path !== '') {\n      routes.push(path + r.path)\n    }\n  })\n  return routes\n}\n\nmodule.exports.meta = require('../package.json')\n"]}