diff --git a/src/components/shortcodes/ProtectedContent.astro b/src/components/shortcodes/ProtectedContent.astro new file mode 100644 index 0000000..1ab737d --- /dev/null +++ b/src/components/shortcodes/ProtectedContent.astro @@ -0,0 +1,131 @@ +--- +import { encrypt } from '../../plugins/encrypt'; +import {siteConfig} from "../../config"; + +interface Props { + password?: string; + pwEnv?: string; +} + +const { password: propPassword, pwEnv } = Astro.props; +// Get password from props, environment variable, or site config +const password = (pwEnv ? import.meta.env[pwEnv] : propPassword) || siteConfig.contentPassword || import.meta.env.CONTENT_PASSWORD || Math.random().toString(); + +// Get the slot content +const content = await Astro.slots.render('default'); + +// Encrypt content at build time +const { encryptedData, iv } = encrypt(content, password); +--- + +
This content is protected. Enter the password to view it:
+ +