Skip to content

Commit

Permalink
Updates to CONTENTFUL_USE_PREVIEW Default Value (#147)
Browse files Browse the repository at this point in the history
* Testing: Remove cache-netlify-plugin from netlify.toml

* chore: Add console log linting workflow

* Testing Prod Values on Branch

* Update Contentful configuration and remove unused variables

* Updating code to ensure default value of false is read for CONTENTFUL_USE_PREVIEW and preview if value is unable to be read properly

* Fix CONTENTFUL_USE_PREVIEW in next.config.js and reverting change to netlify.toml
  • Loading branch information
ct3685 authored Aug 22, 2024
1 parent ce9fa9e commit 8c33470
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 29 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: Console Log Linting
on: [push]

jobs:
lint:
uses: last-rev-llc/workflows/.github/workflows/lint.yml@main
13 changes: 7 additions & 6 deletions lrconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ const parseNumberEnvVar = (value = '') => {
return isNaN(result) ? undefined : result;
};

const parseBooleanEnvVar = (value) => {
const val = value ? value.toString().toLowerCase() : '';
return /^(true|1|yes|y)$/.test(val);
};

const spaceId = testForEnvVar('CONTENTFUL_SPACE_ID');
const contentDeliveryToken = testForEnvVar('CONTENTFUL_DELIVERY_TOKEN');
const contentPreviewToken = testForEnvVar('CONTENTFUL_PREVIEW_TOKEN');
const env = testForEnvVar('CONTENTFUL_ENV');
const parseBooleanEnvVar = (value = '') => {
// values parsed as true: true, 1, yes, y, => ignore caps
const val = value.toString().toLowerCase();
return /^(true|1|yes|y)$/.test(val);
};
const usePreview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false;

const config = new LastRevAppConfig({
cms: 'Contentful',
Expand All @@ -40,7 +41,7 @@ const config = new LastRevAppConfig({
contentDeliveryToken,
spaceId,
env,
usePreview: parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW),
usePreview,
maxBatchSize: parseNumberEnvVar(process.env.CONTENTFUL_MAX_BATCH_SIZE)
},
algolia: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ export type {
} from '@last-rev/component-library/dist/components/CollectionFiltered';
import CollectionFiltered from '@last-rev/component-library/dist/components/CollectionFiltered';

const preview = !!process.env.CONTENTFUL_USE_PREVIEW;
const parseBooleanEnvVar = (value = '') => {
const val = value.toString().toLowerCase();
return /^(true|1|yes|y)$/.test(val);
};

const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false;

const withFetchItems = (Wrapped: any) => (props: any) => {
const fetchItems = async ({ filter, limit, offset }: { filter: any; limit?: number; offset?: number }) => {
Expand Down
7 changes: 6 additions & 1 deletion packages/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ const sentryWebpackPluginOptions = {
// https://github.com/getsentry/sentry-webpack-plugin#options.
};

const parseBooleanEnvVar = (value) => {
const val = value ? value.toString().toLowerCase() : '';
return /^(true|1|yes|y)$/.test(val);
};

const nextConfig = {
...(process.env.NODE_ENV === 'production' && {
async headers() {
Expand Down Expand Up @@ -119,7 +124,7 @@ const nextConfig = {
env: {
CONTENTFUL_SETTINGS_ID: process.env.CONTENTFUL_SETTINGS_ID,
GRAPHQL_SERVER_URL: process.env.GRAPHQL_SERVER_URL,
CONTENTFUL_USE_PREVIEW: process.env.CONTENTFUL_USE_PREVIEW,
CONTENTFUL_USE_PREVIEW: parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false,
SITE: process.env.SITE,
SITE_SETTINGS: process.env.SITE_SETTINGS,
DEFAULT_SITE_ID: process.env.DEFAULT_SITE_ID || process.env.SITE_ID,
Expand Down
2 changes: 1 addition & 1 deletion packages/web/pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ContentModuleProvider } from '@last-rev/component-library/dist/componen
import ContentModule from '@last-rev/component-library/dist/components/ContentModule/ContentModule';
import contentMapping from '@last-rev-marketing-site/components/src/contentMapping';

const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW);
const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false;
const site = process.env.SITE;
const pagesRevalidate = parseInt(process.env.PAGES_REVALIDATE as string, 10);
const revalidate = !isNaN(pagesRevalidate) ? pagesRevalidate : false;
Expand Down
2 changes: 1 addition & 1 deletion packages/web/pages/[[...slug]].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ContentModuleProvider } from '@last-rev/component-library/dist/componen
import ContentModule from '@last-rev/component-library/dist/components/ContentModule/ContentModule';
import contentMapping from '@last-rev-marketing-site/components/src/contentMapping';

const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW);
const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false;
const site = process.env.SITE;
const pagesRevalidate = parseInt(process.env.PAGES_REVALIDATE as string, 10);
const revalidate = !isNaN(pagesRevalidate) ? pagesRevalidate : false;
Expand Down
2 changes: 1 addition & 1 deletion packages/web/pages/sitemap/[...slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { GetServerSideProps } from 'next';
import { client, parseBooleanEnvVar } from '@last-rev-marketing-site/utils';
import config from '../../../../lrconfig';

const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW);
const preview = parseBooleanEnvVar(process.env.CONTENTFUL_USE_PREVIEW) || false;

const pageMatcher = /^([^\-]+)-(\d+)-sitemap.xml$/;

Expand Down
24 changes: 6 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -23078,6 +23078,11 @@ locate-path@^6.0.0:
dependencies:
p-locate "^5.0.0"

lodash-es@^4.17.21:
version "4.17.21"
resolved "https://registry.yarnpkg.com/lodash-es/-/lodash-es-4.17.21.tgz#43e626c46e6591b7750beb2b50117390c609e3ee"
integrity sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==

lodash._reinterpolate@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -28469,16 +28474,7 @@ react-docgen@^5.0.0:
node-dir "^0.1.10"
strip-indent "^3.0.0"

react-dom@^17.0.1:
version "17.0.2"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-17.0.2.tgz#ecffb6845e3ad8dbfcdc498f0d0a939736502c23"
integrity sha512-s4h96KtLDUQlsENhMn1ar8t2bEa+q/YAtj8pPPdIjPDGBDIVNsrD9aXNWqspUe6AzKCIG0C1HZZLqLV7qpOBGA==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"
scheduler "^0.20.2"

react-dom@^18.2.0:
react-dom@^17.0.1, react-dom@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-18.2.0.tgz#22aaf38708db2674ed9ada224ca4aa708d821e3d"
integrity sha512-6IMTriUmvsjHUjNtEDudZfuDQUoWXVxKHhlEGSk81n4YFS+r/Kl99wXiwlVXtPBtJenozv2P+hxDsw9eA7Xo6g==
Expand Down Expand Up @@ -29974,14 +29970,6 @@ saxes@^5.0.1:
dependencies:
xmlchars "^2.2.0"

scheduler@^0.20.2:
version "0.20.2"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.20.2.tgz#4baee39436e34aa93b4874bddcbf0fe8b8b50e91"
integrity sha512-2eWfGgAqqWFGqtdMmcL5zCMK1U8KlXv8SQFGglL3CEtd0aDVDWgeF/YoCmvln55m5zSk3J/20hTaSBeSObsQDQ==
dependencies:
loose-envify "^1.1.0"
object-assign "^4.1.1"

scheduler@^0.23.0:
version "0.23.0"
resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.23.0.tgz#ba8041afc3d30eb206a487b6b384002e4e61fdfe"
Expand Down

0 comments on commit 8c33470

Please sign in to comment.