mktcms 0.1.12 → 0.1.14

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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mktcms",
3
3
  "configKey": "mktcms",
4
- "version": "0.1.12",
4
+ "version": "0.1.14",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -39,8 +39,7 @@ export default defineEventHandler(async (event) => {
39
39
  statusMessage: "Invalid file type. Only PDF, JPG, JPEG, and PNG files are allowed."
40
40
  });
41
41
  }
42
- const filePath = [s3Prefix, sanePath, sanitizeFilename(file.filename)].filter(Boolean).join("/");
42
+ const filePath = [s3Prefix, sanePath, sanitizeFilename(file.filename)].filter(Boolean).join(":");
43
43
  await useStorage("content").setItemRaw(filePath, Buffer.from(file.data));
44
- const returnFileName = filePath;
45
- return { success: true, path: returnFileName };
44
+ return { success: true, path: filePath };
46
45
  });
@@ -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(fullPath);
16
+ if (fallbackFile) {
17
+ return fallbackFile;
18
+ }
14
19
  throw createError({
15
20
  statusCode: 404,
16
21
  statusMessage: "File not found"
@@ -3,19 +3,21 @@ import createFsDriver from "unstorage/drivers/fs";
3
3
  import { defineNitroPlugin, useStorage, useRuntimeConfig } from "nitropack/runtime";
4
4
  export default defineNitroPlugin(() => {
5
5
  const storage = useStorage();
6
- const s3Driver = createS3Driver({
7
- accessKeyId: useRuntimeConfig().mktcms.s3AccessKey,
8
- secretAccessKey: useRuntimeConfig().mktcms.s3SecretKey,
9
- endpoint: useRuntimeConfig().mktcms.s3Endpoint,
10
- bucket: useRuntimeConfig().mktcms.s3Bucket,
11
- region: useRuntimeConfig().mktcms.s3Region
12
- });
13
- const fsDriver = createFsDriver({
14
- base: "./.storage"
15
- });
16
- if (process.env.NODE_ENV === "production") {
17
- storage.mount("content", s3Driver);
6
+ const { mktcms: { s3AccessKey, s3SecretKey, s3Endpoint, s3Bucket, s3Region } } = useRuntimeConfig();
7
+ if (s3AccessKey && s3SecretKey && s3Endpoint && s3Bucket && s3Region) {
8
+ storage.mount("content", createS3Driver({
9
+ accessKeyId: s3AccessKey,
10
+ secretAccessKey: s3SecretKey,
11
+ endpoint: s3Endpoint,
12
+ bucket: s3Bucket,
13
+ region: s3Region
14
+ }));
18
15
  } else {
19
- storage.mount("content", fsDriver);
16
+ storage.mount("content", createFsDriver({
17
+ base: "./.storage"
18
+ }));
20
19
  }
20
+ storage.mount("fallback", createFsDriver({
21
+ base: "./content"
22
+ }));
21
23
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mktcms",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "description": "Simple CMS module for Nuxt",
5
5
  "repository": "mktcode/mktcms",
6
6
  "license": "MIT",