diff --git a/theme/src/client/components/VPDoc.vue b/theme/src/client/components/VPDoc.vue index 232c4430..624290b4 100644 --- a/theme/src/client/components/VPDoc.vue +++ b/theme/src/client/components/VPDoc.vue @@ -293,7 +293,7 @@ watch( @media (min-width: 960px) { .content { - padding: 0 32px 128px; + padding: 0 32px 88px; } } diff --git a/theme/src/client/components/VPEncryptForm.vue b/theme/src/client/components/VPEncryptForm.vue index 02c78678..2fa521f1 100644 --- a/theme/src/client/components/VPEncryptForm.vue +++ b/theme/src/client/components/VPEncryptForm.vue @@ -7,6 +7,10 @@ const { global, info } = defineProps<{ info?: string }>() +const emit = defineEmits<{ + (e: 'validate', isValidate: boolean): void +}>() + const { theme } = useData() const { compareGlobal, comparePage } = useEncryptCompare() @@ -29,6 +33,7 @@ async function onSubmit() { errorCode.value = 0 password.value = '' } + emit('validate', errorCode.value === 0) } @@ -44,8 +49,10 @@ async function onSubmit() { class="encrypt-input" :class="{ error: errorCode === 1 }" type="password" + autocomplete="off" :placeholder="theme.encryptPlaceholder ?? 'Enter Password'" @keyup.enter="onSubmit" + @focus="!password && (errorCode = 0)" @input="password && (errorCode = 0)" > @@ -83,9 +90,9 @@ async function onSubmit() { .encrypt-input { width: 100%; padding: 8px 12px 8px 32px; - background-color: transparent; - border: 1px solid var(--vp-c-border); - border-radius: 4px; + background-color: var(--vp-c-bg-soft); + border: 1px solid var(--vp-c-divider); + border-radius: 21px; outline: none; transition: border-color var(--vp-t-color), background-color var(--vp-t-color); } diff --git a/theme/src/client/components/VPEncryptPage.vue b/theme/src/client/components/VPEncryptPage.vue index 8043e248..1f4f8d9b 100644 --- a/theme/src/client/components/VPEncryptPage.vue +++ b/theme/src/client/components/VPEncryptPage.vue @@ -1,5 +1,6 @@ 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)) }) }