-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into chatbot/docker-compose-complete
- Loading branch information
Showing
12 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": patch | ||
--- | ||
|
||
Add UrlReplaceMapCodec and mapping function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": patch | ||
--- | ||
|
||
Fix margins and text size of guides and tutorials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"nextjs-website": patch | ||
--- | ||
|
||
Fix tutorial's in page menu |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
apps/nextjs-website/src/lib/strapi/__tests__/urlReplaceMap.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { UrlReplaceMapCodec } from '../codecs/UrlReplaceMapCodec'; | ||
import * as Either from 'fp-ts/lib/Either'; | ||
import { productJson } from './fixtures/product'; | ||
import { makeUrlReplaceMap } from '../makeProps/makeUrlReplaceMap'; | ||
import { pipe } from 'fp-ts/lib/function'; | ||
import { mediaRasterJson } from './fixtures/media'; | ||
|
||
const strapiResponse = { | ||
data: { | ||
id: 1, | ||
attributes: { | ||
createdAt: '2024-09-30T10:12:44.888Z', | ||
updatedAt: '2024-09-30T10:12:45.562Z', | ||
publishedAt: '2024-09-30T10:12:45.561Z', | ||
urlToGuide: [ | ||
{ | ||
id: 1, | ||
url: 'aaaa', | ||
version: '2', | ||
guide: { | ||
data: { | ||
id: 1, | ||
attributes: { | ||
title: 'aaa', | ||
slug: 'aaaa', | ||
createdAt: '2024-09-30T10:12:08.182Z', | ||
updatedAt: '2024-09-30T10:12:24.805Z', | ||
publishedAt: '2024-09-30T10:12:24.802Z', | ||
locale: 'en', | ||
image: mediaRasterJson, | ||
mobileImage: mediaRasterJson, | ||
listItems: [ | ||
{ id: 1, text: 'rhhtrhrthrt' }, | ||
{ id: 2, text: 'fdsafdsagtyhtyh' }, | ||
{ id: 3, text: 'hrhrhthrtyrth' }, | ||
], | ||
product: productJson, | ||
versions: [], | ||
bannerLinks: [], | ||
seo: null, | ||
}, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
meta: {}, | ||
}; | ||
|
||
describe('UrlReplaceMapCodec', () => { | ||
it('should decode strapi UrlReplaceMapCodec', () => { | ||
const decodeResponse = UrlReplaceMapCodec.decode(strapiResponse); | ||
expect(Either.isRight(decodeResponse)).toBeTruthy(); | ||
}); | ||
|
||
it('Should correctly convert the map into a record', () => { | ||
const validation = UrlReplaceMapCodec.decode(strapiResponse); | ||
const result = pipe( | ||
validation, | ||
Either.fold( | ||
(left) => { | ||
console.error('Error:', left); | ||
return null; // or handle the error as needed | ||
}, | ||
(right) => { | ||
console.log('Success:', right); | ||
return right; | ||
} | ||
) | ||
); | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
const urlReplaceMap = makeUrlReplaceMap(result!); | ||
|
||
expect(urlReplaceMap).toEqual({ | ||
aaaa: 'firma-con-io/guides/aaaa/2', | ||
}); | ||
}); | ||
}); |
22 changes: 22 additions & 0 deletions
22
apps/nextjs-website/src/lib/strapi/codecs/UrlReplaceMapCodec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as t from 'io-ts/lib'; | ||
import { GuideCodec } from './GuidesCodec'; | ||
import { NullToUndefinedCodec } from './NullToUndefinedCodec'; | ||
|
||
const UrlToGuideCodec = t.strict({ | ||
id: t.number, | ||
url: t.string, | ||
version: t.union([NullToUndefinedCodec, t.string]), | ||
guide: t.strict({ | ||
data: t.union([NullToUndefinedCodec, GuideCodec]), | ||
}), | ||
}); | ||
|
||
export const UrlReplaceMapCodec = t.strict({ | ||
data: t.strict({ | ||
attributes: t.strict({ | ||
urlToGuide: t.array(UrlToGuideCodec), | ||
}), | ||
}), | ||
}); | ||
|
||
export type StrapiUrlReplaceMap = t.TypeOf<typeof UrlReplaceMapCodec>; |
24 changes: 24 additions & 0 deletions
24
apps/nextjs-website/src/lib/strapi/fetches/fetchUrlReplaceMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { fetchFromStrapi } from '../fetchFromStrapi'; | ||
import { UrlReplaceMapCodec } from '../codecs/UrlReplaceMapCodec'; | ||
import qs from 'qs'; | ||
|
||
const makeStrapiUrlReplaceMapPopulate = () => | ||
qs.stringify({ | ||
populate: [ | ||
'urlToGuide.guide.*', | ||
'urlToGuide.guide.image', | ||
'urlToGuide.guide.mobileImage', | ||
'urlToGuide.guide.listItems', | ||
'urlToGuide.guide.product.*', | ||
'urlToGuide.guide.versions.*', | ||
'urlToGuide.guide.seo.*', | ||
'urlToGuide.guide.product.bannerLinks.*', | ||
'urlToGuide.guide.product.bannerLinks.icon', | ||
], | ||
}); | ||
|
||
export const fetchUrlReplaceMap = fetchFromStrapi( | ||
'url-replace-map', | ||
makeStrapiUrlReplaceMapPopulate(), | ||
UrlReplaceMapCodec | ||
); |
19 changes: 19 additions & 0 deletions
19
apps/nextjs-website/src/lib/strapi/makeProps/makeUrlReplaceMap.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { StrapiUrlReplaceMap } from '../codecs/UrlReplaceMapCodec'; | ||
|
||
export type UrlReplaceMap = Record<string, string>; | ||
|
||
export function makeUrlReplaceMap( | ||
urlReplacemap: StrapiUrlReplaceMap | ||
): UrlReplaceMap { | ||
const map = urlReplacemap.data.attributes.urlToGuide.reduce((map, obj) => { | ||
return { | ||
...map, | ||
[obj.url]: `${ | ||
obj.guide.data?.attributes.product.data.attributes.slug | ||
}/guides/${obj.guide.data?.attributes.slug}${ | ||
obj.version ? `/${obj.version}` : '' | ||
}`, | ||
}; | ||
}, {} as UrlReplaceMap); | ||
return map; | ||
} |