diff --git a/packages/post-encrypt/README.md b/packages/post-encrypt/README.md
index e5be3956..68d46a83 100644
--- a/packages/post-encrypt/README.md
+++ b/packages/post-encrypt/README.md
@@ -2,25 +2,46 @@
Post-build AES-256-GCM encryption tool for the [FixIt](https://github.com/hugo-fixit/FixIt) Hugo theme.
+It is designed for HTML generated by FixIt content encryption templates and should be run after your site has already been built.
+
## Usage
After building your Hugo site, run the encryption tool from your site root:
```bash
-npx @hugo-fixit/post-encrypt --input public
+npx @hugo-fixit/post-encrypt
+```
+
+You can also install it globally and run the CLI directly:
+
+```bash
+npm install -g @hugo-fixit/post-encrypt
+post-encrypt
+```
+
+Typical build flow:
+
+```bash
+hugo build
+npx @hugo-fixit/post-encrypt
+npx @hugo-fixit/post-encrypt --verify
```
### Options
-| Option | Description | Default |
-| --- | --- | --- |
-| `--input
` | Input directory containing HTML files | `public` |
-| `--dry-run | Show which files would be modified without writing | `false` |
-| `--verify | Verify all encryption templates are encrypted | `false` |
+| Option | Description | Default |
+| --------------- | -------------------------------------------------- | -------- |
+| `--input ` | Input directory containing HTML files | `public` |
+| `--dry-run` | Show which files would be modified without writing | `false` |
+| `--verify` | Verify all encryption templates are encrypted | `false` |
+| `-h, --help` | Show CLI usage help | |
### Examples
```bash
+# Show CLI help
+npx @hugo-fixit/post-encrypt --help
+
# Encrypt content in the default public/ directory
npx @hugo-fixit/post-encrypt
diff --git a/packages/post-encrypt/package.json b/packages/post-encrypt/package.json
index d916e2ac..dcbf9bf4 100644
--- a/packages/post-encrypt/package.json
+++ b/packages/post-encrypt/package.json
@@ -5,7 +5,7 @@
"description": "Post-build AES-256-GCM encryption tool for the FixIt Hugo theme",
"author": "Lruihao",
"license": "MIT",
- "homepage": "https://github.com/hugo-fixit/FixIt/tree/feat/post-encrypt/packages/post-encrypt#readme",
+ "homepage": "https://github.com/hugo-fixit/FixIt/tree/main/packages/post-encrypt#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/hugo-fixit/FixIt.git",
diff --git a/packages/post-encrypt/src/index.ts b/packages/post-encrypt/src/index.ts
index c3d19ebb..d6feecae 100644
--- a/packages/post-encrypt/src/index.ts
+++ b/packages/post-encrypt/src/index.ts
@@ -19,6 +19,7 @@ interface CliOptions {
cwd: string
dryRun: boolean
verifyOnly: boolean
+ helpRequested: boolean
}
interface TemplateMatch {
@@ -37,10 +38,15 @@ function parseArgs(argv: string[]): CliOptions {
cwd: process.env.INIT_CWD || process.cwd(),
dryRun: false,
verifyOnly: false,
+ helpRequested: false,
}
for (let i = 0; i < argv.length; i++) {
const arg = argv[i]
+ if (arg === '--help' || arg === '-h') {
+ options.helpRequested = true
+ continue
+ }
if (arg === '--input') {
options.input = argv[i + 1] || options.input
i++
@@ -63,6 +69,23 @@ function parseArgs(argv: string[]): CliOptions {
return options
}
+function printHelp(): void {
+ consola.log(`Usage:
+ post-encrypt [options]
+
+Options:
+ --input Input directory containing HTML files (default: public)
+ --dry-run Show which files would be modified without writing
+ --verify Verify all encryption templates are encrypted
+ -h, --help Show this help message
+
+Examples:
+ post-encrypt
+ post-encrypt --input dist
+ post-encrypt --verify
+ post-encrypt --dry-run`)
+}
+
function collectHtmlFiles(targetDir: string): string[] {
const files: string[] = []
@@ -240,6 +263,10 @@ function hasUnencryptedTemplate(matches: TemplateMatch[]): boolean {
function main() {
const options = parseArgs(process.argv.slice(2))
+ if (options.helpRequested) {
+ printHelp()
+ return
+ }
const targetDir = path.isAbsolute(options.input)
? options.input
: path.resolve(options.cwd, options.input)