@c-time/frelio-data-json
v1.4.1
Published
Type definitions for frelio data JSON output
Downloads
623
Readme
@c-time/frelio-data-json
Frelio SSG の中間データフォーマット(data-json)の型定義とバリデーション。
概要
Frelio の静的サイト生成(SSG)は2段階で処理される:
- data-json 生成 (
@c-time/frelio-data-json-generator) — コンテンツから中間 JSON を生成 - HTML 生成 (
@c-time/frelio-gentl) — 中間 JSON + テンプレートから HTML を生成
このパッケージは、その中間データのフォーマットを定義する型定義ライブラリ。ランタイム依存なし。
インストール
npm install @c-time/frelio-data-json使用例
import { isFrelioDataJson, isFrelioDataJsonArray } from '@c-time/frelio-data-json'
import type { FrelioDataJson } from '@c-time/frelio-data-json'
const entry: FrelioDataJson = {
type: 'create',
template: 'news/detail/index.html',
outputFile: 'news/2024/hello-world.html',
data: {
title: 'Hello World',
body: '<p>記事本文</p>',
},
}
// 型ガードでバリデーション
if (isFrelioDataJson(entry)) {
console.log(entry.outputFile)
}
if (isFrelioDataJsonArray([entry])) {
console.log('有効な data-json 配列')
}API
型
FrelioDataJson
| プロパティ | 型 | 説明 |
|-----------|-----|------|
| type | 'create' \| 'update' \| 'delete' | 操作タイプ |
| template | string | テンプレートファイルのパス |
| outputFile | string | 出力ファイルのパス |
| data | Record<string, unknown> | テンプレートに渡すデータ |
関数
| 関数 | 説明 |
|------|------|
| isFrelioDataJson(value) | 値が有効な FrelioDataJson か判定する型ガード |
| isFrelioDataJsonArray(value) | 値が有効な FrelioDataJson[] か判定する型ガード |
ライセンス
MIT
