@c-time/frelio-data-json-recipe 1.2.1 → 1.3.17
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 +89 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/package.json +5 -2
package/README.md
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
# @c-time/frelio-data-json-recipe
|
|
2
|
+
|
|
3
|
+
Frelio SSG のビルドレシピ(build-data-recipe)の型定義。
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## 概要
|
|
8
|
+
|
|
9
|
+
ビルドレシピは、コンテンツをどのように変換して data-json を生成するかを定義する設定ファイルのスキーマ。コンテンツタイプごとの詳細ページ・一覧ページの生成ルール、静的ページの定義、カスタムフィールド変換などを記述する。
|
|
10
|
+
|
|
11
|
+
ランタイム依存なし。型定義と型ガードのみを提供する。
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## インストール
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @c-time/frelio-data-json-recipe
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 使用例
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import type {
|
|
27
|
+
FrelioBuildDataRecipe,
|
|
28
|
+
ContentTypeRecipe,
|
|
29
|
+
DetailPageRecipe,
|
|
30
|
+
ListPageRecipe,
|
|
31
|
+
} from '@c-time/frelio-data-json-recipe'
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
isListPageRecipeWithPagination,
|
|
35
|
+
isCustomFieldTransform,
|
|
36
|
+
} from '@c-time/frelio-data-json-recipe'
|
|
37
|
+
|
|
38
|
+
// レシピの型チェック
|
|
39
|
+
const recipe: FrelioBuildDataRecipe = {
|
|
40
|
+
contentTypes: { /* ... */ },
|
|
41
|
+
staticPages: [],
|
|
42
|
+
templateIncludes: {},
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// ページネーションの有無を判定
|
|
46
|
+
if (isListPageRecipeWithPagination(listRecipe)) {
|
|
47
|
+
console.log(listRecipe.pagination.perPage)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
---
|
|
52
|
+
|
|
53
|
+
## 主な型
|
|
54
|
+
|
|
55
|
+
| 型 | 説明 |
|
|
56
|
+
|----|------|
|
|
57
|
+
| `FrelioBuildDataRecipe` | ビルドレシピ全体の定義 |
|
|
58
|
+
| `ContentTypeRecipe` | コンテンツタイプごとの生成ルール |
|
|
59
|
+
| `DetailPageRecipe` | 詳細ページの生成設定 |
|
|
60
|
+
| `ListPageRecipe` | 一覧ページの生成設定(ページネーション有無で分岐) |
|
|
61
|
+
| `StaticPageRecipe` | 静的ページの生成設定 |
|
|
62
|
+
| `CustomFieldTransform` | フィールド値の変換定義 |
|
|
63
|
+
| `CustomFieldRelationList` | 関連コンテンツの参照定義 |
|
|
64
|
+
| `CustomFieldConstant` | 固定値の定義 |
|
|
65
|
+
| `RelationExpand` | 関連コンテンツの展開設定 |
|
|
66
|
+
| `RecipeSort` / `RecipeFilter` | ソート・フィルタ設定 |
|
|
67
|
+
| `TemplateIncludes` | テンプレート依存関係 |
|
|
68
|
+
|
|
69
|
+
### カスタムフィールドのフォーマットタイプ
|
|
70
|
+
|
|
71
|
+
`string`, `date`, `number`, `escape`, `toc`, `truncate`, `stripHtml`, `slug`, `lowercase`, `uppercase`, `default`, `count`, `first`, `last`, `join`, `url`, `picture`, `img`, `srcset`, `fileLink`, `relationList`, `constant` など 25 種類以上。
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 型ガード
|
|
76
|
+
|
|
77
|
+
| 関数 | 説明 |
|
|
78
|
+
|------|------|
|
|
79
|
+
| `isListPageRecipeWithPagination(recipe)` | ページネーション付き一覧レシピか判定 |
|
|
80
|
+
| `isListPageRecipeWithoutPagination(recipe)` | ページネーションなし一覧レシピか判定 |
|
|
81
|
+
| `isCustomFieldTransform(field)` | Transform 型カスタムフィールドか判定 |
|
|
82
|
+
| `isCustomFieldRelationList(field)` | RelationList 型カスタムフィールドか判定 |
|
|
83
|
+
| `isCustomFieldConstant(field)` | Constant 型カスタムフィールドか判定 |
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## ライセンス
|
|
88
|
+
|
|
89
|
+
MIT
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* カスタムフィールドのフォーマット種別(変換系)
|
|
6
6
|
*/
|
|
7
|
-
type CustomFieldFormatType = 'string' | 'date' | 'number' | 'escape' | 'toc' | 'truncate' | 'stripHtml' | 'slug' | 'lowercase' | 'uppercase' | 'default' | 'count' | 'first' | 'last' | 'join' | 'url' | 'picture' | 'img' | 'srcset' | 'fileLink' | 'relationList';
|
|
7
|
+
type CustomFieldFormatType = 'string' | 'date' | 'number' | 'escape' | 'toc' | 'truncate' | 'stripHtml' | 'slug' | 'lowercase' | 'uppercase' | 'default' | 'count' | 'first' | 'last' | 'join' | 'url' | 'picture' | 'img' | 'srcset' | 'fileLink' | 'relationList' | 'constant';
|
|
8
8
|
/**
|
|
9
9
|
* ソート設定
|
|
10
10
|
*/
|
|
@@ -68,7 +68,7 @@ type CustomFieldTransform = {
|
|
|
68
68
|
/** 元となる式(例: "{$this.title} - {$this.subtitle}") */
|
|
69
69
|
source: string;
|
|
70
70
|
/** フォーマット種別 */
|
|
71
|
-
type
|
|
71
|
+
type: Exclude<CustomFieldFormatType, 'relationList' | 'constant'>;
|
|
72
72
|
/** フォーマット文字列(例: "YYYY年MM月DD日", "#,###円") */
|
|
73
73
|
format?: string;
|
|
74
74
|
/** truncate用の文字数 */
|
|
@@ -109,11 +109,23 @@ type CustomFieldRelationList = {
|
|
|
109
109
|
/** ページネーション設定(任意) */
|
|
110
110
|
pagination?: RelationListPaginationConfig;
|
|
111
111
|
};
|
|
112
|
+
/**
|
|
113
|
+
* カスタムフィールド(定数)
|
|
114
|
+
* コンテンツに依存しない固定値を出力する
|
|
115
|
+
*/
|
|
116
|
+
type CustomFieldConstant = {
|
|
117
|
+
/** 出力フィールド名 */
|
|
118
|
+
field: string;
|
|
119
|
+
/** フォーマット種別(constant 固定) */
|
|
120
|
+
type: 'constant';
|
|
121
|
+
/** 固定値(string, number, boolean, array, object) */
|
|
122
|
+
value: unknown;
|
|
123
|
+
};
|
|
112
124
|
/**
|
|
113
125
|
* カスタムフィールド設定
|
|
114
|
-
* 変換系(CustomFieldTransform
|
|
126
|
+
* 変換系(CustomFieldTransform)、RelationList(CustomFieldRelationList)、定数(CustomFieldConstant)のユニオン型
|
|
115
127
|
*/
|
|
116
|
-
type CustomField = CustomFieldTransform | CustomFieldRelationList;
|
|
128
|
+
type CustomField = CustomFieldTransform | CustomFieldRelationList | CustomFieldConstant;
|
|
117
129
|
/**
|
|
118
130
|
* Relation 展開設定
|
|
119
131
|
* リレーションフィールドを展開し、さらにネストした relation も展開可能
|
|
@@ -319,6 +331,10 @@ declare function isListPageRecipeWithPagination(recipe: ListPageRecipe): recipe
|
|
|
319
331
|
* ListPageRecipe がページネーション無効かどうかを判定
|
|
320
332
|
*/
|
|
321
333
|
declare function isListPageRecipeWithoutPagination(recipe: ListPageRecipe): recipe is ListPageRecipeWithoutPagination;
|
|
334
|
+
/**
|
|
335
|
+
* CustomField が定数(Constant)かどうかを判定
|
|
336
|
+
*/
|
|
337
|
+
declare function isCustomFieldConstant(field: CustomField): field is CustomFieldConstant;
|
|
322
338
|
/**
|
|
323
339
|
* CustomField が RelationList かどうかを判定
|
|
324
340
|
*/
|
|
@@ -328,4 +344,4 @@ declare function isCustomFieldRelationList(field: CustomField): field is CustomF
|
|
|
328
344
|
*/
|
|
329
345
|
declare function isCustomFieldTransform(field: CustomField): field is CustomFieldTransform;
|
|
330
346
|
|
|
331
|
-
export { type ContentTypeRecipe, type CustomField, type CustomFieldFormatType, type CustomFieldRelationList, type CustomFieldTransform, type DetailPageRecipe, type FrelioBuildDataRecipe, type ListPageRecipe, type ListPageRecipePaginationConfig, type ListPageRecipeWithPagination, type ListPageRecipeWithoutPagination, type PaginatedListOutput, type PaginationConfigBase, type RecipeFilter, type RecipeFilterOperator, type RecipeRepeat, type RecipeSort, type RelationExpand, type RelationListPaginationConfig, type StaticPageRecipe, type TemplateIncludes, type TocEntry, isCustomFieldRelationList, isCustomFieldTransform, isListPageRecipeWithPagination, isListPageRecipeWithoutPagination };
|
|
347
|
+
export { type ContentTypeRecipe, type CustomField, type CustomFieldConstant, type CustomFieldFormatType, type CustomFieldRelationList, type CustomFieldTransform, type DetailPageRecipe, type FrelioBuildDataRecipe, type ListPageRecipe, type ListPageRecipePaginationConfig, type ListPageRecipeWithPagination, type ListPageRecipeWithoutPagination, type PaginatedListOutput, type PaginationConfigBase, type RecipeFilter, type RecipeFilterOperator, type RecipeRepeat, type RecipeSort, type RelationExpand, type RelationListPaginationConfig, type StaticPageRecipe, type TemplateIncludes, type TocEntry, isCustomFieldConstant, isCustomFieldRelationList, isCustomFieldTransform, isListPageRecipeWithPagination, isListPageRecipeWithoutPagination };
|
package/dist/index.js
CHANGED
|
@@ -5,13 +5,16 @@ function isListPageRecipeWithPagination(recipe) {
|
|
|
5
5
|
function isListPageRecipeWithoutPagination(recipe) {
|
|
6
6
|
return recipe.pagination === void 0;
|
|
7
7
|
}
|
|
8
|
+
function isCustomFieldConstant(field) {
|
|
9
|
+
return field.type === "constant";
|
|
10
|
+
}
|
|
8
11
|
function isCustomFieldRelationList(field) {
|
|
9
12
|
return field.type === "relationList";
|
|
10
13
|
}
|
|
11
14
|
function isCustomFieldTransform(field) {
|
|
12
|
-
return field.type !== "relationList";
|
|
15
|
+
return field.type !== void 0 && field.type !== "relationList" && field.type !== "constant";
|
|
13
16
|
}
|
|
14
17
|
|
|
15
|
-
export { isCustomFieldRelationList, isCustomFieldTransform, isListPageRecipeWithPagination, isListPageRecipeWithoutPagination };
|
|
18
|
+
export { isCustomFieldConstant, isCustomFieldRelationList, isCustomFieldTransform, isListPageRecipeWithPagination, isListPageRecipeWithoutPagination };
|
|
16
19
|
//# sourceMappingURL=index.js.map
|
|
17
20
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/guards.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"sources":["../src/guards.ts"],"names":[],"mappings":";AAiBO,SAAS,+BACd,MAAA,EACwC;AACxC,EAAA,OAAO,OAAO,UAAA,KAAe,MAAA;AAC/B;AAKO,SAAS,kCACd,MAAA,EAC2C;AAC3C,EAAA,OAAO,OAAO,UAAA,KAAe,MAAA;AAC/B;AAKO,SAAS,sBACd,KAAA,EAC8B;AAC9B,EAAA,OAAO,MAAM,IAAA,KAAS,UAAA;AACxB;AAKO,SAAS,0BACd,KAAA,EACkC;AAClC,EAAA,OAAO,MAAM,IAAA,KAAS,cAAA;AACxB;AAKO,SAAS,uBACd,KAAA,EAC+B;AAC/B,EAAA,OAAO,MAAM,IAAA,KAAS,MAAA,IAAa,MAAM,IAAA,KAAS,cAAA,IAAkB,MAAM,IAAA,KAAS,UAAA;AACrF","file":"index.js","sourcesContent":["/**\n * Type guard functions for Frelio build data recipe.\n */\n\nimport type {\n ListPageRecipe,\n ListPageRecipeWithPagination,\n ListPageRecipeWithoutPagination,\n CustomField,\n CustomFieldConstant,\n CustomFieldRelationList,\n CustomFieldTransform,\n} from './types.js'\n\n/**\n * ListPageRecipe がページネーション有効かどうかを判定\n */\nexport function isListPageRecipeWithPagination(\n recipe: ListPageRecipe\n): recipe is ListPageRecipeWithPagination {\n return recipe.pagination !== undefined\n}\n\n/**\n * ListPageRecipe がページネーション無効かどうかを判定\n */\nexport function isListPageRecipeWithoutPagination(\n recipe: ListPageRecipe\n): recipe is ListPageRecipeWithoutPagination {\n return recipe.pagination === undefined\n}\n\n/**\n * CustomField が定数(Constant)かどうかを判定\n */\nexport function isCustomFieldConstant(\n field: CustomField\n): field is CustomFieldConstant {\n return field.type === 'constant'\n}\n\n/**\n * CustomField が RelationList かどうかを判定\n */\nexport function isCustomFieldRelationList(\n field: CustomField\n): field is CustomFieldRelationList {\n return field.type === 'relationList'\n}\n\n/**\n * CustomField が変換系(Transform)かどうかを判定\n */\nexport function isCustomFieldTransform(\n field: CustomField\n): field is CustomFieldTransform {\n return field.type !== undefined && field.type !== 'relationList' && field.type !== 'constant'\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-time/frelio-data-json-recipe",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.17",
|
|
4
4
|
"description": "Type definitions for frelio data JSON recipe",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
"scripts": {
|
|
20
20
|
"build": "tsup",
|
|
21
21
|
"dev": "tsup --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
22
24
|
"prepublishOnly": "npm run build"
|
|
23
25
|
},
|
|
24
26
|
"publishConfig": {
|
|
@@ -39,7 +41,8 @@
|
|
|
39
41
|
"license": "MIT",
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"tsup": "^8.5.0",
|
|
42
|
-
"typescript": "^5.7.0"
|
|
44
|
+
"typescript": "^5.7.0",
|
|
45
|
+
"vitest": "^4.0.18"
|
|
43
46
|
},
|
|
44
47
|
"engines": {
|
|
45
48
|
"node": ">=18"
|