Skip to content

Commit

Permalink
moved getProvider()
Browse files Browse the repository at this point in the history
  • Loading branch information
leoloso committed Mar 26, 2024
1 parent 95aff9c commit 835d5a6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
18 changes: 1 addition & 17 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ const feed = require('./plugins/feed');
const sitemap = require('./plugins/sitemap');
// const socialImages = require('./plugins/socialImages'); TODO: failing to run on Netlify

import { WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL, WORDPRESS_GRAPHQL_PROVIDER_GATOGRAPHQL } from 'providers/providers';

/** @type {import('next').NextConfig} */
const nextConfig = {
reactStrictMode: true,
Expand All @@ -31,11 +29,7 @@ const nextConfig = {
// the rest will be rendered on-demand
POSTS_PRERENDER_COUNT: 5,

WORDPRESS_GRAPHQL_PROVIDER: parseEnvConstValue(
(process.env.WORDPRESS_GRAPHQL_PROVIDER || '').toLowerCase(),
[WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL, WORDPRESS_GRAPHQL_PROVIDER_GATOGRAPHQL],
WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL
),
WORDPRESS_GRAPHQL_PROVIDER: process.env.WORDPRESS_GRAPHQL_PROVIDER,
WORDPRESS_GRAPHQL_ENDPOINT: process.env.WORDPRESS_GRAPHQL_ENDPOINT,
WORDPRESS_MENU_LOCATION_NAVIGATION: process.env.WORDPRESS_MENU_LOCATION_NAVIGATION || 'PRIMARY',
WORDPRESS_PLUGIN_SEO: parseEnvValue(process.env.WORDPRESS_PLUGIN_SEO, false),
Expand All @@ -58,13 +52,3 @@ function parseEnvValue(value, defaultValue) {
if (value === false || value === 'false') return false;
return value;
}

/**
* parseEnvConst
* @description Helper function to make sure the provider exists, or provide the default one
*/

function parseEnvConstValue(value, options, defaultValue) {
if (!value || !options.includes(value)) return defaultValue;
return value;
}
14 changes: 14 additions & 0 deletions src/lib/provider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL, WORDPRESS_GRAPHQL_PROVIDER_GATOGRAPHQL } from 'providers/providers';

/**
* getProvider
*/

export async function getProvider() {
const providers = [WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL, WORDPRESS_GRAPHQL_PROVIDER_GATOGRAPHQL];
const defaultProvider = WORDPRESS_GRAPHQL_PROVIDER_WPGRAPHQL;
const selectedProvider = (process.env.WORDPRESS_GRAPHQL_PROVIDER || '').toLowerCase();
if (!selectedProvider || !providers.includes(selectedProvider)) return defaultProvider;

return selectedProvider;
}

0 comments on commit 835d5a6

Please sign in to comment.