Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/components/ChangelogFilters/useChangelogFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ export const useChangelogFilters = ({ items }: UseChangelogFiltersProps) => {
const changelogList = document.querySelector(".changelog-list") as HTMLElement

if (filters.searchTerm) {
// Search takes priority - filter by search term
// Combine search with any active filters: a row must match both.
const searchLower = filters.searchTerm.toLowerCase()
const hasFilters =
filters.selectedProducts.length > 0 || filters.selectedNetworks.length > 0 || filters.selectedTypes.length > 0
let visibleCount = 0

changelogItems.forEach((item) => {
Expand All @@ -81,7 +83,12 @@ export const useChangelogFilters = ({ items }: UseChangelogFiltersProps) => {
changelogItem?.name.toLowerCase().includes(searchLower) ||
changelogItem?.["text-description"]?.toLowerCase().includes(searchLower)

if (matchesSearch) {
const passesFilters =
!hasFilters ||
(changelogItem &&
matchesFilters(changelogItem, filters.selectedProducts, filters.selectedNetworks, filters.selectedTypes))

if (matchesSearch && passesFilters) {
;(item as HTMLElement).style.display = ""
visibleCount++
} else {
Expand Down
35 changes: 3 additions & 32 deletions src/components/ChangelogSnippet/ChangelogSnippet.astro
Original file line number Diff line number Diff line change
@@ -1,45 +1,16 @@
---
import { SvgArrowRight2, Typography } from "@chainlink/blocks"
import { SearchClient, searchClient } from "@algolia/client-search"
import ChangelogCard from "./ChangelogCard.astro"
import { AlgoliaQuery, type ChangelogItem } from "./types"
import type { AlgoliaQuery } from "./types"
import styles from "./ChangelogSnippet.module.css"
import { getSecret } from "astro:env/server"
import { getLatestChangelogForTopic } from "~/utils/changelog"

interface Props {
query: AlgoliaQuery
}

const { query } = Astro.props

const appId = getSecret("ALGOLIA_APP_ID")
const apiKey = getSecret("PUBLIC_ALGOLIA_SEARCH_PUBLIC_API_KEY")

let client: SearchClient
let latestLog: ChangelogItem | undefined = undefined

// Initialize client if appId and apiKey are available to avoid needing to update
// the github actions with the new keys (satisfies linkcheck-internal)
if (appId && apiKey) {
client = searchClient(appId, apiKey)

const req = await client.search({
requests: [
{
indexName: "Changelog",
restrictSearchableAttributes: ["topic"],
query,
hitsPerPage: 1,
},
],
})

const firstResult = req.results[0]
const results = "hits" in firstResult ? (firstResult.hits as ChangelogItem[]) : []

// logs are returned sorted by created_at DESC
latestLog = results[0]
}
const latestLog = getLatestChangelogForTopic(query)
---

{
Expand Down
58 changes: 8 additions & 50 deletions src/pages/changelog.astro
Original file line number Diff line number Diff line change
Expand Up @@ -3,59 +3,17 @@ import BaseLayout from "~/layouts/BaseLayout.astro"
import * as CONFIG from "../config"
import { Typography } from "@chainlink/blocks"
import { ChangelogFilters } from "~/components/ChangelogFilters/ChangelogFilters.tsx"
import { getSecret } from "astro:env/server"
import { searchClient, SearchClient } from "@algolia/client-search"
import { ChangelogItem } from "~/components/ChangelogSnippet/types"
import ChangelogCard from "~/components/ChangelogSnippet/ChangelogCard.astro"
import { getUniqueNetworks, getUniqueTopics, getUniqueTypes } from "~/utils/changelogFilters"
import { getChangelogItems } from "~/utils/changelog"
const formattedContentTitle = `${CONFIG.PAGE.titleFallback} | ${CONFIG.SITE.title}`

const appId = getSecret("ALGOLIA_APP_ID")
const apiKey = getSecret("PUBLIC_ALGOLIA_SEARCH_PUBLIC_API_KEY")

let client: SearchClient
let logs: ChangelogItem[] | undefined = undefined

if (appId && apiKey) {
client = searchClient(appId, apiKey)

const firstReq = await client.search({
requests: [
{
indexName: "Changelog",
page: 0,
hitsPerPage: 1000,
},
],
})

const firstResult = firstReq.results[0]
let allHits = "hits" in firstResult ? (firstResult.hits as ChangelogItem[]) : []
const nbPages = "nbPages" in firstResult ? firstResult.nbPages : 1

if (nbPages && nbPages > 1) {
const remainingRequests = Array.from({ length: nbPages - 1 }, (_, i) => ({
indexName: "Changelog",
page: i + 1,
hitsPerPage: 1000,
}))

const remainingResults = await client.search({ requests: remainingRequests })

remainingResults.results.forEach((result) => {
if ("hits" in result) {
allHits = [...allHits, ...(result.hits as ChangelogItem[])]
}
})
}

logs = allHits
}
const logs = getChangelogItems()

// Extract unique filter values
const products = logs ? getUniqueTopics(logs) : []
const networks = logs ? getUniqueNetworks(logs) : []
const types = logs ? getUniqueTypes(logs) : []
const products = getUniqueTopics(logs)
const networks = getUniqueNetworks(logs)
const types = getUniqueTypes(logs)
---

<BaseLayout title={formattedContentTitle}>
Expand All @@ -67,7 +25,7 @@ const types = logs ? getUniqueTypes(logs) : []

<section class="changelog-list">
{
logs?.map((log, index) => (
logs.map((log, index) => (
<div class="changelog-item" data-index={index} style={index >= 25 ? "display: none;" : ""}>
<ChangelogCard showNetworksAndTopic showBorder={false} item={log} />
</div>
Expand All @@ -84,7 +42,7 @@ const types = logs ? getUniqueTypes(logs) : []
</section>

{
logs && logs.length > 25 && (
logs.length > 25 && (
<div class="load-more-section">
<button id="load-more-btn" class="load-more-button">
Load more
Expand All @@ -96,7 +54,7 @@ const types = logs ? getUniqueTypes(logs) : []
)
}

<ChangelogFilters client:load products={products} networks={networks} types={types} items={logs || []} />
<ChangelogFilters client:load products={products} networks={networks} types={types} items={logs} />
</main>
</BaseLayout>

Expand Down
65 changes: 7 additions & 58 deletions src/pages/changelog/[...id].astro
Original file line number Diff line number Diff line change
@@ -1,67 +1,16 @@
---
import BaseLayout from "~/layouts/BaseLayout.astro"
import * as CONFIG from "../../config"
import { getSecret } from "astro:env/server"
import { searchClient } from "@algolia/client-search"
import { ChangelogItem } from "~/components/ChangelogSnippet/types"
import ChangelogCard from "~/components/ChangelogSnippet/ChangelogCard.astro"
import { SvgArrowLeft2, Typography } from "@chainlink/blocks"
import { getChangelogItems } from "~/utils/changelog"

export async function getStaticPaths() {
const appId = getSecret("ALGOLIA_APP_ID")
const apiKey = getSecret("PUBLIC_ALGOLIA_SEARCH_PUBLIC_API_KEY")

// Return empty array if credentials are not available (CI/CD environments)
if (!appId || !apiKey) {
console.warn("Algolia credentials not available, skipping changelog static generation")
return []
}

const client = searchClient(appId, apiKey)

try {
const records: ChangelogItem[] = []
let currentPage = 0
let nbPages = 1
const hitsPerPage = 1000 // Maximum allowed by Algolia

// Fetch all changelog items from Algolia with pagination
while (currentPage < nbPages) {
const req = await client.search({
requests: [
{
indexName: "Changelog",
hitsPerPage,
page: currentPage,
},
],
})

const firstResult = req.results[0]

if ("hits" in firstResult) {
// Add hits from current page to records
const hits = firstResult.hits as ChangelogItem[]
records.push(...hits)

// Update nbPages from the response
if ("nbPages" in firstResult) {
nbPages = firstResult.nbPages as number
}
}

currentPage++
}

// Generate static paths for each changelog item
return records.map((log) => ({
params: { id: log.slug },
props: { log },
}))
} catch (error) {
console.error("Error fetching changelog items:", error)
return []
}
export function getStaticPaths() {
return getChangelogItems().map((log) => ({
params: { id: log.slug },
props: { log },
}))
}

interface Props {
Expand All @@ -81,7 +30,7 @@ const pageTitle = `Changelog and Releases | ${CONFIG.SITE.title}`
<span>Back to Changelog</span>
</a>

<Typography variant="h1" className="header-title">Integration</Typography>
<Typography variant="h1" className="header-title">{log.type}</Typography>
</div>

<div class="changelog-content">
Expand Down
Loading
Loading