astro-loader-hashnode
Version:
Astro content loader for seamlessly integrating Hashnode blog posts into your Astro website using the Content Layer API
153 lines (152 loc) • 5.69 kB
TypeScript
/**
* Astro Loader for Hashnode - Clean, modular API
*
* This package provides Astro content loaders for Hashnode blog content.
* It offers a clean wrapper around the Hashnode GraphQL API with built-in
* caching, type safety, and utilities for content transformation.
*
* @example Basic usage:
* ```typescript
* import { hashnodeLoader } from 'astro-loader-hashnode';
*
* export const collections = {
* blog: defineCollection({
* loader: hashnodeLoader({
* publicationHost: 'blog.example.com'
* })
* })
* };
* ```
*
* @example Advanced usage with multiple loaders:
* ```typescript
* import { postsLoader, seriesLoader, createHashnodeClient } from 'astro-loader-hashnode';
*
* export const collections = {
* posts: defineCollection({
* loader: postsLoader({
* publicationHost: 'blog.example.com',
* maxPosts: 100,
* includeComments: true
* })
* }),
* series: defineCollection({
* loader: seriesLoader({
* publicationHost: 'blog.example.com',
* includePosts: true
* })
* })
* };
* ```
*/
export { postsLoader, seriesLoader, searchLoader, draftsLoader, } from './loaders/index.js';
export { PostsLoader, SeriesLoader, SearchLoader, DraftsLoader, BaseHashnodeLoader, createLoader, } from './loaders/index.js';
export { HashnodeClient, createHashnodeClient } from './api/client.js';
export type { HashnodeClientOptions, GraphQLResponse, PostsResponse, SeriesResponse, SearchResponse, } from './api/client.js';
export type { HashnodePost, HashnodeAuthor, HashnodeSeries, HashnodePublication, HashnodeTag, HashnodeComment, HashnodeStaticPage, TransformedPost, TransformedSeries, TransformedSearch, TransformedDraft, TableOfContentsItem, } from './types/hashnode.js';
export type { BaseLoaderOptions, PostsLoaderOptions, SeriesLoaderOptions, SearchLoaderOptions, DraftsLoaderOptions, } from './types/loader.js';
export type { PostData, SeriesData, SearchResultData, DraftData, } from './types/schema.js';
export { extractTextFromHtml, generateExcerpt, calculateReadingTime, countWords, normalizeContent, extractHeadings, generateTableOfContents, processContent, generateSEOMetadata, optimizeTitle, generateMetaDescription, generateKeywords, generateJSONLD, validateSEOMetadata, formatDate, timeAgo, isRecent, createSlug, normalizeUrl, extractDomain, isValidUrl, makeAbsoluteUrl, buildUrl, parseUrl, cleanUrl, generateSharingUrls, generateCanonicalUrl, extractSlugFromUrl, isSameDomain, generateSitemapEntry, processPostData, } from './utils/index.js';
export type { SEOMetadata } from './utils/index.js';
/**
* Create a Hashnode posts loader (primary entry point)
*
* This is the main function most users should use. It creates a loader
* that fetches blog posts from a Hashnode publication.
*
* @param options - Configuration options for the loader
* @returns Astro Loader instance
*
* @example
* ```typescript
* import { hashnodeLoader } from 'astro-loader-hashnode';
*
* export const collections = {
* blog: defineCollection({
* loader: hashnodeLoader({
* publicationHost: 'blog.example.com',
* maxPosts: 100,
* includeComments: true,
* includeCoAuthors: true
* })
* })
* };
* ```
*/
export declare function hashnodeLoader(options: import('./types/loader.js').PostsLoaderOptions): import("astro/loaders").Loader;
/**
* Create multiple loaders for a complete Hashnode setup
*
* @param baseOptions - Base configuration options
* @returns Object with multiple pre-configured loaders
*
* @example
* ```typescript
* import { createHashnodeLoaders } from 'astro-loader-hashnode';
*
* const { posts, series, drafts } = createHashnodeLoaders({
* publicationHost: 'blog.example.com',
* token: process.env.HASHNODE_TOKEN
* });
*
* export const collections = {
* posts: defineCollection({ loader: posts }),
* series: defineCollection({ loader: series }),
* drafts: defineCollection({ loader: drafts })
* };
* ```
*/
export declare function createHashnodeLoaders(baseOptions: import('./types/loader.js').BaseLoaderOptions): {
posts: import("astro/loaders").Loader;
series: import("astro/loaders").Loader;
drafts: import("astro/loaders").Loader | undefined;
search: (searchTerms: string[]) => import("astro/loaders").Loader;
};
/**
* Create a simple blog setup with just posts
*
* @param options - Posts loader options
* @returns Object with posts loader
*
* @example
* ```typescript
* import { createBlog } from 'astro-loader-hashnode';
*
* export const collections = createBlog({
* publicationHost: 'blog.example.com'
* });
* ```
*/
export declare function createBlog(options: import('./types/loader.js').PostsLoaderOptions): {
posts: {
loader: import("astro/loaders").Loader;
};
};
/**
* Create a complete publication setup with all content types
*
* @param options - Base loader options
* @returns Object with all available loaders
*
* @example
* ```typescript
* import { createPublication } from 'astro-loader-hashnode';
*
* export const collections = createPublication({
* publicationHost: 'blog.example.com',
* token: process.env.HASHNODE_TOKEN,
* maxPosts: 200
* });
* ```
*/
export declare function createPublication(baseOptions: import('./types/loader.js').BaseLoaderOptions): Record<string, {
loader: import("astro/loaders").Loader;
}>;
export declare const packageName = "astro-loader-hashnode";
/**
* Check if the loader is compatible with the current Astro version
*
* @returns boolean indicating compatibility
*/
export declare function checkCompatibility(): Promise<boolean>;
export default hashnodeLoader;