Skip to content

Commit 9f86026

Browse files
authored
Merge pull request #1995 from brefphp/xray-changelog
Add changelog to X-Ray docs
2 parents 4433cb1 + 823beb3 commit 9f86026

File tree

4 files changed

+152
-2
lines changed

4 files changed

+152
-2
lines changed

website/src/github/releases.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export async function getReleases(repository, limit = 20) {
2+
const token = process.env.GITHUB_TOKEN_CHANGELOGS;
3+
if (!token) {
4+
console.error('GITHUB_TOKEN_CHANGELOGS is not set. You may hit rate limits when fetching releases from GitHub API.');
5+
return;
6+
}
7+
8+
const response = await fetch(`https://api.github.com/repos/${repository}/releases?per_page=${limit}`, {
9+
headers: {
10+
'Authorization': `token ${token}`,
11+
},
12+
});
13+
if (!response.ok) {
14+
console.error(`Failed to fetch releases from ${repository}: ${response.status} ${response.statusText}`);
15+
return [];
16+
}
17+
18+
const releases = await response.json();
19+
20+
return releases.map(release => ({
21+
id: release.id,
22+
name: release.name,
23+
tagName: release.tag_name,
24+
body: release.body,
25+
publishedAt: release.published_at,
26+
htmlUrl: release.html_url,
27+
draft: release.draft,
28+
prerelease: release.prerelease
29+
}));
30+
}

website/src/pages/xray.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export function XRay() {
112112
const faqs = [
113113
{
114114
question: 'Where can I learn more about each feature?',
115-
answer: 'You can find more information about each feature in <a href="/xray/docs" class="link">the documentation</a>.',
115+
answer: 'You can find more information about each feature in <a href="/xray/docs" class="link">the documentation</a>. Check the <a href="/xray/changelog" class="link">changelog</a> for the latest updates.',
116116
},
117117
{
118118
question: 'What is a considered a "project"?',
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
import Breadcrumbs from '../../components/Breadcrumbs';
2+
import { NextSeo } from 'next-seo';
3+
import { getReleases } from '../../github/releases';
4+
5+
<NextSeo
6+
title="X-Ray Integration Changelog"
7+
description="Latest updates and releases for the Bref X-Ray integration package"
8+
/>
9+
10+
export async function getStaticProps() {
11+
const releases = await getReleases('brefphp/xray-integration', 20);
12+
13+
// Format dates consistently on the server
14+
const formattedReleases = releases ? releases.map(release => {
15+
const date = new Date(release.publishedAt);
16+
const months = ['January', 'February', 'March', 'April', 'May', 'June',
17+
'July', 'August', 'September', 'October', 'November', 'December'];
18+
return {
19+
...release,
20+
formattedDate: `${months[date.getUTCMonth()]} ${date.getUTCDate()}, ${date.getUTCFullYear()}`
21+
};
22+
}) : [];
23+
24+
return {
25+
props: {
26+
releases: formattedReleases
27+
},
28+
// The page will be considered as stale and regenerated every hour
29+
revalidate: 3600
30+
};
31+
}
32+
33+
export default function ChangelogPage({ releases }) {
34+
function renderMarkdown(markdown) {
35+
// Remove Full Changelog links since the repo is private (handle both bold and non-bold versions)
36+
let cleaned = markdown
37+
.replace(/\*\*Full Changelog\*\*: https:\/\/github\.com\/brefphp\/xray-integration\/compare\/[^\s\n]+/g, '')
38+
.replace(/Full Changelog: https:\/\/github\.com\/brefphp\/xray-integration\/compare\/[^\s\n]+/g, '');
39+
40+
// Simple markdown to HTML conversion
41+
let html = cleaned
42+
// Headers
43+
.replace(/^#### (.+)$/gm, '<h4>$1</h4>')
44+
.replace(/^### (.+)$/gm, '<h3>$1</h3>')
45+
.replace(/^## (.+)$/gm, '<h2>$1</h2>')
46+
.replace(/^# (.+)$/gm, '<h1>$1</h1>')
47+
// Bold and italic
48+
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
49+
.replace(/\*([^*]+)\*/g, '<em>$1</em>')
50+
// Code blocks and inline code
51+
.replace(/```[\s\S]*?```/g, (match) => {
52+
const code = match.slice(3, -3).trim();
53+
return `<pre><code>${code}</code></pre>`;
54+
})
55+
.replace(/`([^`]+)`/g, '<code>$1</code>')
56+
// Links
57+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>')
58+
// Line breaks and paragraphs
59+
.replace(/\n\n/g, '</p><p>')
60+
.replace(/\n/g, '<br/>')
61+
// Lists
62+
.replace(/^\* (.+)$/gm, '<li>$1</li>')
63+
.replace(/^- (.+)$/gm, '<li>$1</li>')
64+
.replace(/(<li>.*<\/li>)/s, '<ul>$1</ul>');
65+
66+
// Wrap in paragraph tags if not already wrapped
67+
if (!html.startsWith('<')) {
68+
html = '<p>' + html + '</p>';
69+
}
70+
71+
return html;
72+
}
73+
74+
if (!releases || releases.length === 0) {
75+
return (
76+
<div>
77+
<Breadcrumbs pages={[
78+
{ name: 'X-Ray', href: '/xray' },
79+
{ name: 'Documentation', href: '/xray/docs' },
80+
{ name: 'Changelog', href: '/xray/changelog' },
81+
]} />
82+
<h1 className="text-4xl font-bold tracking-tight text-gray-900 mt-8">X-Ray Integration Changelog</h1>
83+
<div className="mt-6 text-lg leading-8 text-gray-600">
84+
Latest updates and releases for the Bref X-Ray integration package.
85+
</div>
86+
<div className="mt-12 text-center">
87+
<p className="text-gray-500">No releases found or unable to fetch releases.</p>
88+
</div>
89+
</div>
90+
);
91+
}
92+
93+
return (
94+
<div>
95+
<Breadcrumbs pages={[
96+
{ name: 'X-Ray', href: '/xray' },
97+
{ name: 'Documentation', href: '/xray/docs' },
98+
{ name: 'Changelog', href: '/xray/changelog' },
99+
]} />
100+
<h1 className="text-4xl font-bold tracking-tight text-gray-900 mt-8">X-Ray Integration Changelog</h1>
101+
<div className="mt-6 text-lg leading-8 text-gray-600">
102+
Latest updates and releases for the Bref X-Ray integration package.
103+
</div>
104+
<div className="mt-8">
105+
{releases.map(release => (
106+
<div key={release.id} className="mb-12">
107+
<h2 className="text-2xl font-bold mb-2">
108+
{release.name || release.tagName}
109+
</h2>
110+
<p className="text-sm text-gray-500 mb-4">
111+
{release.formattedDate}
112+
</p>
113+
<div className="prose prose-sm max-w-none"
114+
dangerouslySetInnerHTML={{ __html: renderMarkdown(release.body || 'No release notes provided.') }} />
115+
</div>
116+
))}
117+
</div>
118+
</div>
119+
);
120+
}

website/src/pages/xray/docs.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Callout } from 'nextra/components';
1010

1111
This package provides an advanced integration between Bref applications and [AWS X-Ray monitoring](https://aws.amazon.com/xray/).
1212

13-
Check out the documentation below for screenshots and more details.
13+
Check out the documentation below for screenshots and more details. View the [changelog](/xray/changelog) for the latest updates and releases.
1414

1515
## Installation
1616

0 commit comments

Comments
 (0)