+
diff --git a/theme/src/client/components/VPPage.vue b/theme/src/client/components/VPPage.vue
index 81815593..4274ffb3 100644
--- a/theme/src/client/components/VPPage.vue
+++ b/theme/src/client/components/VPPage.vue
@@ -1,7 +1,17 @@
+
+
-
-
-
+
+
+
+
+
+
diff --git a/theme/src/client/composables/encrypt-data.ts b/theme/src/client/composables/encrypt-data.ts
index 21a26420..c6af00ed 100644
--- a/theme/src/client/composables/encrypt-data.ts
+++ b/theme/src/client/composables/encrypt-data.ts
@@ -1,5 +1,6 @@
import type { Ref } from 'vue'
import { encrypt as rawEncrypt } from '@internal/encrypt'
+import { decodeData } from '@vuepress/helper/client'
import { ref } from 'vue'
export type EncryptConfig = readonly [
@@ -35,14 +36,15 @@ export function useEncryptData(): EncryptRef {
function resolveEncryptData(
[global, separator, admin, matches, rules]: EncryptConfig,
): EncryptData {
+ const keys = matches.map(match => decodeData(match))
return {
global,
separator,
- matches,
+ matches: keys,
admins: admin.split(separator),
ruleList: Object.keys(rules).map(key => ({
key,
- match: matches[key] as string,
+ match: keys[key] as string,
rules: rules[key].split(separator),
})),
}
diff --git a/theme/src/client/composables/encrypt.ts b/theme/src/client/composables/encrypt.ts
index 35c8afde..c0f0349c 100644
--- a/theme/src/client/composables/encrypt.ts
+++ b/theme/src/client/composables/encrypt.ts
@@ -4,6 +4,7 @@ import { hasOwn, useSessionStorage } from '@vueuse/core'
import { compare, genSaltSync } from 'bcrypt-ts/browser'
import { computed, inject, provide } from 'vue'
import { useRoute } from 'vuepress/client'
+import { removeLeadingSlash } from 'vuepress/shared'
import { useData } from './data.js'
import { useEncryptData } from './encrypt-data.js'
@@ -73,12 +74,12 @@ function toMatch(match: string, pagePath: string, filePathRelative: string | nul
const relativePath = filePathRelative || ''
if (match[0] === '^') {
const regex = createMatchRegex(match)
- return regex.test(pagePath) || (relativePath && regex.test(relativePath))
+ return regex.test(pagePath) || regex.test(relativePath)
}
if (match.endsWith('.md'))
return relativePath && relativePath.endsWith(match)
- return pagePath.startsWith(match) || relativePath.startsWith(match)
+ return pagePath.startsWith(match) || relativePath.startsWith(removeLeadingSlash(match))
}
export function setupEncrypt(): void {
diff --git a/theme/src/node/prepare/prepareEncrypt.ts b/theme/src/node/prepare/prepareEncrypt.ts
index 3cba5539..1f0f8a98 100644
--- a/theme/src/node/prepare/prepareEncrypt.ts
+++ b/theme/src/node/prepare/prepareEncrypt.ts
@@ -2,7 +2,8 @@ import type { App } from 'vuepress'
import type { Page } from 'vuepress/core'
import type { EncryptOptions, ThemePageData } from '../../shared/index.js'
import type { FsCache } from '../utils/index.js'
-import { isNumber, isString, toArray } from '@pengzhanbo/utils'
+import { isEmptyObject, isNumber, isString, toArray } from '@pengzhanbo/utils'
+import { encodeData, removeLeadingSlash } from '@vuepress/helper'
import { getThemeConfig } from '../loadConfig/index.js'
import { createFsCache, genEncrypt, hash, perf, resolveContent, writeTemp } from '../utils/index.js'
@@ -15,6 +16,7 @@ export type EncryptConfig = readonly [
]
const isStringLike = (value: unknown): boolean => isString(value) || isNumber(value)
+
const separator = ':'
let contentHash = ''
let fsCache: FsCache<[string, EncryptConfig]> | null = null
@@ -52,14 +54,19 @@ function resolveEncrypt(encrypt?: EncryptOptions): EncryptConfig {
.join(separator)
: ''
- const rules: Record
= {}
- const keys = Object.keys(encrypt?.rules ?? {})
+ const encryptRules = Object.keys(encrypt?.rules ?? {}).reduce((acc, key) => {
+ acc[encodeData(key)] = encrypt!.rules![key]
+ return acc
+ }, {} as Record)
- if (encrypt?.rules) {
- Object.keys(encrypt.rules).forEach((key) => {
+ const rules: Record = {}
+ const keys = Object.keys(encryptRules)
+
+ if (!isEmptyObject(encryptRules)) {
+ Object.keys(encryptRules).forEach((key) => {
const index = keys.indexOf(key)
- rules[String(index)] = toArray(encrypt.rules![key])
+ rules[String(index)] = toArray(encryptRules[key])
.filter(isStringLike)
.map(item => genEncrypt(item))
.join(separator)
@@ -82,11 +89,11 @@ export function isEncryptPage(page: Page, encrypt?: EncryptOption
const relativePath = page.data.filePathRelative || ''
if (match[0] === '^') {
const regex = new RegExp(match)
- return regex.test(page.path) || (relativePath && regex.test(relativePath))
+ return regex.test(page.path) || regex.test(relativePath)
}
if (match.endsWith('.md'))
- return relativePath && relativePath.endsWith(match)
+ return relativePath.endsWith(match)
- return page.path.startsWith(match) || relativePath.startsWith(match)
+ return page.path.startsWith(match) || relativePath.startsWith(removeLeadingSlash(match))
})
}