@vigilkids/cms-nuxt 0.0.1 → 0.1.0
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/dist/module.json +1 -1
- package/dist/runtime/composables/useArticle.js +5 -3
- package/dist/runtime/composables/useArticleList.js +1 -1
- package/dist/runtime/composables/useAuthor.js +8 -6
- package/dist/runtime/composables/useBlogSeo.js +1 -1
- package/dist/runtime/composables/useCategories.js +6 -7
- package/dist/runtime/composables/useCmsClient.js +1 -1
- package/dist/runtime/composables/useCmsPreview.js +1 -1
- package/dist/runtime/server/api/_revalidate.post.js +1 -1
- package/dist/runtime/server/api/preview.get.js +3 -3
- package/dist/runtime/server/middleware/redirects.js +3 -2
- package/dist/runtime/server/utils/cms-client.js +1 -1
- package/package.json +11 -4
package/dist/module.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { toRef } from "vue";
|
|
2
1
|
import { useAsyncData, useHead, useRuntimeConfig, useSeoMeta } from "#imports";
|
|
2
|
+
import { toRef } from "vue";
|
|
3
3
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
4
|
export function useArticle(slug) {
|
|
5
5
|
const resolvedSlug = toRef(slug);
|
|
@@ -29,14 +29,16 @@ export function useArticle(slug) {
|
|
|
29
29
|
});
|
|
30
30
|
useHead({
|
|
31
31
|
script: () => {
|
|
32
|
-
if (!article.value?.json_ld || Object.keys(article.value.json_ld).length === 0)
|
|
32
|
+
if (!article.value?.json_ld || Object.keys(article.value.json_ld).length === 0)
|
|
33
|
+
return [];
|
|
33
34
|
return [{ type: "application/ld+json", innerHTML: JSON.stringify(article.value.json_ld) }];
|
|
34
35
|
}
|
|
35
36
|
});
|
|
36
37
|
useHead({
|
|
37
38
|
link: () => {
|
|
38
39
|
const a = article.value;
|
|
39
|
-
if (!a?.available_locales || a.available_locales.length <= 1)
|
|
40
|
+
if (!a?.available_locales || a.available_locales.length <= 1)
|
|
41
|
+
return [];
|
|
40
42
|
const publicConfig = useRuntimeConfig().public;
|
|
41
43
|
const siteUrl = publicConfig.siteUrl ?? "";
|
|
42
44
|
const links = a.available_locales.map((locale) => ({
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { toRef } from "vue";
|
|
2
1
|
import { useAsyncData } from "#imports";
|
|
2
|
+
import { toRef } from "vue";
|
|
3
3
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
4
|
export function useAuthor(slug) {
|
|
5
5
|
const resolvedSlug = toRef(slug);
|
|
6
6
|
const client = useCmsClient();
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
)
|
|
7
|
+
const {
|
|
8
|
+
data: author,
|
|
9
|
+
status,
|
|
10
|
+
error
|
|
11
|
+
} = useAsyncData(`cms-author-${resolvedSlug.value}`, () => client.getAuthor(resolvedSlug.value), {
|
|
12
|
+
watch: [resolvedSlug]
|
|
13
|
+
});
|
|
12
14
|
const { data: articles } = useAsyncData(
|
|
13
15
|
`cms-author-articles-${resolvedSlug.value}`,
|
|
14
16
|
() => client.getAuthorArticles(resolvedSlug.value),
|
|
@@ -1,20 +1,19 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
2
1
|
import { useAsyncData } from "#imports";
|
|
2
|
+
import { computed } from "vue";
|
|
3
3
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
4
|
export function useCategories() {
|
|
5
5
|
const client = useCmsClient();
|
|
6
|
-
const { data, status, error } = useAsyncData(
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
{ dedupe: "defer" }
|
|
10
|
-
);
|
|
6
|
+
const { data, status, error } = useAsyncData("cms-categories", () => client.getCategories(), {
|
|
7
|
+
dedupe: "defer"
|
|
8
|
+
});
|
|
11
9
|
const categories = computed(() => data.value ?? []);
|
|
12
10
|
const flatCategories = computed(() => {
|
|
13
11
|
const result = [];
|
|
14
12
|
function flatten(nodes) {
|
|
15
13
|
for (const node of nodes) {
|
|
16
14
|
result.push(node);
|
|
17
|
-
if (node.children?.length)
|
|
15
|
+
if (node.children?.length)
|
|
16
|
+
flatten(node.children);
|
|
18
17
|
}
|
|
19
18
|
}
|
|
20
19
|
flatten(categories.value);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CmsClient } from "@vigilkids/cms-client";
|
|
2
1
|
import { useRuntimeConfig, useState } from "#imports";
|
|
2
|
+
import { CmsClient } from "@vigilkids/cms-client";
|
|
3
3
|
export function useCmsClient() {
|
|
4
4
|
const config = useRuntimeConfig();
|
|
5
5
|
const previewToken = useState("cmsPreviewToken", () => null);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { computed } from "vue";
|
|
2
1
|
import { useRuntimeConfig, useState } from "#imports";
|
|
2
|
+
import { computed } from "vue";
|
|
3
3
|
export function useCmsPreview() {
|
|
4
4
|
const previewToken = useState("cmsPreviewToken", () => null);
|
|
5
5
|
const isPreview = computed(() => !!previewToken.value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getHeader, readRawBody } from "h3";
|
|
2
1
|
import { useRuntimeConfig, useStorage } from "#imports";
|
|
3
2
|
import { verifyWebhookSignature } from "@vigilkids/cms-client/webhook";
|
|
3
|
+
import { createError, defineEventHandler, getHeader, readRawBody } from "h3";
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
5
5
|
const config = useRuntimeConfig();
|
|
6
6
|
const secret = config.cms.webhookSecret;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createError, defineEventHandler, getQuery, sendRedirect, setCookie } from "h3";
|
|
2
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { createError, defineEventHandler, getQuery, sendRedirect, setCookie } from "h3";
|
|
3
3
|
export default defineEventHandler(async (event) => {
|
|
4
4
|
const query = getQuery(event);
|
|
5
5
|
const token = query.token;
|
|
@@ -13,7 +13,7 @@ export default defineEventHandler(async (event) => {
|
|
|
13
13
|
const cookieName = cmsConfig.preview?.cookieName ?? "__preview_token";
|
|
14
14
|
const cookieMaxAge = cmsConfig.preview?.cookieMaxAge ?? 1800;
|
|
15
15
|
setCookie(event, cookieName, token, {
|
|
16
|
-
httpOnly:
|
|
16
|
+
httpOnly: false,
|
|
17
17
|
secure: process.env.NODE_ENV === "production",
|
|
18
18
|
sameSite: "lax",
|
|
19
19
|
path: "/",
|
|
@@ -23,7 +23,7 @@ export default defineEventHandler(async (event) => {
|
|
|
23
23
|
let prefix = "";
|
|
24
24
|
if (locale && locale !== defaultLocale) {
|
|
25
25
|
const prefixes = cmsConfig.localePrefixes ?? {};
|
|
26
|
-
prefix =
|
|
26
|
+
prefix = `/${prefixes[locale] ?? locale.toLowerCase()}`;
|
|
27
27
|
}
|
|
28
28
|
const articlePath = cmsConfig.preview?.articlePath ?? "/blog/{slug}";
|
|
29
29
|
const path = articlePath.replace("{slug}", slug);
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { defineEventHandler, getRequestURL, sendRedirect } from "h3";
|
|
2
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
|
+
import { defineEventHandler, getRequestURL, sendRedirect } from "h3";
|
|
3
3
|
let cachedRules = null;
|
|
4
4
|
let cacheExpiry = 0;
|
|
5
5
|
async function loadRules() {
|
|
6
6
|
const now = Date.now();
|
|
7
|
-
if (cachedRules && now < cacheExpiry)
|
|
7
|
+
if (cachedRules && now < cacheExpiry)
|
|
8
|
+
return cachedRules;
|
|
8
9
|
const config = useRuntimeConfig();
|
|
9
10
|
const cacheTtl = config.cms.redirects?.cacheTtl ?? 3e5;
|
|
10
11
|
try {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vigilkids/cms-nuxt",
|
|
3
|
-
"version": "0.0
|
|
4
|
-
"description": "Nuxt 3 module for OnEx CMS
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Nuxt 3 module for OnEx CMS — composables, server routes, middleware, sitemap",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.mjs",
|
|
7
7
|
"types": "./dist/types.d.ts",
|
|
@@ -17,7 +17,10 @@
|
|
|
17
17
|
"sideEffects": false,
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "nuxt-module-build build",
|
|
20
|
-
"prepack": "nuxt-module-build build"
|
|
20
|
+
"prepack": "nuxt-module-build build",
|
|
21
|
+
"lint": "eslint .",
|
|
22
|
+
"lint:fix": "eslint . --fix",
|
|
23
|
+
"format": "prettier --write src/"
|
|
21
24
|
},
|
|
22
25
|
"publishConfig": {
|
|
23
26
|
"access": "public"
|
|
@@ -28,15 +31,19 @@
|
|
|
28
31
|
"directory": "packages/cms-nuxt"
|
|
29
32
|
},
|
|
30
33
|
"devDependencies": {
|
|
34
|
+
"@antfu/eslint-config": "^4.13.2",
|
|
31
35
|
"@nuxt/kit": "^3.15.0",
|
|
32
36
|
"@nuxt/module-builder": "^0.8.0",
|
|
33
37
|
"@nuxt/schema": "^3.15.0",
|
|
34
38
|
"@types/node": "^22.0.0",
|
|
39
|
+
"eslint": "^9.22.0",
|
|
40
|
+
"eslint-config-prettier": "^10.1.1",
|
|
35
41
|
"h3": "^1.12.0",
|
|
42
|
+
"prettier": "^3.5.3",
|
|
36
43
|
"vue": "^3.4.0"
|
|
37
44
|
},
|
|
38
45
|
"peerDependencies": {
|
|
39
|
-
"@vigilkids/cms-client": "
|
|
46
|
+
"@vigilkids/cms-client": "workspace:*",
|
|
40
47
|
"nuxt": ">=3.15.0"
|
|
41
48
|
},
|
|
42
49
|
"peerDependenciesMeta": {
|