@rxdrag/website-lib-core 0.0.27 → 0.0.29

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rxdrag/website-lib-core",
3
- "version": "0.0.27",
3
+ "version": "0.0.29",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.ts"
@@ -24,9 +24,9 @@
24
24
  "@types/react-dom": "^18.2.7",
25
25
  "eslint": "^7.32.0",
26
26
  "typescript": "^5",
27
- "@rxdrag/entify-hooks": "0.2.46",
28
- "@rxdrag/slate-preview": "1.2.57",
29
27
  "@rxdrag/eslint-config-custom": "0.2.12",
28
+ "@rxdrag/slate-preview": "1.2.57",
29
+ "@rxdrag/entify-hooks": "0.2.48",
30
30
  "@rxdrag/tsconfig": "0.2.0"
31
31
  },
32
32
  "dependencies": {
@@ -35,7 +35,7 @@
35
35
  "lodash-es": "^4.17.21",
36
36
  "react": "^18.2.0",
37
37
  "react-dom": "^18.2.0",
38
- "@rxdrag/rxcms-models": "0.3.54"
38
+ "@rxdrag/rxcms-models": "0.3.56"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "astro": "^4.0.0 || ^5.0.0"
@@ -21,11 +21,11 @@ export function toHref(
21
21
  }
22
22
 
23
23
  if (type === "products") {
24
- return `${productsSlug}/page/1`;
24
+ return `/${productsSlug}/page/1`;
25
25
  }
26
26
 
27
27
  if (type === "posts") {
28
- return `${postsSlug}/page/1`;
28
+ return `/${postsSlug}/page/1`;
29
29
  }
30
30
 
31
31
  if (type === "page") {
@@ -33,11 +33,11 @@ export function toHref(
33
33
  }
34
34
 
35
35
  if (type === "post") {
36
- return `${postsSlug}/${to}`;
36
+ return `/${postsSlug}/${to}`;
37
37
  }
38
38
 
39
39
  if (type === "product") {
40
- return `${productsSlug}/${to}`;
40
+ return `/${productsSlug}/${to}`;
41
41
  }
42
42
 
43
43
  if (type === "user") {
@@ -45,11 +45,11 @@ export function toHref(
45
45
  }
46
46
 
47
47
  if (type === "product-category") {
48
- return `${productsSlug}/categories/${to}/1`;
48
+ return `/${productsSlug}/categories/${to}/1`;
49
49
  }
50
50
 
51
51
  if (type === "post-category") {
52
- return `${postsSlug}/categories/${to}/1`;
52
+ return `/${postsSlug}/categories/${to}/1`;
53
53
  }
54
54
 
55
55
  return `/${type}/${to}`;
@@ -24,7 +24,7 @@ import { queryPostSlugs } from "./lib/queryPostSlugs";
24
24
  import { queryUserIds } from "./lib/queryUserIds";
25
25
  import { IEntify, PostPatinateOptions, PostsOptions } from "./IEntify";
26
26
  import { queryWebsite } from "./lib/queryWebsite";
27
- import { Page, PageType } from "@rxdrag/rxcms-models";
27
+ import { Page, PageType, Product } from "@rxdrag/rxcms-models";
28
28
  import { queryPageBySlug } from "./lib/queryPageBySlug";
29
29
  import { queryPageByType } from "./lib/queryPageByType";
30
30
 
@@ -68,8 +68,12 @@ export class Entify implements IEntify {
68
68
  return (await queryLangs(this.envVariables))?.items;
69
69
  }
70
70
 
71
- public async getFeaturedProducts(count?: number, imageSize?: TSize) {
72
- return await queryFeaturedProducts(count, imageSize, this.envVariables);
71
+ public async getFeaturedProducts(
72
+ count?: number,
73
+ imageSize?: TSize,
74
+ addonFields?: (keyof Product)[]
75
+ ) {
76
+ return await queryFeaturedProducts(count, imageSize, this.envVariables, addonFields);
73
77
  }
74
78
 
75
79
  public async getLatestPosts(count?: number, coverSize?: TSize) {
@@ -178,10 +182,12 @@ export class Entify implements IEntify {
178
182
 
179
183
  public async getProducts(
180
184
  conditions: ListConditions,
181
- imageSize: TSize | undefined
185
+ imageSize: TSize | undefined,
186
+ addonFields?: (keyof Product)[]
182
187
  ) {
183
- return (await queryProducts(conditions, imageSize, this.envVariables))
184
- ?.items;
188
+ return (
189
+ await queryProducts(conditions, imageSize, this.envVariables, addonFields)
190
+ )?.items;
185
191
  }
186
192
 
187
193
  public async getProductListPaths(options: {
@@ -372,7 +378,7 @@ export class Entify implements IEntify {
372
378
  }
373
379
 
374
380
  public async fulltextSearch(keyword: string, imageSize: TSize | undefined) {
375
- return await fulltextSearch(keyword, imageSize,this.envVariables);
381
+ return await fulltextSearch(keyword, imageSize, this.envVariables);
376
382
  }
377
383
 
378
384
  public async getUserPaths() {
@@ -8,7 +8,7 @@ import {
8
8
  TProductCategory,
9
9
  TUser,
10
10
  } from "./view-model";
11
- import { Lang, Page, PageType, SearchIndex, Theme, Website } from "@rxdrag/rxcms-models";
11
+ import { Lang, Page, PageType, Product, SearchIndex, Theme, Website } from "@rxdrag/rxcms-models";
12
12
 
13
13
  export type PostsOptions = {
14
14
  category?: string;
@@ -41,7 +41,7 @@ export interface IEntify {
41
41
 
42
42
  getLangs(): Promise<Lang[] | undefined>;
43
43
 
44
- getFeaturedProducts(count?: number, imageSize?: TSize): Promise<TProduct[] | undefined>;
44
+ getFeaturedProducts(count?: number, imageSize?: TSize, addonFields?: (keyof Product)[]): Promise<TProduct[] | undefined>;
45
45
 
46
46
  getLatestPosts(count?: number, coverSize?: TSize): Promise<TPost[] | undefined>;
47
47
 
@@ -92,7 +92,8 @@ export interface IEntify {
92
92
 
93
93
  getProducts(
94
94
  conditions: ListConditions,
95
- imageSize: TSize | undefined
95
+ imageSize: TSize | undefined,
96
+ addonFields?: (keyof Product)[]
96
97
  ): Promise<TProduct[] | undefined>;
97
98
 
98
99
  getProductListPaths(options: {
@@ -14,8 +14,9 @@ import { TProduct } from "../view-model";
14
14
 
15
15
  export async function queryFeaturedProducts(
16
16
  count: number = 8,
17
- imageSize: TSize|undefined,
18
- envVariables: EnvVariables
17
+ imageSize: TSize | undefined,
18
+ envVariables: EnvVariables,
19
+ addonFields?: (keyof Product)[]
19
20
  ) {
20
21
  const result = await queryEntityList<
21
22
  Product,
@@ -30,6 +31,7 @@ export async function queryFeaturedProducts(
30
31
  ProductFields.title,
31
32
  ProductFields.shortTitle,
32
33
  ProductFields.description,
34
+ ...(addonFields || []),
33
35
  ],
34
36
  {
35
37
  offset: 0,
@@ -19,7 +19,7 @@ export async function queryProducts(
19
19
  conditions: ListConditions,
20
20
  imageSize: TSize | undefined,
21
21
  envVariables: EnvVariables,
22
- selectFields?: (keyof Product)[]
22
+ addonFields?: (keyof Product)[]
23
23
  ) {
24
24
  const { category: categorySlug, page = 1, pageSize = 10 } = conditions;
25
25
 
@@ -44,7 +44,7 @@ export async function queryProducts(
44
44
  ];
45
45
 
46
46
  // 使用指定的字段或默认字段
47
- const fields = selectFields || defaultFields;
47
+ const fields = [...defaultFields, ...(addonFields || [])];
48
48
 
49
49
  const queryOptions = new ProductQueryOptions(fields, {
50
50
  offset: (page - 1) * pageSize,
@@ -66,7 +66,7 @@ export async function queryProducts(
66
66
  });
67
67
 
68
68
  // 只有在不指定字段或需要查询媒体时才添加媒体查询
69
- if (!selectFields || !selectFields.includes("slug" as keyof Product)) {
69
+ if (!addonFields || !addonFields.includes("slug" as keyof Product)) {
70
70
  queryOptions.mediaPivots(newQueryProductsMediaOptions(imageSize));
71
71
  }
72
72