@asteroidcms/core-utils 0.1.7 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { InMemoryCacheConfig, ApolloClientOptions, ApolloClient, DocumentNode } from '@apollo/client';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
 
3
4
  type AsteroidCMSConfig = {
4
5
  /** Base URL of the Asteroid CMS API (e.g. https://cms-api.example.com). */
@@ -227,4 +228,188 @@ declare function extractHeadingsFromElement(root: HTMLElement, options?: Extract
227
228
  scrollMarginTop?: number;
228
229
  }): ExtractedHeading[];
229
230
 
230
- export { type AsteroidCMSConfig, type CmsMutateOptions, type CmsSearchCondition, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector$1 as FieldSelector, type HeadingLevel, type MutationType, type ParseRichTextOptions, type ReferenceExpansion$1 as ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type UseCmsContentOptions, buildCmsMutation, buildCmsQuery, cmsImage, cmsMutate, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseRichText, removeEmptyParagraphs, slugify };
231
+ interface ISeoValues {
232
+ title: string;
233
+ siteName: string;
234
+ twitter: string;
235
+ description: string;
236
+ url: string;
237
+ keywords: string;
238
+ image?: string;
239
+ noindex?: boolean;
240
+ manifestUrl?: string;
241
+ }
242
+ type SeoClientProps = {
243
+ title: string;
244
+ description: string;
245
+ url: string;
246
+ siteName?: string;
247
+ keywords?: string;
248
+ twitter?: string;
249
+ image?: string;
250
+ noindex?: boolean;
251
+ };
252
+ /** Theme colors used when generating dynamic OG images. */
253
+ interface AsteroidOgImagePalette {
254
+ background: string;
255
+ foreground: string;
256
+ accent: string;
257
+ accentMuted?: string;
258
+ mutedText?: string;
259
+ }
260
+ interface AsteroidOgImageParams {
261
+ title: string;
262
+ subtitle?: string;
263
+ eyebrow?: string;
264
+ type?: "article" | "listing";
265
+ }
266
+ /** Options for the generic per-page SEO builder (landing pages, etc.). */
267
+ interface AsteroidPageSeoOptions {
268
+ /** Raw page title; the config `titleTemplate` (or the `| siteName` default) is applied. */
269
+ title: string;
270
+ description?: string;
271
+ /** Path appended to `baseUrl`. Default: `/`. */
272
+ path?: string;
273
+ keywords?: string;
274
+ /** Explicit social image URL. If absent, a generated OG image is used. */
275
+ image?: string;
276
+ /** Eyebrow label for the generated OG image. */
277
+ eyebrow?: string;
278
+ /** Open Graph object type. Default: `website`. */
279
+ ogType?: "website" | "article";
280
+ /** Mark the page as `noindex` for search engines. */
281
+ noindex?: boolean;
282
+ }
283
+ /** Site-level identity used to build the Organization/WebSite JSON-LD graph. */
284
+ interface AsteroidOrganizationConfig {
285
+ logoUrl?: string;
286
+ contactEmail?: string;
287
+ contactPhone?: string;
288
+ address?: {
289
+ street?: string;
290
+ city?: string;
291
+ country?: string;
292
+ };
293
+ /** Generic list of profile URLs (LinkedIn, X, etc.). Maps to schema.org `sameAs`. */
294
+ socials?: string[];
295
+ }
296
+ /** Site-level SEO config passed into the headless Asteroid content components. */
297
+ interface AsteroidSeoConfig {
298
+ siteName: string;
299
+ baseUrl: string;
300
+ twitter?: string;
301
+ defaultDescription?: string;
302
+ defaultKeywords?: string;
303
+ /** Path prefix for the article collection (e.g. `/blog`, `/news`, `/docs`). Default: `/blog` */
304
+ articlePath?: string;
305
+ /**
306
+ * Human label for the article collection, used in default titles/eyebrows
307
+ * (e.g. "Blog", "News", "Documentation"). Default: `"Articles"`.
308
+ */
309
+ contentLabel?: string;
310
+ /**
311
+ * Override how a raw page/article title becomes the final `<title>`.
312
+ * Default: `(title) => `${title} | ${siteName}``.
313
+ */
314
+ titleTemplate?: (title: string) => string;
315
+ ogImage?: {
316
+ palette: AsteroidOgImagePalette;
317
+ /** OG image API route path. Default: `/api/og` */
318
+ apiPath?: string;
319
+ };
320
+ /** Override dynamic OG image URL generation (e.g. custom CDN or renderer). */
321
+ getOgImageUrl?: (params: AsteroidOgImageParams) => string | undefined;
322
+ /** Site identity for the Organization/WebSite JSON-LD graph. */
323
+ organization?: AsteroidOrganizationConfig;
324
+ /** Extra schema.org @graph nodes (e.g. a ProfessionalService node). */
325
+ extraJsonLdNodes?: object[];
326
+ /** CMS base URL for resolving featured-image URLs. Required server-side for featured images. */
327
+ cmsUrl?: string;
328
+ /** URL to a PWA manifest.json. When set, a `<link rel="manifest">` is emitted. */
329
+ manifestUrl?: string;
330
+ /** Site-wide default robots policy. Per-page overrides are available on builder options. */
331
+ noindex?: boolean;
332
+ }
333
+
334
+ /** Apply the configured title template, defaulting to `${title} | ${siteName}`. */
335
+ declare function applyTitleTemplate(config: AsteroidSeoConfig, title: string): string;
336
+ declare function buildOgImageUrl(config: AsteroidSeoConfig, params: AsteroidOgImageParams): string | undefined;
337
+ type ArticleLike = {
338
+ title: string;
339
+ description?: string;
340
+ meta_description?: string;
341
+ featured_image?: string;
342
+ };
343
+ /**
344
+ * Generic per-page SEO builder. Use it directly for landing/marketing pages, or
345
+ * as the base for the article/listing wrappers below. Content-type agnostic.
346
+ */
347
+ declare function buildPageSeoValues(config: AsteroidSeoConfig, options: AsteroidPageSeoOptions): ISeoValues;
348
+ /** SEO for a single article; works for news, articles, or docs pages. */
349
+ declare function buildArticleSeoValues<TPost extends ArticleLike>(post: TPost, config: AsteroidSeoConfig, slug: string, options?: {
350
+ noindex?: boolean;
351
+ }): ISeoValues;
352
+ /** SEO for an article collection / category listing (any content type). */
353
+ declare function buildArticleListingSeoValues(config: AsteroidSeoConfig, options?: {
354
+ categoryName?: string;
355
+ categorySlug?: string;
356
+ noindex?: boolean;
357
+ }): ISeoValues;
358
+ declare function seoValuesToClientProps(values: ISeoValues): SeoClientProps;
359
+
360
+ /** Build the site-wide Organization + WebSite @graph from config. */
361
+ declare function buildSiteJsonLd(config: AsteroidSeoConfig): object;
362
+ /** schema.org Article subtypes; pick per content kind. */
363
+ type ArticleJsonLdType = "Article" | "BlogPosting" | "NewsArticle" | "TechArticle" | (string & {});
364
+ type ArticleJsonLdProps = {
365
+ title: string;
366
+ description: string;
367
+ url: string;
368
+ /** Site name; used as the author fallback. */
369
+ siteName: string;
370
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
371
+ siteUrl: string;
372
+ /** schema.org @type. Default: `"Article"`. */
373
+ articleType?: ArticleJsonLdType;
374
+ image?: string;
375
+ authorName?: string;
376
+ publishedTime?: string;
377
+ tags?: string[];
378
+ category?: string;
379
+ };
380
+ declare function buildArticleJsonLd(props: ArticleJsonLdProps): object;
381
+ type CollectionJsonLdProps = {
382
+ name: string;
383
+ description: string;
384
+ url: string;
385
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
386
+ siteUrl: string;
387
+ };
388
+ declare function buildCollectionJsonLd(props: CollectionJsonLdProps): object;
389
+ type WebPageJsonLdProps = {
390
+ name: string;
391
+ description: string;
392
+ url: string;
393
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
394
+ siteUrl: string;
395
+ };
396
+ /** Generic WebPage node for landing/marketing pages with no article concept. */
397
+ declare function buildWebPageJsonLd(props: WebPageJsonLdProps): object;
398
+
399
+ type OgImageVariant = "article" | "listing";
400
+ interface OgImageContentParams {
401
+ title: string;
402
+ subtitle?: string;
403
+ eyebrow?: string;
404
+ siteName?: string;
405
+ palette: AsteroidOgImagePalette;
406
+ variant?: OgImageVariant;
407
+ }
408
+ interface ParsedOgImageParams extends OgImageContentParams {
409
+ variant: OgImageVariant;
410
+ }
411
+ declare function parseOgImageSearchParams(searchParams: URLSearchParams): ParsedOgImageParams;
412
+ /** JSX layout consumed by `next/og` ImageResponse and compatible OG endpoints. */
413
+ declare function OgImageContent({ title, subtitle, eyebrow, siteName, palette, variant, }: OgImageContentParams): react_jsx_runtime.JSX.Element;
414
+
415
+ export { type ArticleJsonLdProps, type ArticleJsonLdType, type AsteroidCMSConfig, type AsteroidOgImagePalette, type AsteroidOgImageParams, type AsteroidOrganizationConfig, type AsteroidPageSeoOptions, type AsteroidSeoConfig, type CmsMutateOptions, type CmsSearchCondition, type CollectionJsonLdProps, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector$1 as FieldSelector, type HeadingLevel, type ISeoValues, type MutationType, OgImageContent, type OgImageContentParams, type OgImageVariant, type ParseRichTextOptions, type ParsedOgImageParams, type ReferenceExpansion$1 as ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type SeoClientProps, type UseCmsContentOptions, type WebPageJsonLdProps, applyTitleTemplate, buildArticleJsonLd, buildArticleListingSeoValues, buildArticleSeoValues, buildCmsMutation, buildCmsQuery, buildCollectionJsonLd, buildOgImageUrl, buildPageSeoValues, buildSiteJsonLd, buildWebPageJsonLd, cmsImage, cmsMutate, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseOgImageSearchParams, parseRichText, removeEmptyParagraphs, seoValuesToClientProps, slugify };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { InMemoryCacheConfig, ApolloClientOptions, ApolloClient, DocumentNode } from '@apollo/client';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
3
 
