Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deps/fff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { StrictPresetOptions } from "https://deno.land/x/[email protected]/src/utils/presets/strict.ts";
123 changes: 123 additions & 0 deletions presets/fff.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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",
},
...fffExtra(options),
// markdown content
{
name: "content",
type: "markdown",
label: "Content",
},
];

export const fffPreset = (options?: Options) => ({
article: () => article(options),
});

export default fffPreset;