From fe849227d21983b949451c1da7bbe501c7977005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 26 Mar 2024 22:59:31 +0800 Subject: [PATCH 1/4] feat: create fff preset --- deps/fff.ts | 3 ++ presets/fff.ts | 124 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 127 insertions(+) create mode 100644 deps/fff.ts create mode 100644 presets/fff.ts diff --git a/deps/fff.ts b/deps/fff.ts new file mode 100644 index 0000000..93c5268 --- /dev/null +++ b/deps/fff.ts @@ -0,0 +1,3 @@ +export type { StrictPresetOptions } from "https://deno.land/x/fff@v1.2.1/src/utils/presets/strict.ts"; + +// export type * from "https://deno.land/x/fff@v1.2.1/src/types.ts"; diff --git a/presets/fff.ts b/presets/fff.ts new file mode 100644 index 0000000..733db96 --- /dev/null +++ b/presets/fff.ts @@ -0,0 +1,124 @@ +import type { StrictPresetOptions } from "../deps/fff.ts"; +import { Field } from "../types.ts"; + +export interface Options { + /** {@link https://fff.js.org/references/fff-flavored-frontmatter.strictpresetoptions.html} */ + strict?: StrictPresetOptions; + /** {@link https://fff.js.org/version/1.2.html#extra} */ + extra?: { + authors?: false; + lang?: false; + location?: true; // TODO + syndication?: true; // TODO + checkin?: true; // TODO + rsvp?: true; // TODO + }; +} + +/** {@link https://fff.js.org/version/1.2.html#base} */ +export const fffBase = (options: Options): (Field | string)[] => [ + "title: text", + "summary: text", + ...(options.strict?.categories === false ? [] : [ + { + name: "categories", + type: "list", + label: "Categories", + init: (field) => { + const { data } = field.cmsContent; + field.options = data.site?.search.values("categories"); + }, + } satisfies Field, + ]), + { + name: "tags", + type: "list", + label: "Tags", + init: (field) => { + const { data } = field.cmsContent; + field.options = data.site?.search.values("tags"); + }, + }, + { + name: "flags", + type: "list", + label: "Flags", + init: (field) => { + const { data } = field.cmsContent; + field.options = data.site?.search.values("flags"); + }, + }, +]; + +/** {@link https://fff.js.org/version/1.2.html#extra} */ +export const fffExtra = (options: Options): (Field | string)[] => [ + ...(options.extra?.authors === false ? [] : [ + { + name: "authors", + type: "object-list", + /** {@link https://fff.js.org/version/1.2.html#fffauthor} */ + fields: [ + "name: text", + "url: url", + "avatar: url", + ], + } satisfies Field, + ]), + ...(options.extra?.lang === false ? [] : [ + { + name: "lang", + type: "text", + label: "Language", + } satisfies Field, + ]), + ...(options.strict?.draft === false ? [] : [ + { + name: "draft", + type: "checkbox", + label: "Draft", + description: "If checked, the post will not be published.", + } satisfies Field, + ]), + ...(options.strict?.visibility === false ? [] : [ + { + name: "visibility", + type: "select", + label: "Visibility", + options: [ + "public", + "unlisted", + "private", + ], + } satisfies Field, + ]), +]; + +export const article = (options: Options): (Field | string)[] => [ + ...fffBase(options), + // https://fff.js.org/version/1.2.html#datetime + "created: date", + "updated: date", + "published: date", + // https://fff.js.org/version/1.2.html#media + { + // https://fff.js.org/version/1.2.html#image + // `images` / Object Media is not supported yet. + name: "image", + type: "file", + label: "Image", + uploads: "src:images", + }, + ...fffExtra(options), + // markdown content + { + name: "content", + type: "markdown", + label: "Content", + }, +]; + +export const fffPreset = (options: Options) => ({ + article: () => article(options), +}); + +export default fffPreset; From e63277a1e09d802dc478512d3d219c5a1f197c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:03:41 +0800 Subject: [PATCH 2/4] chore(deps): remove useless export --- deps/fff.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/deps/fff.ts b/deps/fff.ts index 93c5268..a4a3de5 100644 --- a/deps/fff.ts +++ b/deps/fff.ts @@ -1,3 +1 @@ export type { StrictPresetOptions } from "https://deno.land/x/fff@v1.2.1/src/utils/presets/strict.ts"; - -// export type * from "https://deno.land/x/fff@v1.2.1/src/types.ts"; From 125d226492fcb5e21be40ad6e5dd5b6ae7fa3dae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:09:42 +0800 Subject: [PATCH 3/4] fix: make options optional --- presets/fff.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/presets/fff.ts b/presets/fff.ts index 733db96..caa25db 100644 --- a/presets/fff.ts +++ b/presets/fff.ts @@ -16,10 +16,10 @@ export interface Options { } /** {@link https://fff.js.org/version/1.2.html#base} */ -export const fffBase = (options: Options): (Field | string)[] => [ +export const fffBase = (options?: Options): (Field | string)[] => [ "title: text", "summary: text", - ...(options.strict?.categories === false ? [] : [ + ...(options?.strict?.categories === false ? [] : [ { name: "categories", type: "list", @@ -51,8 +51,8 @@ export const fffBase = (options: Options): (Field | string)[] => [ ]; /** {@link https://fff.js.org/version/1.2.html#extra} */ -export const fffExtra = (options: Options): (Field | string)[] => [ - ...(options.extra?.authors === false ? [] : [ +export const fffExtra = (options?: Options): (Field | string)[] => [ + ...(options?.extra?.authors === false ? [] : [ { name: "authors", type: "object-list", @@ -64,14 +64,14 @@ export const fffExtra = (options: Options): (Field | string)[] => [ ], } satisfies Field, ]), - ...(options.extra?.lang === false ? [] : [ + ...(options?.extra?.lang === false ? [] : [ { name: "lang", type: "text", label: "Language", } satisfies Field, ]), - ...(options.strict?.draft === false ? [] : [ + ...(options?.strict?.draft === false ? [] : [ { name: "draft", type: "checkbox", @@ -79,7 +79,7 @@ export const fffExtra = (options: Options): (Field | string)[] => [ description: "If checked, the post will not be published.", } satisfies Field, ]), - ...(options.strict?.visibility === false ? [] : [ + ...(options?.strict?.visibility === false ? [] : [ { name: "visibility", type: "select", @@ -93,7 +93,7 @@ export const fffExtra = (options: Options): (Field | string)[] => [ ]), ]; -export const article = (options: Options): (Field | string)[] => [ +export const article = (options?: Options): (Field | string)[] => [ ...fffBase(options), // https://fff.js.org/version/1.2.html#datetime "created: date", @@ -117,7 +117,7 @@ export const article = (options: Options): (Field | string)[] => [ }, ]; -export const fffPreset = (options: Options) => ({ +export const fffPreset = (options?: Options) => ({ article: () => article(options), }); From 33570a751b77ebbc4eca371cecfb6f03e610a79d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Tue, 26 Mar 2024 23:18:01 +0800 Subject: [PATCH 4/4] fix: remove image uploads --- presets/fff.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/presets/fff.ts b/presets/fff.ts index caa25db..38f334e 100644 --- a/presets/fff.ts +++ b/presets/fff.ts @@ -106,7 +106,6 @@ export const article = (options?: Options): (Field | string)[] => [ name: "image", type: "file", label: "Image", - uploads: "src:images", }, ...fffExtra(options), // markdown content