|
| 1 | +interface ChangelogEntry { |
| 2 | + id: string; |
| 3 | + title: string; |
| 4 | + description: string; |
| 5 | + url: string; |
| 6 | + publishedAt: string; |
| 7 | + author: string; |
| 8 | + filesChanged?: { |
| 9 | + added: string[]; |
| 10 | + modified: string[]; |
| 11 | + removed: string[]; |
| 12 | + }; |
| 13 | +} |
| 14 | + |
| 15 | +async function getChangelogEntries(): Promise<ChangelogEntry[]> { |
| 16 | + try { |
| 17 | + const res = await fetch('https://sentry-content-dashboard.sentry.dev/api/docs', { |
| 18 | + next: { revalidate: 3600 }, // Cache for 1 hour |
| 19 | + }); |
| 20 | + |
| 21 | + if (!res.ok) { |
| 22 | + throw new Error('Failed to fetch changelog'); |
| 23 | + } |
| 24 | + |
| 25 | + return res.json(); |
| 26 | + } catch (error) { |
| 27 | + console.error('Error fetching changelog:', error); |
| 28 | + return []; |
| 29 | + } |
| 30 | +} |
| 31 | + |
| 32 | +export async function DocsChangelog() { |
| 33 | + const entries = await getChangelogEntries(); |
| 34 | + |
| 35 | + if (entries.length === 0) { |
| 36 | + return ( |
| 37 | + <div className="rounded-lg border border-yellow-200 bg-yellow-50 p-4 text-yellow-800"> |
| 38 | + <p className="font-semibold">No changelog entries available</p> |
| 39 | + <p className="text-sm">Check back later for updates.</p> |
| 40 | + </div> |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + return ( |
| 45 | + <div className="space-y-8"> |
| 46 | + {entries.map(entry => { |
| 47 | + const date = new Date(entry.publishedAt); |
| 48 | + const totalFiles = |
| 49 | + (entry.filesChanged?.added.length || 0) + |
| 50 | + (entry.filesChanged?.modified.length || 0) + |
| 51 | + (entry.filesChanged?.removed.length || 0); |
| 52 | + |
| 53 | + return ( |
| 54 | + <article |
| 55 | + key={entry.id} |
| 56 | + className="border-b border-gray-200 pb-8 last:border-0" |
| 57 | + > |
| 58 | + <header className="mb-3"> |
| 59 | + <h3 className="mb-2 text-xl font-semibold"> |
| 60 | + <a |
| 61 | + href={entry.url} |
| 62 | + target="_blank" |
| 63 | + rel="noopener noreferrer" |
| 64 | + className="text-primary hover:underline" |
| 65 | + > |
| 66 | + {entry.title.replace('Docs Update: ', '')} |
| 67 | + </a> |
| 68 | + </h3> |
| 69 | + <div className="flex flex-wrap items-center gap-3 text-sm text-gray-600"> |
| 70 | + <time dateTime={entry.publishedAt}> |
| 71 | + {date.toLocaleDateString('en-US', { |
| 72 | + year: 'numeric', |
| 73 | + month: 'long', |
| 74 | + day: 'numeric', |
| 75 | + })} |
| 76 | + </time> |
| 77 | + <span>•</span> |
| 78 | + <span>by {entry.author}</span> |
| 79 | + {totalFiles > 0 && ( |
| 80 | + <> |
| 81 | + <span>•</span> |
| 82 | + <span>{totalFiles} file{totalFiles !== 1 ? 's' : ''} changed</span> |
| 83 | + </> |
| 84 | + )} |
| 85 | + </div> |
| 86 | + </header> |
| 87 | + |
| 88 | + <p className="mb-4 text-gray-700">{entry.description}</p> |
| 89 | + |
| 90 | + {entry.filesChanged && totalFiles > 0 && ( |
| 91 | + <details className="text-sm"> |
| 92 | + <summary className="cursor-pointer text-gray-600 hover:text-gray-800"> |
| 93 | + View changed files |
| 94 | + </summary> |
| 95 | + <div className="mt-2 space-y-2 rounded-md bg-gray-50 p-3"> |
| 96 | + {entry.filesChanged.added.length > 0 && ( |
| 97 | + <div> |
| 98 | + <span className="font-semibold text-green-700">Added:</span> |
| 99 | + <ul className="ml-4 mt-1 list-inside list-disc"> |
| 100 | + {entry.filesChanged.added.map(file => ( |
| 101 | + <li key={file} className="text-gray-700"> |
| 102 | + {file} |
| 103 | + </li> |
| 104 | + ))} |
| 105 | + </ul> |
| 106 | + </div> |
| 107 | + )} |
| 108 | + {entry.filesChanged.modified.length > 0 && ( |
| 109 | + <div> |
| 110 | + <span className="font-semibold text-blue-700">Modified:</span> |
| 111 | + <ul className="ml-4 mt-1 list-inside list-disc"> |
| 112 | + {entry.filesChanged.modified.map(file => ( |
| 113 | + <li key={file} className="text-gray-700"> |
| 114 | + {file} |
| 115 | + </li> |
| 116 | + ))} |
| 117 | + </ul> |
| 118 | + </div> |
| 119 | + )} |
| 120 | + {entry.filesChanged.removed.length > 0 && ( |
| 121 | + <div> |
| 122 | + <span className="font-semibold text-red-700">Removed:</span> |
| 123 | + <ul className="ml-4 mt-1 list-inside list-disc"> |
| 124 | + {entry.filesChanged.removed.map(file => ( |
| 125 | + <li key={file} className="text-gray-700"> |
| 126 | + {file} |
| 127 | + </li> |
| 128 | + ))} |
| 129 | + </ul> |
| 130 | + </div> |
| 131 | + )} |
| 132 | + </div> |
| 133 | + </details> |
| 134 | + )} |
| 135 | + </article> |
| 136 | + ); |
| 137 | + })} |
| 138 | + </div> |
| 139 | + ); |
| 140 | +} |
| 141 | + |
0 commit comments