@nshipster/sosumi 1.0.5 → 1.0.6
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/package.json +1 -1
- package/src/lib/reference/render.ts +107 -2
- package/src/lib/types.ts +9 -0
package/package.json
CHANGED
|
@@ -7,6 +7,7 @@ import type {
|
|
|
7
7
|
ContentItem,
|
|
8
8
|
Declaration,
|
|
9
9
|
IndexContentItem,
|
|
10
|
+
Platform,
|
|
10
11
|
PossibleValueItem,
|
|
11
12
|
PropertyItem,
|
|
12
13
|
TopicSection,
|
|
@@ -67,6 +68,8 @@ export async function renderFromJSON(
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
markdown += renderDeprecationNotice(jsonData, jsonData.references, options.externalOrigin)
|
|
72
|
+
|
|
70
73
|
// Add declaration
|
|
71
74
|
if (jsonData.primaryContentSections) {
|
|
72
75
|
const declarationSection = jsonData.primaryContentSections.find(
|
|
@@ -193,6 +196,10 @@ function generateFrontMatterFromJSON(jsonData: AppleDocJSON, sourceUrl: string):
|
|
|
193
196
|
frontMatter.source = sourceUrl
|
|
194
197
|
frontMatter.timestamp = new Date().toISOString()
|
|
195
198
|
|
|
199
|
+
if (isSymbolDeprecated(jsonData)) {
|
|
200
|
+
frontMatter.deprecated = "true"
|
|
201
|
+
}
|
|
202
|
+
|
|
196
203
|
// Convert to YAML format
|
|
197
204
|
const yamlLines = Object.entries(frontMatter).map(([key, value]) => `${key}: ${value}`)
|
|
198
205
|
return `---\n${yamlLines.join("\n")}\n---\n\n`
|
|
@@ -452,7 +459,8 @@ function renderContentArray(
|
|
|
452
459
|
? renderContentArray(item.content, references, depth + 1, externalOrigin)
|
|
453
460
|
: ""
|
|
454
461
|
const cleanContent = asideContent.trim().replace(/\n/g, "\n> ")
|
|
455
|
-
|
|
462
|
+
const deprecatedLabel = style.toLowerCase() === "deprecated" ? "**Deprecated**\n>\n> " : ""
|
|
463
|
+
markdown += `> [!${calloutType}]\n> ${deprecatedLabel}${cleanContent}\n\n`
|
|
456
464
|
} else if (item.type === "table") {
|
|
457
465
|
markdown += renderTable(item, references, depth, externalOrigin)
|
|
458
466
|
} else if (item.type === "tabNavigator" && item.tabs?.length) {
|
|
@@ -625,7 +633,8 @@ function renderTopicSections(
|
|
|
625
633
|
? reference.abstract.map((a: { text: string }) => a.text).join("")
|
|
626
634
|
: ""
|
|
627
635
|
|
|
628
|
-
|
|
636
|
+
const deprecatedLabel = reference?.deprecated ? " *(Deprecated)*" : ""
|
|
637
|
+
markdown += `- [${title}](${url})${deprecatedLabel}`
|
|
629
638
|
if (abstract) {
|
|
630
639
|
markdown += ` ${abstract}`
|
|
631
640
|
}
|
|
@@ -725,6 +734,102 @@ function renderSeeAlso(
|
|
|
725
734
|
return markdown
|
|
726
735
|
}
|
|
727
736
|
|
|
737
|
+
/**
|
|
738
|
+
* Whether the symbol page represents a deprecated API.
|
|
739
|
+
*/
|
|
740
|
+
function isSymbolDeprecated(jsonData: AppleDocJSON): boolean {
|
|
741
|
+
return getDeprecationNoticeBody(jsonData, jsonData.references) !== null
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Collect a deprecation message from platform availability metadata.
|
|
746
|
+
*/
|
|
747
|
+
function getDeprecationMessageFromPlatforms(platforms?: Platform[]): string | null {
|
|
748
|
+
if (!platforms?.length) {
|
|
749
|
+
return null
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
const deprecatedPlatforms = platforms.filter(
|
|
753
|
+
(platform) => platform.deprecated === true || platform.deprecatedAt,
|
|
754
|
+
)
|
|
755
|
+
if (deprecatedPlatforms.length === 0) {
|
|
756
|
+
return null
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
const uniqueMessages = [
|
|
760
|
+
...new Set(
|
|
761
|
+
deprecatedPlatforms
|
|
762
|
+
.map((platform) => platform.message?.trim())
|
|
763
|
+
.filter((message): message is string => Boolean(message)),
|
|
764
|
+
),
|
|
765
|
+
]
|
|
766
|
+
|
|
767
|
+
if (uniqueMessages.length === 1) {
|
|
768
|
+
return uniqueMessages[0]
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
if (uniqueMessages.length > 1) {
|
|
772
|
+
return deprecatedPlatforms
|
|
773
|
+
.filter((platform) => platform.message)
|
|
774
|
+
.map((platform) => `**${platform.name}:** ${platform.message}`)
|
|
775
|
+
.join("\n")
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
return DEFAULT_DEPRECATION_MESSAGE
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
const DEFAULT_DEPRECATION_MESSAGE = "This symbol is deprecated."
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* Resolve deprecation notice text from DocC JSON (without rendering the callout).
|
|
785
|
+
*/
|
|
786
|
+
function getDeprecationNoticeBody(
|
|
787
|
+
jsonData: AppleDocJSON,
|
|
788
|
+
references?: Record<string, ContentItem>,
|
|
789
|
+
externalOrigin?: string,
|
|
790
|
+
): string | null {
|
|
791
|
+
if (jsonData.deprecationSummary?.length) {
|
|
792
|
+
const summary = renderContentArray(
|
|
793
|
+
jsonData.deprecationSummary,
|
|
794
|
+
references,
|
|
795
|
+
0,
|
|
796
|
+
externalOrigin,
|
|
797
|
+
).trim()
|
|
798
|
+
if (summary) {
|
|
799
|
+
return summary
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
const platformMessage = getDeprecationMessageFromPlatforms(jsonData.metadata?.platforms)
|
|
804
|
+
if (platformMessage) {
|
|
805
|
+
return platformMessage
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
const identifier = jsonData.identifier?.url
|
|
809
|
+
if (identifier && references?.[identifier]?.deprecated === true) {
|
|
810
|
+
return DEFAULT_DEPRECATION_MESSAGE
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
return null
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
/**
|
|
817
|
+
* Render a deprecation callout for deprecated symbol pages.
|
|
818
|
+
*/
|
|
819
|
+
function renderDeprecationNotice(
|
|
820
|
+
jsonData: AppleDocJSON,
|
|
821
|
+
references?: Record<string, ContentItem>,
|
|
822
|
+
externalOrigin?: string,
|
|
823
|
+
): string {
|
|
824
|
+
const body = getDeprecationNoticeBody(jsonData, references, externalOrigin)
|
|
825
|
+
if (!body) {
|
|
826
|
+
return ""
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
const quotedBody = body.replace(/\n/g, "\n> ")
|
|
830
|
+
return `> [!WARNING]\n> **Deprecated**\n>\n> ${quotedBody}\n\n`
|
|
831
|
+
}
|
|
832
|
+
|
|
728
833
|
/**
|
|
729
834
|
* Map aside style to GitHub-style callout
|
|
730
835
|
*/
|
package/src/lib/types.ts
CHANGED
|
@@ -75,6 +75,9 @@ export interface ContentItem {
|
|
|
75
75
|
|
|
76
76
|
// Abstract content
|
|
77
77
|
abstract?: TextFragment[]
|
|
78
|
+
|
|
79
|
+
/** Present on reference entries for deprecated symbols. */
|
|
80
|
+
deprecated?: boolean
|
|
78
81
|
}
|
|
79
82
|
|
|
80
83
|
// ============================================================================
|
|
@@ -261,6 +264,10 @@ export interface Platform {
|
|
|
261
264
|
name: string
|
|
262
265
|
introducedAt: string
|
|
263
266
|
beta?: boolean
|
|
267
|
+
deprecated?: boolean
|
|
268
|
+
deprecatedAt?: string
|
|
269
|
+
message?: string
|
|
270
|
+
unavailable?: boolean
|
|
264
271
|
}
|
|
265
272
|
|
|
266
273
|
/**
|
|
@@ -297,6 +304,8 @@ export interface AppleDocJSON {
|
|
|
297
304
|
|
|
298
305
|
// Content
|
|
299
306
|
abstract?: Array<{ text: string; type: string }>
|
|
307
|
+
/** DocC deprecation notice shown at the top of deprecated symbol pages. */
|
|
308
|
+
deprecationSummary?: ContentItem[]
|
|
300
309
|
sections?: ContentItem[]
|
|
301
310
|
|
|
302
311
|
// Primary content sections
|