dropped live prop from contentful in favour of previews, fixed linting
This commit is contained in:
parent
86ab07e34a
commit
e4742d5560
|
@ -8,8 +8,8 @@
|
||||||
"build:staging": "NEXT_PUBLIC_SITE_ENV=development NODE_ENV=production next build",
|
"build:staging": "NEXT_PUBLIC_SITE_ENV=development NODE_ENV=production next build",
|
||||||
"start": "NEXT_PUBLIC_SITE_ENV=production NODE_ENV=production next start",
|
"start": "NEXT_PUBLIC_SITE_ENV=production NODE_ENV=production next start",
|
||||||
"start:staging": "NEXT_PUBLIC_SITE_ENV=development NODE_ENV=production next start",
|
"start:staging": "NEXT_PUBLIC_SITE_ENV=development NODE_ENV=production next start",
|
||||||
"lint": "next lint --quiet",
|
"lint": "next lint",
|
||||||
"lint:fix": "npm run lint --fix"
|
"lint:fix": "eslint --fix"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/icons": "^4.2.2",
|
"@ant-design/icons": "^4.2.2",
|
||||||
|
|
|
@ -22,15 +22,9 @@ import {
|
||||||
IFetchFAQItemsReturn,
|
IFetchFAQItemsReturn,
|
||||||
ITagList,
|
ITagList,
|
||||||
} from '../types/cms';
|
} from '../types/cms';
|
||||||
import isLive from '../utils/environment';
|
|
||||||
import { generateURL } from '../constants/metadata';
|
import { generateURL } from '../constants/metadata';
|
||||||
import { fetchContent } from './embed';
|
import { fetchContent } from './embed';
|
||||||
|
|
||||||
function loadOptions(options: any) {
|
|
||||||
if (isLive()) options['fields.live'] = true;
|
|
||||||
return options;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Turns CMS IDs into slugs
|
// Turns CMS IDs into slugs
|
||||||
export const slugify = (id: string) => id?.replace(/_/g, '-').toLowerCase();
|
export const slugify = (id: string) => id?.replace(/_/g, '-').toLowerCase();
|
||||||
export const unslugify = (slug: string) =>
|
export const unslugify = (slug: string) =>
|
||||||
|
@ -65,14 +59,12 @@ export class CmsApi {
|
||||||
quantity = CMS.BLOG_RESULTS_PER_PAGE,
|
quantity = CMS.BLOG_RESULTS_PER_PAGE,
|
||||||
page = 1,
|
page = 1,
|
||||||
): Promise<IFetchBlogEntriesReturn> {
|
): Promise<IFetchBlogEntriesReturn> {
|
||||||
const _entries = await this.client.getEntries(
|
const _entries = await this.client.getEntries({
|
||||||
loadOptions({
|
content_type: 'post', // only fetch blog post entry
|
||||||
content_type: 'post', // only fetch blog post entry
|
order: '-fields.date',
|
||||||
order: '-fields.date',
|
limit: quantity,
|
||||||
limit: quantity,
|
skip: (page - 1) * quantity,
|
||||||
skip: (page - 1) * quantity,
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = await this.generateEntries(_entries, 'post');
|
const results = await this.generateEntries(_entries, 'post');
|
||||||
return {
|
return {
|
||||||
|
@ -86,15 +78,13 @@ export class CmsApi {
|
||||||
quantity = CMS.BLOG_RESULTS_PER_PAGE_TAGGED,
|
quantity = CMS.BLOG_RESULTS_PER_PAGE_TAGGED,
|
||||||
page = 1,
|
page = 1,
|
||||||
): Promise<IFetchBlogEntriesReturn> {
|
): Promise<IFetchBlogEntriesReturn> {
|
||||||
const _entries = await this.client.getEntries(
|
const _entries = await this.client.getEntries({
|
||||||
loadOptions({
|
content_type: 'post',
|
||||||
content_type: 'post',
|
order: '-fields.date',
|
||||||
order: '-fields.date',
|
'fields.tags[in]': tag,
|
||||||
'fields.tags[in]': tag,
|
limit: quantity,
|
||||||
limit: quantity,
|
skip: (page - 1) * quantity,
|
||||||
skip: (page - 1) * quantity,
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = await this.generateEntries(_entries, 'post');
|
const results = await this.generateEntries(_entries, 'post');
|
||||||
return {
|
return {
|
||||||
|
@ -108,15 +98,13 @@ export class CmsApi {
|
||||||
page = 1,
|
page = 1,
|
||||||
): Promise<IFetchBlogEntriesReturn> {
|
): Promise<IFetchBlogEntriesReturn> {
|
||||||
const DEV_UPDATE_TAG = 'dev-update';
|
const DEV_UPDATE_TAG = 'dev-update';
|
||||||
const _entries = await this.client.getEntries(
|
const _entries = await this.client.getEntries({
|
||||||
loadOptions({
|
content_type: 'post', // only fetch blog post entry
|
||||||
content_type: 'post', // only fetch blog post entry
|
order: '-fields.date',
|
||||||
order: '-fields.date',
|
'fields.tags[ne]': DEV_UPDATE_TAG, // Exclude blog posts with the "dev-update" tag
|
||||||
'fields.tags[ne]': DEV_UPDATE_TAG, // Exclude blog posts with the "dev-update" tag
|
limit: quantity,
|
||||||
limit: quantity,
|
skip: (page - 1) * quantity,
|
||||||
skip: (page - 1) * quantity,
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = await this.generateEntries(_entries, 'post');
|
const results = await this.generateEntries(_entries, 'post');
|
||||||
return {
|
return {
|
||||||
|
@ -127,12 +115,10 @@ export class CmsApi {
|
||||||
|
|
||||||
public async fetchPageEntries(): Promise<TPages> {
|
public async fetchPageEntries(): Promise<TPages> {
|
||||||
try {
|
try {
|
||||||
const _entries = await this.client.getEntries(
|
const _entries = await this.client.getEntries({
|
||||||
loadOptions({
|
content_type: 'splitPage', // only fetch blog post entry
|
||||||
content_type: 'splitPage', // only fetch blog post entry
|
order: 'fields.order',
|
||||||
order: 'fields.order',
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = await this.generateEntries(_entries, 'splitPage');
|
const results = await this.generateEntries(_entries, 'splitPage');
|
||||||
const pages: TPages = {};
|
const pages: TPages = {};
|
||||||
|
@ -215,12 +201,10 @@ export class CmsApi {
|
||||||
slug: string,
|
slug: string,
|
||||||
entryType: 'post' | 'splitPage',
|
entryType: 'post' | 'splitPage',
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
const _entries = await this.client.getEntries(
|
const _entries = await this.client.getEntries({
|
||||||
loadOptions({
|
content_type: entryType, // only fetch specific type
|
||||||
content_type: entryType, // only fetch specific type
|
'fields.slug': slug,
|
||||||
'fields.slug': slug,
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
if (_entries?.items?.length > 0) {
|
if (_entries?.items?.length > 0) {
|
||||||
let entry;
|
let entry;
|
||||||
|
@ -244,12 +228,10 @@ export class CmsApi {
|
||||||
|
|
||||||
public async fetchPageById(id: SideMenuItem): Promise<ISplitPage> {
|
public async fetchPageById(id: SideMenuItem): Promise<ISplitPage> {
|
||||||
return this.client
|
return this.client
|
||||||
.getEntries(
|
.getEntries({
|
||||||
loadOptions({
|
content_type: 'splitPage',
|
||||||
content_type: 'splitPage',
|
'fields.id[in]': id,
|
||||||
'fields.id[in]': id,
|
})
|
||||||
}),
|
|
||||||
)
|
|
||||||
.then(entries => {
|
.then(entries => {
|
||||||
if (entries && entries.items && entries.items.length > 0) {
|
if (entries && entries.items && entries.items.length > 0) {
|
||||||
return this.convertPage(entries.items[0]);
|
return this.convertPage(entries.items[0]);
|
||||||
|
|
Loading…
Reference in New Issue