@adatechnology/content-contracts 0.2.0 → 0.3.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.ts CHANGED
@@ -692,6 +692,13 @@ type MarkdownInline = {
692
692
  } | {
693
693
  readonly type: 'break';
694
694
  };
695
+ type MarkdownFigureImage = {
696
+ readonly src: string;
697
+ readonly alt: string;
698
+ };
699
+ type MarkdownGalleryImage = MarkdownFigureImage & {
700
+ readonly caption?: string;
701
+ };
695
702
  type MarkdownBlock = {
696
703
  readonly type: 'heading';
697
704
  readonly level: 1 | 2 | 3 | 4 | 5 | 6;
@@ -717,6 +724,17 @@ type MarkdownBlock = {
717
724
  readonly value: string;
718
725
  } | {
719
726
  readonly type: 'thematicBreak';
727
+ }
728
+ /** Parágrafo só com uma imagem que tem título: o título vira a legenda. */
729
+ | {
730
+ readonly type: 'figure';
731
+ readonly image: MarkdownFigureImage;
732
+ readonly caption: string;
733
+ }
734
+ /** Parágrafo só com 2+ imagens. */
735
+ | {
736
+ readonly type: 'gallery';
737
+ readonly images: readonly MarkdownGalleryImage[];
720
738
  };
721
739
  type MarkdownDocument = {
722
740
  readonly type: 'root';
@@ -855,4 +873,4 @@ declare function buildAtomFeed(params: {
855
873
  }): string;
856
874
  declare function buildSitemapXml(entries: readonly SitemapEntry[]): string;
857
875
 
858
- export { CONTENT_ERROR_CODES, type ClockPort, ConfigMissingError, ContentError, type ContentErrorCode, type ContentFeedConfig, type ContentHooks, type ContentImageStoragePort, type ContentModuleConfig, type CreateFromTemplateInput, type CreatePostInput, type CreateRecurrenceInput, DEFAULT_ADMIN_SCOPES, DEFAULT_LINK_REL, DEFAULT_POST_PATH_TEMPLATE, DEFAULT_PUBLIC_CACHE_CONTROL, DEFAULT_SHORT_SLUG_LENGTH, DEFAULT_WORDS_PER_MINUTE, DuplicateSlugError, type FeedChannel, type FeedItem, ImageStorageDisabledError, InvalidCoverImageError, type InvalidImageReason, InvalidSlugError, type ListPostsQuery, type ListPublishedPostsQuery, type LogMeta, type LoggerPort, type MarkdownBlock, type MarkdownDocument, type MarkdownInline, type MarkdownRenderOptions, NotATemplateError, POST_EVENT, POST_LIMITS, POST_SORT_FIELDS, POST_STATUS, POST_STATUSES, PT_BR_STOP_WORDS, type Paginated, type Pagination, type ParsedPostRef, type Post, type PostChangedEvent, type PostCounts, type PostEventType, PostNotFoundError, PostNotPublishedError, type PostSortField, type PostStatus, type PostSummary, type PublicPost, type PublicPostSummary, type PublishPostInput, RECURRENCE_FREQUENCIES, RECURRENCE_FREQUENCY, type RecurrenceFrequency, RecurrenceNotFoundError, type RecurrenceRule, RepublishDateInFutureError, type RepublishPostInput, SHORT_ID_LENGTH, SLUG_MAX_LENGTH, type SaveAsTemplateInput, type ShortSlugOptions, type SitemapEntry, TAGS_MAX_COUNT, TAG_MAX_LENGTH, type TagCount, type TagLabels, TemplateNotPublishableError, type UpdatePostInput, type UpdateRecurrenceInput, buildAtomFeed, buildExcerpt, buildPostPath, buildPostRef, buildPostUrl, buildRssFeed, buildShortSlug, buildSitemapXml, buildTagLabels, countWords, createFromTemplateSchema, createHeadingIdGenerator, createPostSchema, createRecurrenceSchema, documentToPlainText, escapeHtml, escapeXml, estimateReadingTimeMinutes, formatTagLabel, httpUrlSchema, inlineToPlainText, isAbsoluteHttpUrl, isCanonicalPostRef, isPostStatus, isShortId, isValidSlug, listPostsQuerySchema, listPublishedPostsQuerySchema, markdownToPlainText, normalizeTag, normalizeTags, parseInline, parseMarkdown, parsePostPath, parsePostRef, postFieldsSchema, publishPostSchema, renderMarkdownDocument, renderMarkdownToHtml, republishPostSchema, resolveHeadingLevel, sanitizeImageUrl, sanitizeLinkUrl, saveAsTemplateSchema, slugSchema, slugify, updatePostSchema, updateRecurrenceSchema, withSlugSuffix };
876
+ export { CONTENT_ERROR_CODES, type ClockPort, ConfigMissingError, ContentError, type ContentErrorCode, type ContentFeedConfig, type ContentHooks, type ContentImageStoragePort, type ContentModuleConfig, type CreateFromTemplateInput, type CreatePostInput, type CreateRecurrenceInput, DEFAULT_ADMIN_SCOPES, DEFAULT_LINK_REL, DEFAULT_POST_PATH_TEMPLATE, DEFAULT_PUBLIC_CACHE_CONTROL, DEFAULT_SHORT_SLUG_LENGTH, DEFAULT_WORDS_PER_MINUTE, DuplicateSlugError, type FeedChannel, type FeedItem, ImageStorageDisabledError, InvalidCoverImageError, type InvalidImageReason, InvalidSlugError, type ListPostsQuery, type ListPublishedPostsQuery, type LogMeta, type LoggerPort, type MarkdownBlock, type MarkdownDocument, type MarkdownFigureImage, type MarkdownGalleryImage, type MarkdownInline, type MarkdownRenderOptions, NotATemplateError, POST_EVENT, POST_LIMITS, POST_SORT_FIELDS, POST_STATUS, POST_STATUSES, PT_BR_STOP_WORDS, type Paginated, type Pagination, type ParsedPostRef, type Post, type PostChangedEvent, type PostCounts, type PostEventType, PostNotFoundError, PostNotPublishedError, type PostSortField, type PostStatus, type PostSummary, type PublicPost, type PublicPostSummary, type PublishPostInput, RECURRENCE_FREQUENCIES, RECURRENCE_FREQUENCY, type RecurrenceFrequency, RecurrenceNotFoundError, type RecurrenceRule, RepublishDateInFutureError, type RepublishPostInput, SHORT_ID_LENGTH, SLUG_MAX_LENGTH, type SaveAsTemplateInput, type ShortSlugOptions, type SitemapEntry, TAGS_MAX_COUNT, TAG_MAX_LENGTH, type TagCount, type TagLabels, TemplateNotPublishableError, type UpdatePostInput, type UpdateRecurrenceInput, buildAtomFeed, buildExcerpt, buildPostPath, buildPostRef, buildPostUrl, buildRssFeed, buildShortSlug, buildSitemapXml, buildTagLabels, countWords, createFromTemplateSchema, createHeadingIdGenerator, createPostSchema, createRecurrenceSchema, documentToPlainText, escapeHtml, escapeXml, estimateReadingTimeMinutes, formatTagLabel, httpUrlSchema, inlineToPlainText, isAbsoluteHttpUrl, isCanonicalPostRef, isPostStatus, isShortId, isValidSlug, listPostsQuerySchema, listPublishedPostsQuerySchema, markdownToPlainText, normalizeTag, normalizeTags, parseInline, parseMarkdown, parsePostPath, parsePostRef, postFieldsSchema, publishPostSchema, renderMarkdownDocument, renderMarkdownToHtml, republishPostSchema, resolveHeadingLevel, sanitizeImageUrl, sanitizeLinkUrl, saveAsTemplateSchema, slugSchema, slugify, updatePostSchema, updateRecurrenceSchema, withSlugSuffix };
package/dist/index.js CHANGED
@@ -797,6 +797,47 @@ function parseDestination(text, start) {
797
797
  }
798
798
  __name(parseDestination, "parseDestination");
799
799
 
800
+ // src/markdown/paragraphToBlock.ts
801
+ function isFiller(node) {
802
+ return node.type === "break" || node.type === "text" && !node.value.trim();
803
+ }
804
+ __name(isFiller, "isFiller");
805
+ function paragraphToBlock(children) {
806
+ const meaningful = children.filter((node) => !isFiller(node));
807
+ const images = meaningful.filter((node) => node.type === "image");
808
+ if (images.length === 0 || images.length !== meaningful.length) return {
809
+ type: "paragraph",
810
+ children
811
+ };
812
+ const [only] = images;
813
+ if (images.length === 1 && only?.title) {
814
+ return {
815
+ type: "figure",
816
+ image: {
817
+ src: only.src,
818
+ alt: only.alt
819
+ },
820
+ caption: only.title
821
+ };
822
+ }
823
+ if (images.length < 2) return {
824
+ type: "paragraph",
825
+ children
826
+ };
827
+ const gallery = images.map((image) => ({
828
+ src: image.src,
829
+ alt: image.alt,
830
+ ...image.title ? {
831
+ caption: image.title
832
+ } : {}
833
+ }));
834
+ return {
835
+ type: "gallery",
836
+ images: gallery
837
+ };
838
+ }
839
+ __name(paragraphToBlock, "paragraphToBlock");
840
+
800
841
  // src/markdown/parseMarkdown.ts
801
842
  var MAX_BLOCK_DEPTH = 6;
802
843
  var FENCE_PATTERN = /^ {0,3}(`{3,}|~{3,})\s*([^\s`]*)[^`]*$/;
@@ -918,10 +959,7 @@ function parseParagraph(lines, index, depth) {
918
959
  cursor += 1;
919
960
  }
920
961
  return {
921
- block: {
922
- type: "paragraph",
923
- children: parseInline(content.join("\n").trimEnd())
924
- },
962
+ block: paragraphToBlock(parseInline(content.join("\n").trimEnd())),
925
963
  next: cursor
926
964
  };
927
965
  }
@@ -1033,7 +1071,10 @@ function blockToPlainText(block) {
1033
1071
  return block.children.map(blockToPlainText).join("\n\n");
1034
1072
  case "list":
1035
1073
  return block.items.map((item) => item.map(blockToPlainText).join("\n")).join("\n");
1074
+ case "figure":
1075
+ return block.caption;
1036
1076
  case "thematicBreak":
1077
+ case "gallery":
1037
1078
  return "";
1038
1079
  }
1039
1080
  }
@@ -1129,6 +1170,12 @@ function renderInlineNode(node, context) {
1129
1170
  }
1130
1171
  }
1131
1172
  __name(renderInlineNode, "renderInlineNode");
1173
+ function renderFigure(image, caption) {
1174
+ const img = `<img src="${escapeHtml(image.src)}" alt="${escapeHtml(image.alt)}" loading="lazy" decoding="async">`;
1175
+ const figcaption = caption ? `<figcaption>${escapeHtml(caption)}</figcaption>` : "";
1176
+ return `<figure class="adc-figure">${img}${figcaption}</figure>`;
1177
+ }
1178
+ __name(renderFigure, "renderFigure");
1132
1179
  function renderBlock(block, context, tight = false) {
1133
1180
  switch (block.type) {
1134
1181
  case "heading": {
@@ -1146,6 +1193,10 @@ function renderBlock(block, context, tight = false) {
1146
1193
  }
1147
1194
  case "thematicBreak":
1148
1195
  return "<hr>";
1196
+ case "figure":
1197
+ return renderFigure(block.image, block.caption);
1198
+ case "gallery":
1199
+ return `<div class="adc-gallery" data-count="${block.images.length}">${block.images.map((image) => renderFigure(image, image.caption)).join("")}</div>`;
1149
1200
  case "list": {
1150
1201
  const tag = block.ordered ? "ol" : "ul";
1151
1202
  const start = block.ordered && block.start !== void 0 && block.start !== 1 ? ` start="${block.start}"` : "";