astro-loader-bluesky-posts
Version:
Astro loader for loading Bluesky posts and threads using post URLs or AT-URIs.
96 lines (91 loc) • 3.53 kB
TypeScript
import { RichTextProps } from '@atproto/api';
import { z } from 'astro/zod';
import { Loader } from 'astro/loaders';
declare const BlueskyPostsLoaderConfigSchema: z.ZodObject<{
/**
* List of Bluesky post URLs or {@link https://atproto.com/specs/at-uri-scheme AT-URIs}.
*/
uris: z.ZodArray<z.ZodString, "many">;
/**
* The type of text to display for links when generating renderable HTML:
* - `'domain-path'`: Shows the link's domain and path.
* - `'post-text'`: Uses the link text as shown in the post.
*
* @default 'post-text'
*/
linkTextType: z.ZodDefault<z.ZodEnum<["domain-path", "post-text"]>>;
/**
* The way for processing `\n` when generating renderable HTML:
* - `'none'`: Keep as is.
* - `'break'`: Replace consecutive `\n` with `<br>`.
* - `'paragraph'`: Wrap paragraphs with `<p>` while removing standalone `\n`.
*
* @default 'none'
*/
newlineHandling: z.ZodDefault<z.ZodEnum<["none", "break", "paragraph"]>>;
/**
* Whether to fetch the post's thread including replies and parents.
*
* @default false
*/
fetchThread: z.ZodDefault<z.ZodBoolean>;
/**
* The depth of the descendant post tree to fetch if fetching the thread.
* Specifies how many levels of reply depth should be included.
*
* @default 1
*/
threadDepth: z.ZodDefault<z.ZodNumber>;
/**
* The height of the ancestor post tree to fetch if fetching the thread.
* Specifies how many levels of parent posts should be included.
*
* @default 1
*/
threadParentHeight: z.ZodDefault<z.ZodNumber>;
/**
* Fetches only the post author's replies at the specified `threadDepth`.
*
* - `false` (default): Includes all replies without filtering.
* - `true`: Returns only the author's replies as a flat array, ignoring `threadParentHeight`,
* with no `parent` field.
*
* @default false
*/
fetchOnlyAuthorReplies: z.ZodDefault<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
uris: string[];
linkTextType: "domain-path" | "post-text";
newlineHandling: "none" | "break" | "paragraph";
fetchThread: boolean;
threadDepth: number;
threadParentHeight: number;
fetchOnlyAuthorReplies: boolean;
}, {
uris: string[];
linkTextType?: "domain-path" | "post-text" | undefined;
newlineHandling?: "none" | "break" | "paragraph" | undefined;
fetchThread?: boolean | undefined;
threadDepth?: number | undefined;
threadParentHeight?: number | undefined;
fetchOnlyAuthorReplies?: boolean | undefined;
}>;
type BlueskyPostsLoaderUserConfig = z.input<typeof BlueskyPostsLoaderConfigSchema>;
/**
* Renders a post as HTML based on the given configuration options.
*/
declare function renderPostAsHtml(richText: RichTextProps, options: {
linkTextType: z.output<typeof BlueskyPostsLoaderConfigSchema>['linkTextType'];
newlineHandling: z.output<typeof BlueskyPostsLoaderConfigSchema>['newlineHandling'];
}): string;
/**
* Converts an AT-URI to a post URI.
*/
declare function atUriToPostUri(atUri: string): string;
/**
* Astro loader for loading Bluesky posts and threads using post URLs or AT-URIs.
*
* @see https://github.com/lin-stephanie/astro-loaders/tree/main/packages/astro-loader-bluesky-posts
*/
declare function blueskyPostsLoader(userConfig: BlueskyPostsLoaderUserConfig): Loader;
export { type BlueskyPostsLoaderUserConfig, atUriToPostUri, blueskyPostsLoader, renderPostAsHtml };