From b773ac26b1b98016d4288f3eb96327a69e45d810 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tr=E1=BA=A7n=20=C4=90=E1=BB=A9c=20Nam?= Date: Thu, 6 Feb 2025 21:52:10 +0700 Subject: [PATCH] fix: hide content of password-protected pages in searching and rss --- quartz/i18n/locales/ar-SA.ts | 1 + quartz/i18n/locales/ca-ES.ts | 1 + quartz/i18n/locales/cs-CZ.ts | 1 + quartz/i18n/locales/de-DE.ts | 1 + quartz/i18n/locales/en-GB.ts | 1 + quartz/i18n/locales/en-US.ts | 1 + quartz/i18n/locales/es-ES.ts | 1 + quartz/i18n/locales/fa-IR.ts | 1 + quartz/i18n/locales/fr-FR.ts | 1 + quartz/i18n/locales/hu-HU.ts | 1 + quartz/i18n/locales/it-IT.ts | 1 + quartz/i18n/locales/ja-JP.ts | 1 + quartz/i18n/locales/ko-KR.ts | 1 + quartz/i18n/locales/nl-NL.ts | 1 + quartz/i18n/locales/pl-PL.ts | 1 + quartz/i18n/locales/pt-BR.ts | 1 + quartz/i18n/locales/ro-RO.ts | 1 + quartz/i18n/locales/ru-RU.ts | 1 + quartz/i18n/locales/uk-UA.ts | 1 + quartz/i18n/locales/vi-VN.ts | 1 + quartz/i18n/locales/zh-CN.ts | 1 + quartz/plugins/emitters/contentIndex.ts | 9 +++++---- quartz/plugins/transformers/description.ts | 8 ++++++-- 23 files changed, 32 insertions(+), 6 deletions(-) diff --git a/quartz/i18n/locales/ar-SA.ts b/quartz/i18n/locales/ar-SA.ts index 0b059bab6a7d8..22994702c00ec 100644 --- a/quartz/i18n/locales/ar-SA.ts +++ b/quartz/i18n/locales/ar-SA.ts @@ -94,6 +94,7 @@ export default { wrongPassword: "خاطئة. يرجى إعادة إدخال كلمة المرور لفتح القفل:", noPayload: "حمولة مشفرة.", decrypting: "جاري فك التشفير...", + defaultDescription: "هذه صفحة مشفرة", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/ca-ES.ts b/quartz/i18n/locales/ca-ES.ts index 8604a12398dc5..f1e28e932d539 100644 --- a/quartz/i18n/locales/ca-ES.ts +++ b/quartz/i18n/locales/ca-ES.ts @@ -90,6 +90,7 @@ export default { wrongPassword: "Contrasenya incorrecta. Introduïu de nou la contrasenya per desbloquejar:", noPayload: "No hi ha càrrega útil xifrada.", decrypting: "Desxifrant...", + defaultDescription: "Aquesta és una pàgina xifrada", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/cs-CZ.ts b/quartz/i18n/locales/cs-CZ.ts index e4686a67b1179..9ea1ecfe67a8d 100644 --- a/quartz/i18n/locales/cs-CZ.ts +++ b/quartz/i18n/locales/cs-CZ.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Nesprávné heslo. Zadejte heslo znovu pro odemknutí:", noPayload: "Není žádné šifrované užitečné zatížení.", decrypting: "Dekódování...", + defaultDescription: "Toto je šifrovaná stránka", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/de-DE.ts b/quartz/i18n/locales/de-DE.ts index c61a5b265d24b..1e871323c0d41 100644 --- a/quartz/i18n/locales/de-DE.ts +++ b/quartz/i18n/locales/de-DE.ts @@ -91,6 +91,7 @@ export default { "Falsches Passwort. Bitte geben Sie das Passwort erneut ein, um zu entsperren:", noPayload: "Keine verschlüsselte Nutzlast.", decrypting: "Entschlüsseln...", + defaultDescription: "Dies ist eine verschlüsselte Seite", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/en-GB.ts b/quartz/i18n/locales/en-GB.ts index a0ac07b9ff0ad..0d63017fab9f0 100644 --- a/quartz/i18n/locales/en-GB.ts +++ b/quartz/i18n/locales/en-GB.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Wrong password. Please re-enter passsword to unlock:", noPayload: "No encrypted payload.", decrypting: "Decrypting...", + defaultDescription: "This is encrypted page", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/en-US.ts b/quartz/i18n/locales/en-US.ts index 23cd1db496838..5e2ed062e2cf4 100644 --- a/quartz/i18n/locales/en-US.ts +++ b/quartz/i18n/locales/en-US.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Wrong password. Please re-enter passsword to unlock:", noPayload: "No encrypted payload.", decrypting: "Decrypting...", + defaultDescription: "This is encrypted page", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/es-ES.ts b/quartz/i18n/locales/es-ES.ts index f2acfd354918d..b4fe65f0ab948 100644 --- a/quartz/i18n/locales/es-ES.ts +++ b/quartz/i18n/locales/es-ES.ts @@ -90,6 +90,7 @@ export default { wrongPassword: "Contraseña incorrecta. Vuelva a introducir la contraseña para desbloquear:", noPayload: "No hay ninguna carga útil cifrada.", decrypting: "Descifrando...", + defaultDescription: "Esta es una página encriptada", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/fa-IR.ts b/quartz/i18n/locales/fa-IR.ts index c051175b246b1..9b68b868da304 100644 --- a/quartz/i18n/locales/fa-IR.ts +++ b/quartz/i18n/locales/fa-IR.ts @@ -90,6 +90,7 @@ export default { wrongPassword: "رمز عبور اشتباه است. لطفا رمز عبور را دوباره وارد کنید تا قفل باز شود:", noPayload: "هیچ محموله رمزگذاری شده ای وجود ندارد.", decrypting: "در حال رمزگشایی...", + defaultDescription: "این صفحه رمزگذاری شده است", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/fr-FR.ts b/quartz/i18n/locales/fr-FR.ts index 51975ce41e61a..ce8686be8ae2c 100644 --- a/quartz/i18n/locales/fr-FR.ts +++ b/quartz/i18n/locales/fr-FR.ts @@ -91,6 +91,7 @@ export default { "Mot de passe incorrect. Veuillez saisir à nouveau le mot de passe pour déverrouiller :", noPayload: "Aucune charge utile cryptée.", decrypting: "Décryptage en cours...", + defaultDescription: "Ceci est une page cryptée", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/hu-HU.ts b/quartz/i18n/locales/hu-HU.ts index 59fb06cf49423..c7b1ef6433de9 100644 --- a/quartz/i18n/locales/hu-HU.ts +++ b/quartz/i18n/locales/hu-HU.ts @@ -88,6 +88,7 @@ export default { wrongPassword: "Helytelen jelszó. Kérjük, adja meg újra a jelszót a feloldáshoz:", noPayload: "Nincs titkosított hasznos teher.", decrypting: "Dekódolás...", + defaultDescription: "Ez egy titkosított oldal", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/it-IT.ts b/quartz/i18n/locales/it-IT.ts index 4b19c50ce3448..685771cbb51a8 100644 --- a/quartz/i18n/locales/it-IT.ts +++ b/quartz/i18n/locales/it-IT.ts @@ -90,6 +90,7 @@ export default { wrongPassword: "Password errato. Si prega di reinserire la password per sbloccare:", noPayload: "Nessun payload crittografato.", decrypting: "Decifrazione in corso...", + defaultDescription: "Questa è una pagina crittografata", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/ja-JP.ts b/quartz/i18n/locales/ja-JP.ts index 412a77dd4f2fa..9ef6e5c16be56 100644 --- a/quartz/i18n/locales/ja-JP.ts +++ b/quartz/i18n/locales/ja-JP.ts @@ -89,6 +89,7 @@ export default { "パスワードが間違っています。ロックを解除するにはパスワードを再度入力してください:", noPayload: "暗号化されたペイロードはありません。", decrypting: "解読中...", + defaultDescription: "これは暗号化されたページです", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/ko-KR.ts b/quartz/i18n/locales/ko-KR.ts index 1339e9eccfb72..046bdefdcec7b 100644 --- a/quartz/i18n/locales/ko-KR.ts +++ b/quartz/i18n/locales/ko-KR.ts @@ -87,6 +87,7 @@ export default { wrongPassword: "비밀번호가 잘못되었습니다. 잠금을 해제하려면 암호를 다시 입력하십시오:", noPayload: "암호화된 페이로드가 없습니다.", decrypting: "해독 중...", + defaultDescription: "이 페이지는 암호화된 페이지입니다", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/nl-NL.ts b/quartz/i18n/locales/nl-NL.ts index f3ce080bbad09..ca84b1e0cb0e0 100644 --- a/quartz/i18n/locales/nl-NL.ts +++ b/quartz/i18n/locales/nl-NL.ts @@ -93,6 +93,7 @@ export default { "Verkeerd wachtwoord. Voer alstublieft uw wachtwoord opnieuw in om te ontgrendelen:", noPayload: "Geen versleutelde payload.", decrypting: "Ontsleutelen..", + defaultDescription: "Dit is een gecodeerde pagina", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/pl-PL.ts b/quartz/i18n/locales/pl-PL.ts index ab4ad8120cfa7..4eaa458cadec3 100644 --- a/quartz/i18n/locales/pl-PL.ts +++ b/quartz/i18n/locales/pl-PL.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Senha incorreta. Digite a senha novamente para desbloquear:", noPayload: "Nie ma zaszyfrowanego ładunku.", decrypting: "Deszyfrowanie...", + defaultDescription: "To jest zaszyfrowana strona", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/pt-BR.ts b/quartz/i18n/locales/pt-BR.ts index a34b2b88f1c97..6741d0b035148 100644 --- a/quartz/i18n/locales/pt-BR.ts +++ b/quartz/i18n/locales/pt-BR.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Parolă greșită. Vă rugăm să reintroduceți parola pentru a debloca:", noPayload: "Não há nenhuma carga útil criptografada.", decrypting: "Descifrando...", + defaultDescription: "Esta é uma página criptografada", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/ro-RO.ts b/quartz/i18n/locales/ro-RO.ts index a7b4aea6d992d..f04b90005f7c6 100644 --- a/quartz/i18n/locales/ro-RO.ts +++ b/quartz/i18n/locales/ro-RO.ts @@ -91,6 +91,7 @@ export default { wrongPassword: "Неправильний пароль. Будь ласка, введіть пароль ще раз, щоб розблокувати:", noPayload: "Nu există nicio sarcină utilă criptată.", decrypting: "Decriptare...", + defaultDescription: "Aceasta este o pagină criptată", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/ru-RU.ts b/quartz/i18n/locales/ru-RU.ts index c8197f86240f8..888f348e4cc25 100644 --- a/quartz/i18n/locales/ru-RU.ts +++ b/quartz/i18n/locales/ru-RU.ts @@ -92,6 +92,7 @@ export default { wrongPassword: "Неверный пароль. Пожалуйста, введите пароль еще раз для разблокировки:", noPayload: "Нет зашифрованной полезной нагрузки.", decrypting: "Расшифровка...", + defaultDescription: "Это зашифрованная страница", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/uk-UA.ts b/quartz/i18n/locales/uk-UA.ts index ffde3fa6846f5..f61b9fab22f4e 100644 --- a/quartz/i18n/locales/uk-UA.ts +++ b/quartz/i18n/locales/uk-UA.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Неправильний пароль. Будь ласка, введіть пароль ще раз, щоб розблокувати:", noPayload: "Немає зашифрованого корисного навантаження.", decrypting: "Розшифровка...", + defaultDescription: "Це зашифрована сторінка", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/vi-VN.ts b/quartz/i18n/locales/vi-VN.ts index afbab2f5cb17d..288563ace8c44 100644 --- a/quartz/i18n/locales/vi-VN.ts +++ b/quartz/i18n/locales/vi-VN.ts @@ -89,6 +89,7 @@ export default { wrongPassword: "Sai mật khẩu. Vui lòng điền lại mật khẩu để mở khóa:", noPayload: "Không có nội dung được mã hóa.", decrypting: "Đang giải mã...", + defaultDescription: "Trang này đã được mã hóa", }, }, } as const satisfies Translation diff --git a/quartz/i18n/locales/zh-CN.ts b/quartz/i18n/locales/zh-CN.ts index bbcef526f7597..6e021e8d1aa89 100644 --- a/quartz/i18n/locales/zh-CN.ts +++ b/quartz/i18n/locales/zh-CN.ts @@ -87,6 +87,7 @@ export default { wrongPassword: "密码错误。请重新输入密码解锁:", noPayload: "没有加密的有效负载。", decrypting: "解密中...", + defaultDescription: "这是加密页面", }, }, } as const satisfies Translation diff --git a/quartz/plugins/emitters/contentIndex.ts b/quartz/plugins/emitters/contentIndex.ts index c0fef86d27100..4844baf1bab83 100644 --- a/quartz/plugins/emitters/contentIndex.ts +++ b/quartz/plugins/emitters/contentIndex.ts @@ -125,10 +125,11 @@ export const ContentIndex: QuartzEmitterPlugin> = (opts) => { title: file.data.frontmatter?.title!, links: file.data.links ?? [], tags: file.data.frontmatter?.tags ?? [], - content: file.data.text ?? "", - richContent: opts?.rssFullHtml - ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true })) - : undefined, + content: file.data.text && !file.data.frontmatter?.password ? file.data.text : "", + richContent: + opts?.rssFullHtml && !file.data.frontmatter?.password + ? escapeHTML(toHtml(tree as Root, { allowDangerousHtml: true })) + : undefined, date: date, description: file.data.description ?? "", }) diff --git a/quartz/plugins/transformers/description.ts b/quartz/plugins/transformers/description.ts index c7e592ee93304..f441229374f1e 100644 --- a/quartz/plugins/transformers/description.ts +++ b/quartz/plugins/transformers/description.ts @@ -2,6 +2,7 @@ import { Root as HTMLRoot } from "hast" import { toString } from "hast-util-to-string" import { QuartzTransformerPlugin } from "../types" import { escapeHTML } from "../../util/escape" +import { i18n } from "../../i18n" export interface Options { descriptionLength: number @@ -22,7 +23,7 @@ export const Description: QuartzTransformerPlugin> = (userOpts) const opts = { ...defaultOptions, ...userOpts } return { name: "Description", - htmlPlugins() { + htmlPlugins(ctx) { return [ () => { return async (tree: HTMLRoot, file) => { @@ -37,7 +38,10 @@ export const Description: QuartzTransformerPlugin> = (userOpts) text = text.replace(urlRegex, "$" + "$") } - const desc = frontMatterDescription ?? text + const desc = + (frontMatterDescription ?? file.data.frontmatter?.password) + ? i18n(ctx.cfg.configuration.locale).pages.encryptedContent.defaultDescription + : text const sentences = desc.replace(/\s+/g, " ").split(/\.\s/) const finalDesc: string[] = [] const len = opts.descriptionLength