mktcms 0.1.11 → 0.1.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -17,6 +17,7 @@ This module is my personal, minimalist, opinionated, independent alternative to
|
|
|
17
17
|
- API routes at `/api/admin`
|
|
18
18
|
- `MKTCMS_ADMIN_AUTH_KEY` env var to set a password
|
|
19
19
|
- `useContent` composable
|
|
20
|
+
- `sendMail` utility to send emails via SMTP
|
|
20
21
|
|
|
21
22
|
## Setup
|
|
22
23
|
|
|
@@ -96,6 +97,42 @@ const { data: article } = await useContent<Article>('articles/article-1.json')
|
|
|
96
97
|
</template>
|
|
97
98
|
```
|
|
98
99
|
|
|
100
|
+
The storage falls back to a `content` folder that you can include in your repo as default content.
|
|
101
|
+
|
|
102
|
+
```ts
|
|
103
|
+
const { data: article } = await useContent<Article>('articles/article-1.json')
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
This will check S3 at `your-project:articles:article-1.json` first, and if not found, `~~/content/articles/article-1.json`.
|
|
107
|
+
(In development `.storage/` is used instead of S3.)
|
|
108
|
+
|
|
109
|
+
### Mailer
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
await sendMail({
|
|
113
|
+
subject: 'Notification from MKT CMS',
|
|
114
|
+
fields: {
|
|
115
|
+
'Error': 'Something went wrong',
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
If you have an email from a user, you can use the `replyTo` field:
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
const name = 'John Doe'
|
|
124
|
+
const email = 'john.doe@example.com'
|
|
125
|
+
|
|
126
|
+
await sendMail({
|
|
127
|
+
subject: 'Contact Form Submission',
|
|
128
|
+
fields: {
|
|
129
|
+
'Name': name,
|
|
130
|
+
'Email': email,
|
|
131
|
+
},
|
|
132
|
+
replyTo: email,
|
|
133
|
+
})
|
|
134
|
+
```
|
|
135
|
+
|
|
99
136
|
## Contribution
|
|
100
137
|
|
|
101
138
|
<details>
|
package/dist/module.json
CHANGED
|
@@ -11,6 +11,11 @@ export default defineEventHandler(async (event) => {
|
|
|
11
11
|
const storage = useStorage("content");
|
|
12
12
|
const file = await storage.getItem(fullPath);
|
|
13
13
|
if (!file) {
|
|
14
|
+
const fallbackStorage = useStorage("fallback");
|
|
15
|
+
const fallbackFile = await fallbackStorage.getItem(path);
|
|
16
|
+
if (fallbackFile) {
|
|
17
|
+
return fallbackFile;
|
|
18
|
+
}
|
|
14
19
|
throw createError({
|
|
15
20
|
statusCode: 404,
|
|
16
21
|
statusMessage: "File not found"
|
|
@@ -13,6 +13,10 @@ export default defineNitroPlugin(() => {
|
|
|
13
13
|
const fsDriver = createFsDriver({
|
|
14
14
|
base: "./.storage"
|
|
15
15
|
});
|
|
16
|
+
const fallbackDriver = createFsDriver({
|
|
17
|
+
base: "./content"
|
|
18
|
+
});
|
|
19
|
+
storage.mount("fallback", fallbackDriver);
|
|
16
20
|
if (process.env.NODE_ENV === "production") {
|
|
17
21
|
storage.mount("content", s3Driver);
|
|
18
22
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import nodemailer from "nodemailer";
|
|
2
2
|
import { useRuntimeConfig } from "nitropack/runtime";
|
|
3
|
-
export async function sendMail({ subject, fields }) {
|
|
3
|
+
export async function sendMail({ subject, fields, replyTo }) {
|
|
4
4
|
const { mktcms: { smtpHost, smtpPort, smtpUser, smtpPass, smtpSecure, mailerFrom, mailerTo } } = useRuntimeConfig();
|
|
5
5
|
const transporter = nodemailer.createTransport({
|
|
6
6
|
host: smtpHost,
|
|
@@ -14,6 +14,7 @@ export async function sendMail({ subject, fields }) {
|
|
|
14
14
|
const mailOptions = {
|
|
15
15
|
from: mailerFrom,
|
|
16
16
|
to: mailerTo,
|
|
17
|
+
replyTo: replyTo || void 0,
|
|
17
18
|
subject,
|
|
18
19
|
html: Object.entries(fields).map(([key, value]) => `<p><strong>${key}:</strong> ${value}</p>`).join(""),
|
|
19
20
|
text: Object.entries(fields).map(([key, value]) => `${key}: ${value}`).join("\n")
|