diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-15 19:11:59 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-15 19:23:54 +0100 |
| commit | 3760b757f8fd35eafc340a43f7980ab954413f4e (patch) | |
| tree | 3342bd1abbfa72df157d609c510a6207c5949a23 /src/services | |
| parent | 102121498b45ef221191401f6216260f072f78a9 (diff) | |
chore: create CV view
Diffstat (limited to 'src/services')
| -rw-r--r-- | src/services/graphql/pages.ts | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/services/graphql/pages.ts b/src/services/graphql/pages.ts new file mode 100644 index 0000000..6689e37 --- /dev/null +++ b/src/services/graphql/pages.ts @@ -0,0 +1,48 @@ +import { + FetchPageByUriReturn, + GetCVPageReturn, + Page, + PageResponse, + RawPage, +} from '@ts/types/pages'; +import { gql } from 'graphql-request'; +import { getGraphQLClient } from './client'; + +const fetchPageByUri: FetchPageByUriReturn = async (uri: string) => { + const client = getGraphQLClient(); + const query = gql` + query PageByUri($uri: String!) { + pageBy(uri: $uri) { + contentParts { + afterMore + beforeMore + } + date + modified + title + } + } + `; + + const variables = { uri }; + + try { + const response: PageResponse = await client.request(query, variables); + return response.pageBy; + } catch (error) { + console.error(JSON.stringify(error, undefined, 2)); + process.exit(1); + } +}; + +export const getCVPage: GetCVPageReturn = async () => { + const rawCV = await fetchPageByUri('/cv/'); + + const formattedCV: Page = { + ...rawCV, + content: rawCV.contentParts.afterMore, + intro: rawCV.contentParts.beforeMore, + }; + + return formattedCV; +}; |
