Skip to content

Commit

Permalink
Merge branch 'main' into add-waf-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
amanfrinati authored Feb 28, 2025
2 parents 8d85f0f + ba335c4 commit 95fc48f
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 65 deletions.
5 changes: 5 additions & 0 deletions .changeset/clean-lizards-rescue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": minor
---

Add autoplay to the swiper in Home page
5 changes: 5 additions & 0 deletions .changeset/hungry-kids-provide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"gitbook-docs": patch
---

Update doc parsing to show images in tables
5 changes: 5 additions & 0 deletions .changeset/perfect-kiwis-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"infrastructure": patch
---

Fixed codebuild cicd lambda permissions
5 changes: 5 additions & 0 deletions .changeset/tall-cats-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nextjs-website": patch
---

Implement caching for API responses
2 changes: 1 addition & 1 deletion apps/infrastructure/src/modules/cicd/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ resource "aws_iam_policy" "deploy_website" {
Action = [
"lambda:*",
]
Resource = ["arn:aws:lambda:${var.aws_region}:${data.aws_caller_identity.current.account_id}:function/*chatbot*"]
Resource = ["arn:aws:lambda:${var.aws_region}:${data.aws_caller_identity.current.account_id}:function:*chatbot*"]
}
]
})
Expand Down
2 changes: 1 addition & 1 deletion apps/nextjs-website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"react-syntax-highlighter": "^15.5.0",
"schema-dts": "^1.1.2",
"swagger-ui": "^5.9.1",
"swiper": "^10.0.3",
"swiper": "^11.2.4",
"swr": "^2.2.4"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
productToBreadcrumb,
} from '@/helpers/structuredData.helpers';
import { getGitBookSubPaths, getReleaseNote } from '@/lib/api';
import {
getCachedUrlReplaceMapProps,
getReleaseNotesProps,
} from '@/lib/cmsApi';
import { getUrlReplaceMapProps, getReleaseNotesProps } from '@/lib/cmsApi';
import {
BreadcrumbItem,
gitBookPageToBreadcrumbs,
Expand Down Expand Up @@ -87,7 +84,7 @@ const ReleaseNotePage = async ({
const { bannerLinks, page, path, product, seo, source, title, bodyConfig } =
await getReleaseNote(params.productSlug, params.releaseNoteSubPathSlugs);

const urlReplaceMap = await getCachedUrlReplaceMapProps();
const urlReplaceMap = await getUrlReplaceMapProps();

const props = {
...page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from '@/helpers/metadata.helpers';
import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate';
import { productPageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers';
import { getGuidesProps, getCachedUrlReplaceMapProps } from '@/lib/cmsApi';
import { getGuidesProps, getUrlReplaceMapProps } from '@/lib/cmsApi';
import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers';
import {
breadcrumbItemByProduct,
Expand Down Expand Up @@ -77,7 +77,7 @@ const Page = async ({ params }: { params: Params }) => {
params?.productGuidePage ?? ['']
);

const urlReplaceMap = await getCachedUrlReplaceMapProps();
const urlReplaceMap = await getUrlReplaceMapProps();
const {
product,
page,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getSolutionDetail, getSolutionSubPaths } from '@/lib/api';
import GitBookTemplate from '@/components/templates/GitBookTemplate/GitBookTemplate';
import { pageToBreadcrumbs } from '@/helpers/breadcrumbs.helpers';
import { ParseContentConfig } from 'gitbook-docs/parseContent';
import { getSolutionsProps, getCachedUrlReplaceMapProps } from '@/lib/cmsApi';
import { getSolutionsProps, getUrlReplaceMapProps } from '@/lib/cmsApi';
import { SolutionTemplateProps } from '@/components/templates/SolutionTemplate/SolutionTemplate';
import { generateStructuredDataScripts } from '@/helpers/generateStructuredDataScripts.helpers';
import { getItemFromPaths } from '@/helpers/structuredData.helpers';
Expand Down Expand Up @@ -56,7 +56,7 @@ const Page = async ({ params }: { params: Params }) => {
params?.solutionSubPathSlugs
);

const urlReplaceMap = await getCachedUrlReplaceMapProps();
const urlReplaceMap = await getUrlReplaceMapProps();
if (!solutionProps) {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use client';
import React, { useCallback, useState } from 'react';
import { Swiper, SwiperSlide } from 'swiper/react';
import { Navigation, Pagination } from 'swiper/modules';
import { Autoplay, Navigation, Pagination } from 'swiper/modules';
import NavigationArrow from '@/components/atoms/NavigationArrow/NavigationArrow';
import CtaSlide, { CtaSlideProps } from '@/components/atoms/CtaSlide/CtaSlide';
import { Swiper as SwiperCore } from 'swiper';
Expand All @@ -10,6 +10,8 @@ export type HeroSwiperProps = {
cards: CtaSlideProps[];
};

const SWIPER_AUTOPLAY_DELAY_IN_MS = 5 * 1000;

const HeroSwiper = ({ cards }: HeroSwiperProps) => {
const [swiperCore, setSwiperCore] = useState<SwiperCore>();
const [swiperIndex, setSwiperIndex] = useState(0);
Expand All @@ -32,8 +34,12 @@ const HeroSwiper = ({ cards }: HeroSwiperProps) => {
setSwiperIndex(swiperCore.activeIndex);
}}
pagination={{ clickable: true }}
autoplay={{
delay: SWIPER_AUTOPLAY_DELAY_IN_MS,
disableOnInteraction: false,
}}
loop={true}
modules={[Navigation, Pagination]}
modules={[Autoplay, Navigation, Pagination]}
>
{cards.length > 1 && (
<>
Expand Down
40 changes: 40 additions & 0 deletions apps/nextjs-website/src/lib/cache.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// In-memory cache store
interface CacheEntry<T> {
readonly data: T;
readonly expiry: number;
}

const cacheStore = new Map<string, CacheEntry<unknown>>();

export const getCacheKey = (prefix: string, ...args: readonly string[]) =>
`cache:${prefix}:${args.join(':')}`;

export const withCache = async <T>(
key: string,
fetchFn: () => Promise<T>,
cache_expiry_in_seconds: number
): Promise<T> => {
const now = Date.now();
const cached = cacheStore.get(key);

// Check if we have valid cached data
if (cached && cached.expiry > now) {
return cached.data as T;
}

// If no cached data or expired, fetch and cache
// eslint-disable-next-line functional/no-try-statements
try {
const data = await fetchFn();
// eslint-disable-next-line functional/no-expression-statements
cacheStore.set(key, {
data,
expiry: now + cache_expiry_in_seconds * 1000,
});
return data;
} catch (error) {
// eslint-disable-next-line functional/no-expression-statements
console.error('Cache error:', error);
return fetchFn();
}
};
Loading

0 comments on commit 95fc48f

Please sign in to comment.