@vigilkids/cms-nuxt 0.2.0 → 0.2.2
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 +16 -8
- package/dist/runtime/composables/useAuthor.js +4 -2
- package/dist/runtime/composables/useCategories.js +2 -1
- package/dist/runtime/server/api/preview.get.js +1 -0
- package/dist/runtime/server/middleware/preview-context.js +10 -0
- package/dist/runtime/server/middleware/redirects.js +2 -1
- package/dist/runtime/sitemap/provider.js +2 -1
- package/dist/runtime/utils/list.d.ts +0 -0
- package/dist/runtime/utils/list.js +3 -0
- package/package.json +3 -3
package/dist/module.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useAsyncData, useHead, useRuntimeConfig, useSeoMeta } from "#imports";
|
|
2
|
-
import { toRef } from "vue";
|
|
2
|
+
import { computed, toRef } from "vue";
|
|
3
|
+
import { toArray } from "../utils/list.js";
|
|
3
4
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
5
|
export function useArticle(slug) {
|
|
5
6
|
const resolvedSlug = toRef(slug);
|
|
@@ -15,6 +16,9 @@ export function useArticle(slug) {
|
|
|
15
16
|
() => client.getRelatedArticles(resolvedSlug.value),
|
|
16
17
|
{ lazy: true, watch: [resolvedSlug] }
|
|
17
18
|
);
|
|
19
|
+
const relatedArticleList = computed(
|
|
20
|
+
() => toArray(relatedArticles.value)
|
|
21
|
+
);
|
|
18
22
|
useSeoMeta({
|
|
19
23
|
title: () => article.value?.seo_meta?.title ?? article.value?.title ?? "",
|
|
20
24
|
description: () => article.value?.seo_meta?.description ?? article.value?.excerpt ?? "",
|
|
@@ -41,22 +45,26 @@ export function useArticle(slug) {
|
|
|
41
45
|
return [];
|
|
42
46
|
const publicConfig = useRuntimeConfig().public;
|
|
43
47
|
const siteUrl = publicConfig.siteUrl ?? "";
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
const defaultSlug = a.localized_slugs?.en ?? a.slug;
|
|
49
|
+
const links = a.available_locales.map((locale) => {
|
|
50
|
+
const slug2 = a.localized_slugs?.[locale] ?? a.slug;
|
|
51
|
+
return {
|
|
52
|
+
rel: "alternate",
|
|
53
|
+
hreflang: locale,
|
|
54
|
+
href: locale === "en" ? `${siteUrl}/blog/${slug2}` : `${siteUrl}/${locale}/blog/${slug2}`
|
|
55
|
+
};
|
|
56
|
+
});
|
|
49
57
|
links.push({
|
|
50
58
|
rel: "alternate",
|
|
51
59
|
hreflang: "x-default",
|
|
52
|
-
href: `${siteUrl}/blog/${
|
|
60
|
+
href: `${siteUrl}/blog/${defaultSlug}`
|
|
53
61
|
});
|
|
54
62
|
return links;
|
|
55
63
|
}
|
|
56
64
|
});
|
|
57
65
|
return {
|
|
58
66
|
article,
|
|
59
|
-
relatedArticles,
|
|
67
|
+
relatedArticles: relatedArticleList,
|
|
60
68
|
status,
|
|
61
69
|
error,
|
|
62
70
|
ready: _articleAsync
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useAsyncData } from "#imports";
|
|
2
|
-
import { toRef } from "vue";
|
|
2
|
+
import { computed, toRef } from "vue";
|
|
3
|
+
import { toArray } from "../utils/list.js";
|
|
3
4
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
5
|
export function useAuthor(slug) {
|
|
5
6
|
const resolvedSlug = toRef(slug);
|
|
@@ -16,9 +17,10 @@ export function useAuthor(slug) {
|
|
|
16
17
|
() => client.getAuthorArticles(resolvedSlug.value),
|
|
17
18
|
{ lazy: true, watch: [resolvedSlug] }
|
|
18
19
|
);
|
|
20
|
+
const articleList = computed(() => toArray(articles.value));
|
|
19
21
|
return {
|
|
20
22
|
author,
|
|
21
|
-
articles,
|
|
23
|
+
articles: articleList,
|
|
22
24
|
status,
|
|
23
25
|
error
|
|
24
26
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { useAsyncData } from "#imports";
|
|
2
2
|
import { computed } from "vue";
|
|
3
|
+
import { toArray } from "../utils/list.js";
|
|
3
4
|
import { useCmsClient } from "./useCmsClient.js";
|
|
4
5
|
export function useCategories() {
|
|
5
6
|
const client = useCmsClient();
|
|
6
7
|
const { data, status, error } = useAsyncData("cms-categories", () => client.getCategories(), {
|
|
7
8
|
dedupe: "defer"
|
|
8
9
|
});
|
|
9
|
-
const categories = computed(() => data.value
|
|
10
|
+
const categories = computed(() => toArray(data.value));
|
|
10
11
|
const flatCategories = computed(() => {
|
|
11
12
|
const result = [];
|
|
12
13
|
function flatten(nodes) {
|
|
@@ -6,5 +6,15 @@ export default defineEventHandler((event) => {
|
|
|
6
6
|
const raw = getCookie(event, cookieName);
|
|
7
7
|
if (raw) {
|
|
8
8
|
event.context.__cms_preview_token = decodeURIComponent(raw);
|
|
9
|
+
const url = event.node.req.url || "/";
|
|
10
|
+
if (!url.startsWith("/api/") && !url.startsWith("/_") && !url.startsWith("/cms-proxy/")) {
|
|
11
|
+
const ts = Date.now();
|
|
12
|
+
const sep = url.includes("?") ? "&" : "?";
|
|
13
|
+
event.node.req.url = `${url}${sep}_pt=${ts}`;
|
|
14
|
+
if (event.node.req.originalUrl) {
|
|
15
|
+
const origSep = event.node.req.originalUrl.includes("?") ? "&" : "?";
|
|
16
|
+
event.node.req.originalUrl = `${event.node.req.originalUrl}${origSep}_pt=${ts}`;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
9
19
|
}
|
|
10
20
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
2
|
import { defineEventHandler, getRequestURL, sendRedirect } from "h3";
|
|
3
|
+
import { toArray } from "../../utils/list.js";
|
|
3
4
|
let cachedRules = null;
|
|
4
5
|
let cacheExpiry = 0;
|
|
5
6
|
async function loadRules() {
|
|
@@ -11,7 +12,7 @@ async function loadRules() {
|
|
|
11
12
|
try {
|
|
12
13
|
const { useServerCmsClient } = await import("../utils/cms-client.js");
|
|
13
14
|
const client = useServerCmsClient();
|
|
14
|
-
cachedRules = await client.getRedirects();
|
|
15
|
+
cachedRules = toArray(await client.getRedirects());
|
|
15
16
|
cacheExpiry = now + cacheTtl;
|
|
16
17
|
return cachedRules;
|
|
17
18
|
} catch (error) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CmsClient } from "@vigilkids/cms-client";
|
|
2
|
+
import { toArray } from "../utils/list.js";
|
|
2
3
|
export async function sitemapProvider(options) {
|
|
3
4
|
const client = new CmsClient({
|
|
4
5
|
baseUrl: options.apiUrl,
|
|
@@ -9,7 +10,7 @@ export async function sitemapProvider(options) {
|
|
|
9
10
|
const entries = [];
|
|
10
11
|
for (const locale of locales) {
|
|
11
12
|
const sitemapEntries = await client.getSitemap(locale);
|
|
12
|
-
for (const entry of sitemapEntries) {
|
|
13
|
+
for (const entry of toArray(sitemapEntries)) {
|
|
13
14
|
entries.push({
|
|
14
15
|
loc: entry.loc,
|
|
15
16
|
lastmod: entry.last_mod,
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vigilkids/cms-nuxt",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Nuxt 3 module for OnEx CMS — composables, server routes, middleware, sitemap",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/module.mjs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"repository": {
|
|
29
29
|
"type": "git",
|
|
30
|
-
"url": "https://github.com/1yhy/onex.git",
|
|
30
|
+
"url": "git+https://github.com/1yhy/onex.git",
|
|
31
31
|
"directory": "packages/cms-nuxt"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"vue": "^3.4.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@vigilkids/cms-client": "
|
|
46
|
+
"@vigilkids/cms-client": "^0.1.4",
|
|
47
47
|
"nuxt": ">=3.15.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependenciesMeta": {
|