Source identity
| Field | Recorded value |
|---|---|
| Source type | GitHub source |
| Original record | Janady13/llms-txt-hub / apps/web/lib/extension-updates.ts |
| Date | Not specified in source |
| Repository | Janady13/llms-txt-hub |
| Revision | e0f4bf978d4df168369c7601d9c5f5ea89e84377 |
| Branch | main |
| Path or archive member | apps/web/lib/extension-updates.ts |
| Original SHA-256 | 68edf630776b20111710e237b9f6b1863ffbeca65ac27ded4c1ac8c1100d98d8 |
| Git blob SHA | 54f255aa5c36bc2f632209a904760dd148908315 |
| Reading-copy SHA-256 | 68edf630776b20111710e237b9f6b1863ffbeca65ac27ded4c1ac8c1100d98d8 |
Recovered source transcript
Download complete source text ↓103 lines · 2.7 KB
let allExtensionUpdates: any[] = []
try {
const collections = require('@/.content-collections/generated')
allExtensionUpdates = collections.allExtensionUpdates || []
} catch {
if (process.env.NODE_ENV !== 'test') {
console.warn('Extension update content collection not available, using empty array')
}
}
interface ContentMeta {
path: string
content?: string
}
interface ExtensionUpdate {
slug?: string
version: string
title: string
description: string
date: string
published: boolean
highlights: string[]
content?: string
_meta?: ContentMeta
}
export interface ExtensionUpdateMetadata {
slug: string
version: string
title: string
description: string
date: string
published: boolean
highlights: string[]
content?: string
}
/**
* Normalize extension versions so both `v2.0.0` and `2.0.0` match.
*
* @param version - Version string from query/frontmatter
* @returns Normalized version without leading `v`
*/
function normalizeExtensionVersion(version: string): string {
if (typeof version !== 'string') {
return ''
}
const normalized = version.trim().toLowerCase()
return normalized.startsWith('v') ? normalized.slice(1) : normalized
}
/**
* Return all published extension updates sorted by release date descending.
*
* @returns List of normalized extension updates
*/
export function getExtensionUpdates(): ExtensionUpdateMetadata[] {
return allExtensionUpdates
.filter((update: ExtensionUpdate) => update.published)
.map((update: ExtensionUpdate) => ({
slug: update.slug || update._meta?.path || '',
version: update.version || '',
title: update.title || '',
description: update.description || '',
date: update.date || '',
published: update.published !== false,
highlights: Array.isArray(update.highlights) ? update.highlights.slice(0, 5) : [],
content: update.content || update._meta?.content || ''
}))
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
}
/**
* Return the newest published extension update.
*
* @returns Latest update or null when none exist
*/
export function getLatestExtensionUpdate(): ExtensionUpdateMetadata | null {
const updates = getExtensionUpdates()
return updates.length > 0 ? updates[0] : null
}
/**
* Resolve an extension update by version.
*
* @param version - Version identifier (`2.0.0` or `v2.0.0`)
* @returns Matching update or null
*/
export function getExtensionUpdateByVersion(version: string): ExtensionUpdateMetadata | null {
const normalizedTarget = normalizeExtensionVersion(version)
if (!normalizedTarget) {
return null
}
const updates = getExtensionUpdates()
return (
updates.find(update => normalizeExtensionVersion(update.version) === normalizedTarget) || null
)
}