@vigilkids/cms-nuxt 0.2.1 → 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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.15.0"
6
6
  },
7
- "version": "0.2.1",
7
+ "version": "0.2.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "0.8.4",
10
10
  "unbuild": "unknown"
@@ -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 links = a.available_locales.map((locale) => ({
45
- rel: "alternate",
46
- hreflang: locale,
47
- href: locale === "en" ? `${siteUrl}/blog/${a.slug}` : `${siteUrl}/${locale}/blog/${a.slug}`
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/${a.slug}`
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) {
@@ -1,3 +1,4 @@
1
+ import process from "node:process";
1
2
  import { useRuntimeConfig } from "#imports";
2
3
  import { createError, defineEventHandler, getQuery, sendRedirect, setCookie } from "h3";
3
4
  export default defineEventHandler(async (event) => {
@@ -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
@@ -0,0 +1,3 @@
1
+ export function toArray(value) {
2
+ return Array.isArray(value) ? value : [];
3
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vigilkids/cms-nuxt",
3
- "version": "0.2.1",
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": "workspace:*",
46
+ "@vigilkids/cms-client": "^0.1.4",
47
47
  "nuxt": ">=3.15.0"
48
48
  },
49
49
  "peerDependenciesMeta": {