@vite-pwa/vitepress 0.2.2 → 0.2.3

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.
package/dist/index.cjs CHANGED
@@ -106,10 +106,8 @@ function withUserConfig(config) {
106
106
  if (typeof allowlist !== "undefined") {
107
107
  const base = siteConfig.site.base ?? "/";
108
108
  for (const page of siteConfig.pages) {
109
- if (page === "index.md")
110
- allowlist.push(new RegExp(`^${base}(.html)?$`));
111
- else
112
- allowlist.push(new RegExp(`^${base}${page.replace(/\.md$/, "(.html)?")}$`));
109
+ const regex = page === "index.md" ? escapeStringRegexp(base) : escapeStringRegexp(`${base}${page.replace(/\.md$/, "")}`);
110
+ allowlist.push(new RegExp(`^${regex}(\\.html)?$`));
113
111
  }
114
112
  }
115
113
  await api.generateSW();
@@ -117,6 +115,9 @@ function withUserConfig(config) {
117
115
  };
118
116
  return vitePressConfig;
119
117
  }
118
+ function escapeStringRegexp(value) {
119
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
120
+ }
120
121
 
121
122
  async function withPwa(config) {
122
123
  if (typeof config === "function") {
package/dist/index.mjs CHANGED
@@ -104,10 +104,8 @@ function withUserConfig(config) {
104
104
  if (typeof allowlist !== "undefined") {
105
105
  const base = siteConfig.site.base ?? "/";
106
106
  for (const page of siteConfig.pages) {
107
- if (page === "index.md")
108
- allowlist.push(new RegExp(`^${base}(.html)?$`));
109
- else
110
- allowlist.push(new RegExp(`^${base}${page.replace(/\.md$/, "(.html)?")}$`));
107
+ const regex = page === "index.md" ? escapeStringRegexp(base) : escapeStringRegexp(`${base}${page.replace(/\.md$/, "")}`);
108
+ allowlist.push(new RegExp(`^${regex}(\\.html)?$`));
111
109
  }
112
110
  }
113
111
  await api.generateSW();
@@ -115,6 +113,9 @@ function withUserConfig(config) {
115
113
  };
116
114
  return vitePressConfig;
117
115
  }
116
+ function escapeStringRegexp(value) {
117
+ return value.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
118
+ }
118
119
 
119
120
  async function withPwa(config) {
120
121
  if (typeof config === "function") {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vite-pwa/vitepress",
3
3
  "type": "module",
4
- "version": "0.2.2",
4
+ "version": "0.2.3",
5
5
  "packageManager": "pnpm@8.9.0",
6
6
  "description": "Zero-config PWA for VitePress",
7
7
  "author": "antfu <anthonyfu117@hotmail.com>",