3
4
  type AsteroidCMSConfig = {
4
5
  /** Base URL of the Asteroid CMS API (e.g. https://cms-api.example.com). */
@@ -227,4 +228,188 @@ declare function extractHeadingsFromElement(root: HTMLElement, options?: Extract
227
228
  scrollMarginTop?: number;
228
229
  }): ExtractedHeading[];
229
230
 
230
- export { type AsteroidCMSConfig, type CmsMutateOptions, type CmsSearchCondition, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector$1 as FieldSelector, type HeadingLevel, type MutationType, type ParseRichTextOptions, type ReferenceExpansion$1 as ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type UseCmsContentOptions, buildCmsMutation, buildCmsQuery, cmsImage, cmsMutate, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseRichText, removeEmptyParagraphs, slugify };
231
+ interface ISeoValues {
232
+ title: string;
233
+ siteName: string;
234
+ twitter: string;
235
+ description: string;
236
+ url: string;
237
+ keywords: string;
238
+ image?: string;
239
+ noindex?: boolean;
240
+ manifestUrl?: string;
241
+ }
242
+ type SeoClientProps = {
243
+ title: string;
244
+ description: string;
245
+ url: string;
246
+ siteName?: string;
247
+ keywords?: string;
248
+ twitter?: string;
249
+ image?: string;
250
+ noindex?: boolean;
251
+ };
252
+ /** Theme colors used when generating dynamic OG images. */
253
+ interface AsteroidOgImagePalette {
254
+ background: string;
255
+ foreground: string;
256
+ accent: string;
257
+ accentMuted?: string;
258
+ mutedText?: string;
259
+ }
260
+ interface AsteroidOgImageParams {
261
+ title: string;
262
+ subtitle?: string;
263
+ eyebrow?: string;
264
+ type?: "article" | "listing";
265
+ }
266
+ /** Options for the generic per-page SEO builder (landing pages, etc.). */
267
+ interface AsteroidPageSeoOptions {
268
+ /** Raw page title; the config `titleTemplate` (or the `| siteName` default) is applied. */
269
+ title: string;
270
+ description?: string;
271
+ /** Path appended to `baseUrl`. Default: `/`. */
272
+ path?: string;
273
+ keywords?: string;
274
+ /** Explicit social image URL. If absent, a generated OG image is used. */
275
+ image?: string;
276
+ /** Eyebrow label for the generated OG image. */
277
+ eyebrow?: string;
278
+ /** Open Graph object type. Default: `website`. */
279
+ ogType?: "website" | "article";
280
+ /** Mark the page as `noindex` for search engines. */
281
+ noindex?: boolean;
282
+ }
283
+ /** Site-level identity used to build the Organization/WebSite JSON-LD graph. */
284
+ interface AsteroidOrganizationConfig {
285
+ logoUrl?: string;
286
+ contactEmail?: string;
287
+ contactPhone?: string;
288
+ address?: {
289
+ street?: string;
290
+ city?: string;
291
+ country?: string;
292
+ };
293
+ /** Generic list of profile URLs (LinkedIn, X, etc.). Maps to schema.org `sameAs`. */
294
+ socials?: string[];
295
+ }
296
+ /** Site-level SEO config passed into the headless Asteroid content components. */
297
+ interface AsteroidSeoConfig {
298
+ siteName: string;
299
+ baseUrl: string;
300
+ twitter?: string;
301
+ defaultDescription?: string;
302
+ defaultKeywords?: string;
303
+ /** Path prefix for the article collection (e.g. `/blog`, `/news`, `/docs`). Default: `/blog` */
304
+ articlePath?: string;
305
+ /**
306
+ * Human label for the article collection, used in default titles/eyebrows
307
+ * (e.g. "Blog", "News", "Documentation"). Default: `"Articles"`.
308
+ */
309
+ contentLabel?: string;
310
+ /**
311
+ * Override how a raw page/article title becomes the final `<title>`.
312
+ * Default: `(title) => `${title} | ${siteName}``.
313
+ */
314
+ titleTemplate?: (title: string) => string;
315
+ ogImage?: {
316
+ palette: AsteroidOgImagePalette;
317
+ /** OG image API route path. Default: `/api/og` */
318
+ apiPath?: string;
319
+ };
320
+ /** Override dynamic OG image URL generation (e.g. custom CDN or renderer). */
321
+ getOgImageUrl?: (params: AsteroidOgImageParams) => string | undefined;
322
+ /** Site identity for the Organization/WebSite JSON-LD graph. */
323
+ organization?: AsteroidOrganizationConfig;
324
+ /** Extra schema.org @graph nodes (e.g. a ProfessionalService node). */
325
+ extraJsonLdNodes?: object[];
326
+ /** CMS base URL for resolving featured-image URLs. Required server-side for featured images. */
327
+ cmsUrl?: string;
328
+ /** URL to a PWA manifest.json. When set, a `<link rel="manifest">` is emitted. */
329
+ manifestUrl?: string;
330
+ /** Site-wide default robots policy. Per-page overrides are available on builder options. */
331
+ noindex?: boolean;
332
+ }
333
+
334
+ /** Apply the configured title template, defaulting to `${title} | ${siteName}`. */
335
+ declare function applyTitleTemplate(config: AsteroidSeoConfig, title: string): string;
336
+ declare function buildOgImageUrl(config: AsteroidSeoConfig, params: AsteroidOgImageParams): string | undefined;
337
+ type ArticleLike = {
338
+ title: string;
339
+ description?: string;
340
+ meta_description?: string;
341
+ featured_image?: string;
342
+ };
343
+ /**
344
+ * Generic per-page SEO builder. Use it directly for landing/marketing pages, or
345
+ * as the base for the article/listing wrappers below. Content-type agnostic.
346
+ */
347
+ declare function buildPageSeoValues(config: AsteroidSeoConfig, options: AsteroidPageSeoOptions): ISeoValues;
348
+ /** SEO for a single article; works for news, articles, or docs pages. */
349
+ declare function buildArticleSeoValues<TPost extends ArticleLike>(post: TPost, config: AsteroidSeoConfig, slug: string, options?: {
350
+ noindex?: boolean;
351
+ }): ISeoValues;
352
+ /** SEO for an article collection / category listing (any content type). */
353
+ declare function buildArticleListingSeoValues(config: AsteroidSeoConfig, options?: {
354
+ categoryName?: string;
355
+ categorySlug?: string;
356
+ noindex?: boolean;
357
+ }): ISeoValues;
358
+ declare function seoValuesToClientProps(values: ISeoValues): SeoClientProps;
359
+
360
+ /** Build the site-wide Organization + WebSite @graph from config. */
361
+ declare function buildSiteJsonLd(config: AsteroidSeoConfig): object;
362
+ /** schema.org Article subtypes; pick per content kind. */
363
+ type ArticleJsonLdType = "Article" | "BlogPosting" | "NewsArticle" | "TechArticle" | (string & {});
364
+ type ArticleJsonLdProps = {
365
+ title: string;
366
+ description: string;
367
+ url: string;
368
+ /** Site name; used as the author fallback. */
369
+ siteName: string;
370
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
371
+ siteUrl: string;
372
+ /** schema.org @type. Default: `"Article"`. */
373
+ articleType?: ArticleJsonLdType;
374
+ image?: string;
375
+ authorName?: string;
376
+ publishedTime?: string;
377
+ tags?: string[];
378
+ category?: string;
379
+ };
380
+ declare function buildArticleJsonLd(props: ArticleJsonLdProps): object;
381
+ type CollectionJsonLdProps = {
382
+ name: string;
383
+ description: string;
384
+ url: string;
385
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
386
+ siteUrl: string;
387
+ };
388
+ declare function buildCollectionJsonLd(props: CollectionJsonLdProps): object;
389
+ type WebPageJsonLdProps = {
390
+ name: string;
391
+ description: string;
392
+ url: string;
393
+ /** Normalized base URL (no trailing slash); used to reference the org/website @ids. */
394
+ siteUrl: string;
395
+ };
396
+ /** Generic WebPage node for landing/marketing pages with no article concept. */
397
+ declare function buildWebPageJsonLd(props: WebPageJsonLdProps): object;
398
+
399
+ type OgImageVariant = "article" | "listing";
400
+ interface OgImageContentParams {
401
+ title: string;
402
+ subtitle?: string;
403
+ eyebrow?: string;
404
+ siteName?: string;
405
+ palette: AsteroidOgImagePalette;
406
+ variant?: OgImageVariant;
407
+ }
408
+ interface ParsedOgImageParams extends OgImageContentParams {
409
+ variant: OgImageVariant;
410
+ }
411
+ declare function parseOgImageSearchParams(searchParams: URLSearchParams): ParsedOgImageParams;
412
+ /** JSX layout consumed by `next/og` ImageResponse and compatible OG endpoints. */
413
+ declare function OgImageContent({ title, subtitle, eyebrow, siteName, palette, variant, }: OgImageContentParams): react_jsx_runtime.JSX.Element;
414
+
415
+ export { type ArticleJsonLdProps, type ArticleJsonLdType, type AsteroidCMSConfig, type AsteroidOgImagePalette, type AsteroidOgImageParams, type AsteroidOrganizationConfig, type AsteroidPageSeoOptions, type AsteroidSeoConfig, type CmsMutateOptions, type CmsSearchCondition, type CollectionJsonLdProps, type ContentStatus, type ExtractHeadingsOptions, type ExtractedHeading, type FieldSelector$1 as FieldSelector, type HeadingLevel, type ISeoValues, type MutationType, OgImageContent, type OgImageContentParams, type OgImageVariant, type ParseRichTextOptions, type ParsedOgImageParams, type ReferenceExpansion$1 as ReferenceExpansion, type ResolvedAsteroidCMSConfig, type RichTextClassKey, type RichTextClassMap, type SeoClientProps, type UseCmsContentOptions, type WebPageJsonLdProps, applyTitleTemplate, buildArticleJsonLd, buildArticleListingSeoValues, buildArticleSeoValues, buildCmsMutation, buildCmsQuery, buildCollectionJsonLd, buildOgImageUrl, buildPageSeoValues, buildSiteJsonLd, buildWebPageJsonLd, cmsImage, cmsMutate, createApolloClient, extractHeadingsFromElement, extractHeadingsFromHtml, fetchCmsContent, getContentReadTime, parseOgImageSearchParams, parseRichText, removeEmptyParagraphs, seoValuesToClientProps, slugify };