"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { postTypeDiscovery: () => postTypeDiscovery, strict: () => strict, strictCategories: () => strictCategories, strictDraft: () => strictDraft, strictMedia: () => strictMedia, strictVisibility: () => strictVisibility, toJF2FeedChild: () => toJF2FeedChild, toJSONFeedItem: () => toJSONFeedItem, transform: () => transform }); module.exports = __toCommonJS(src_exports); // src/utils/presets/strict.ts var strictMediaTransform = (options, media, alt) => typeof media === "string" ? options?.type === "object" ? { alt, src: media } : media : options?.type === "string" ? media?.src : media; var strictMedia = ({ media: options } = {}) => ({ alt: ({ alt, image, images }) => alt ?? (options?.type === "string" && (image || images)) ? (image ?? images?.[0]).alt : void 0, audio: ({ audio }) => strictMediaTransform(options, audio), image: ({ alt, image, images }) => strictMediaTransform( options, options?.array === false ? image ?? images?.[0] : image, alt ), images: ({ alt, image, images }) => [...images ?? [], ...options?.array ? [image] : []].map( (image2, index) => strictMediaTransform(options, image2, index === 0 ? alt : void 0) ), video: ({ video }) => strictMediaTransform(options, video) }); var strictCategories = ({ categories: options } = {}) => ({ categories: ({ categories, tags }) => options === true ? [...categories ?? [], ...tags ?? []] : categories, tags: ({ categories, tags }) => options === false ? [...tags ?? [], ...categories ?? []] : tags }); var strictDraft = ({ draft: options } = {}) => ({ draft: ({ draft, flags }) => draft ?? options === true ? flags?.includes("draft") : void 0, flags: ({ draft, flags }) => options === false && draft ? [...flags ?? [], "draft"] : flags }); var strictVisibility = ({ visibility: options } = {}) => ({ flags: ({ flags, visibility }) => options === false && visibility ? [...flags ?? [], visibility] : flags, visibility: ({ flags, visibility }) => visibility ?? options === true ? flags?.find((flag) => ["private", "public", "unlisted"].includes(flag)) : void 0 }); var strict = (options) => ({ ...strictCategories(options), ...strictDraft(options), ...strictMedia(options), ...strictVisibility(options) }); // src/utils/ptd.ts var postTypeDiscovery = (fm) => { if (fm.flags?.includes("event")) return "event"; else if (fm.rsvp && ["interested", "maybe", "no", "yes"].includes(fm.rsvp.toLowerCase())) return "rsvp"; else if (fm.repost_of) return "repost"; else if (fm.like_of) return "like"; else if (fm.bookmark_of) return "bookmark"; else if (fm.in_reply_to) return "reply"; else if (fm.video) return "video"; else if (fm.audio) return "audio"; else if (fm.title) return "article"; else if (fm.images) return "photo"; else return "note"; }; // src/utils/transform.ts var transform = (fm, presets) => { for (const preset of presets) { for (const [output, input] of Object.entries(preset)) { fm = { ...fm, [output]: (typeof input === "function" ? input(fm) : fm[input]) ?? fm[output] }; } } return fm; }; // src/utils/feed.ts var toJSONFeedItem = (fm, item) => { fm = transform(fm, [strict({ categories: false, media: { array: false, type: "string" } })]); return { ...item, /** * Treats keys starts with underscore as Custom JSON Feed Extensions * @see {@link https://www.jsonfeed.org/version/1.1/#extensions-a-name-extensions-a} */ ...Object.fromEntries( Object.entries(fm).filter(([key, value]) => key.startsWith("_") && typeof value === "object") ), _indieweb: { "bookmark-of": fm.bookmark_of, "in-reply-to": fm.in_reply_to, "like-of": fm.like_of, "repost-of": fm.repost_of, "syndication": fm.syndication, "type": postTypeDiscovery(fm), ...fm._indieweb, ...item?._indieweb }, authors: fm.authors, date_modified: fm.updated, date_published: fm.published ?? fm.created, image: fm.image, language: fm.lang, summary: fm.summary, tags: fm.tags, title: fm.title }; }; var toJF2FeedChild = (fm, child) => { fm = transform(fm, [strict({ categories: false, media: { array: false, type: "string" } })]); return { ...child, author: fm.authors && { name: fm.authors[0].name, photo: fm.authors[0].avatar, type: "card", url: fm.authors[0].url }, category: fm.tags, featured: fm.title && fm.image, lang: fm.lang, name: fm.title, photo: fm.image, published: fm.published ?? fm.created, type: "entry", updated: fm.updated }; }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { postTypeDiscovery, strict, strictCategories, strictDraft, strictMedia, strictVisibility, toJF2FeedChild, toJSONFeedItem, transform });