-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
OPHJOD-1139: Fetch content from CMS API and show them as cards on hom…
…e page
- Loading branch information
Showing
9 changed files
with
212 additions
and
28 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,4 @@ | ||
JODTOKEN= | ||
CMSUSER= | ||
CMSPASSWORD= | ||
CMSURL= |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import Home from './Home'; | ||
import loader from './loader'; | ||
|
||
export { Home }; | ||
export { Home, loader as homeLoader }; |
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 { StructuredContentPage } from '@/types/cms-content'; | ||
import { LoaderFunction } from 'react-router'; | ||
|
||
const loader = (async () => { | ||
const queryParams = new URLSearchParams(); | ||
queryParams.set('sort', 'dateCreated:desc'); | ||
const response = await fetch(`cms/o/headless-delivery/v1.0/sites/20117/structured-contents?${queryParams}`, { | ||
headers: { | ||
Accept: 'application/json', | ||
'Accept-Language': 'fi-FI', | ||
}, | ||
}); | ||
const data: StructuredContentPage = await response.json(); | ||
|
||
return { data }; | ||
}) satisfies LoaderFunction; | ||
|
||
export type LoaderData = Awaited<ReturnType<typeof loader>>; | ||
export default loader; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/TaxonomyCategoryBrief | ||
export interface TaxonomyBrief { | ||
taxonomyCategoryId: number; | ||
taxonomyCategoryName: string; | ||
} | ||
|
||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/ContentDocument | ||
export interface ContentDocument { | ||
contentType: string; | ||
contentUrl: string; | ||
description: string; | ||
encodingFormat: string; | ||
fileExtension: string; | ||
id: number; | ||
sizeInBytes: number; | ||
title: string; | ||
} | ||
|
||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/ContentFieldValue | ||
export interface ContentFieldValue { | ||
data?: string; | ||
image?: ContentDocument; | ||
geo?: Record<string, unknown>; | ||
link?: string; | ||
} | ||
|
||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/ContentField | ||
export interface ContentField { | ||
contentFieldValue: ContentFieldValue; | ||
dataType: string; | ||
inputControl: string; | ||
label: string; | ||
name: string; | ||
nestedContentFields: unknown[]; | ||
repeatable: boolean; | ||
} | ||
|
||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/StructuredContent | ||
export interface StructuredContent { | ||
actions?: Record<string, unknown>; | ||
availableLanguages?: string[]; | ||
contentFields?: ContentField[]; | ||
contentStructureId: number; | ||
creator?: Record<string, string | number>; | ||
customFields?: unknown[]; | ||
dateCreated?: string; | ||
dateModified?: string; | ||
description?: string; | ||
externalReferenceCode?: string; | ||
friendlyUrlPath?: string; | ||
id?: number; | ||
key?: number; | ||
keywords?: string[]; | ||
neverExpire?: boolean; | ||
numberOfComments?: number; | ||
priority?: number; | ||
relatedContents?: unknown[]; | ||
renderedContents?: Record<string, unknown>[]; | ||
siteId?: number; | ||
strucuturedContentFolderId?: number; | ||
subscribed?: boolean; | ||
taxonomyCategoryBriefs?: TaxonomyBrief[]; | ||
title: string; | ||
uuid?: string; | ||
} | ||
|
||
// https://app.swaggerhub.com/apis/liferayinc/headless-delivery/v1.0#/StructuredContent/getSiteStructuredContentsPage | ||
export interface StructuredContentPage { | ||
actions: Record<string, unknown>; | ||
facets: unknown[]; | ||
items: StructuredContent[]; | ||
lastPage: number; | ||
page: number; | ||
pageSize: number; | ||
totalCount: number; | ||
} |
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,13 @@ | ||
import { StructuredContent } from '@/types/cms-content'; | ||
|
||
type ContentLabel = 'Tiivistelmä' | 'Kuvaus' | 'Kuva' | 'Tiedosto' | 'Linkki'; | ||
|
||
/** | ||
* Finds the content value from Liferay strucured content by label | ||
* @param item Structured content item | ||
* @param {ContentLabel} label Content label | ||
* @returns {ContentFieldValue | undefined} Content value | ||
*/ | ||
export const findContentValueByLabel = (item: StructuredContent, label: ContentLabel) => { | ||
return item.contentFields?.find((field) => field.label === label)?.contentFieldValue; | ||
}; |
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 |
---|---|---|
@@ -1,30 +1,57 @@ | ||
/// <reference types="vitest" /> | ||
import react from '@vitejs/plugin-react-swc'; | ||
import { fileURLToPath } from 'node:url'; | ||
import { defineConfig } from 'vite'; | ||
import { defineConfig, loadEnv } from 'vite'; | ||
|
||
const cmsHeaders = (env: Record<string, string>) => ({ | ||
Cookie: `JODTOKEN=${env.JODTOKEN}`, | ||
Accept: 'application/json', | ||
Authorization: 'Basic ' + Buffer.from(`${env.CMSUSER}:${env.CMSPASSWORD}`).toString('base64'), | ||
}); | ||
|
||
// https://vite.dev/config/ | ||
export default defineConfig({ | ||
base: '/ohjaaja/', | ||
plugins: [react()], | ||
test: { | ||
environment: 'jsdom', | ||
globals: true, | ||
setupFiles: ['./vitest.setup.ts'], | ||
coverage: { | ||
provider: 'v8', | ||
reporter: ['lcov'], | ||
export default defineConfig(({ mode }) => { | ||
// loadEnv is required to read .env files | ||
const env = loadEnv(mode, process.cwd(), ''); | ||
const target = env.CMSURL; | ||
|
||
return { | ||
base: '/ohjaaja/', | ||
plugins: [react()], | ||
test: { | ||
environment: 'jsdom', | ||
globals: true, | ||
setupFiles: ['./vitest.setup.ts'], | ||
coverage: { | ||
provider: 'v8', | ||
reporter: ['lcov'], | ||
}, | ||
}, | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: '@', | ||
replacement: fileURLToPath(new URL('./src', import.meta.url)), | ||
}, | ||
], | ||
}, | ||
}, | ||
resolve: { | ||
alias: [ | ||
{ | ||
find: '@', | ||
replacement: fileURLToPath(new URL('./src', import.meta.url)), | ||
server: { | ||
port: 8080, | ||
proxy: { | ||
'/ohjaaja/cms': { | ||
target, | ||
changeOrigin: true, | ||
xfwd: true, | ||
rewrite: (path) => path.replace(/^\/ohjaaja\/cms/, '/cms'), | ||
headers: cmsHeaders(env), | ||
}, | ||
'/cms/documents': { | ||
target, | ||
changeOrigin: true, | ||
xfwd: true, | ||
headers: cmsHeaders(env), | ||
}, | ||
}, | ||
], | ||
}, | ||
server: { | ||
port: 8080, | ||
}, | ||
}, | ||
}; | ||
}); |