Skip to content

Commit

Permalink
feat(project): customizable footer through env-var
Browse files Browse the repository at this point in the history
Co-authored-by: Mike van Veenhuijzen <mike@videodock.com>
  • Loading branch information
2 people authored and ChristiaanScheermeijer committed Jan 31, 2024
1 parent 588f69a commit 9d8ff15
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
9 changes: 1 addition & 8 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ Use the `styling` object to define extra styles for your application.
"styling": {
"backgroundColor": null,
"highlightColor": null,
"headerBackground": null,
"footerText": "Blender Foundation"
"headerBackground": null
}
```

Expand All @@ -187,12 +186,6 @@ Use this parameter to change the background color of the header. By default, the

---

**styling.footerText** (optional)

Text that will be placed in the footer of the site. Markdown links are supported.

---

**features**

Use the `features` object to define extra properties for your app.
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type Env = {
APP_VERSION: string;
APP_API_BASE_URL: string;
APP_PLAYER_ID: string;

APP_FOOTER_TEXT: string;
APP_DEFAULT_CONFIG_SOURCE?: string;
APP_PLAYER_LICENSE_KEY?: string;
};
Expand All @@ -11,12 +11,14 @@ const env: Env = {
APP_VERSION: '',
APP_API_BASE_URL: 'https://cdn.jwplayer.com',
APP_PLAYER_ID: 'M4qoGvUk',
APP_FOOTER_TEXT: '',
};

export const configureEnv = (options: Partial<Env>) => {
env.APP_VERSION = options.APP_VERSION || env.APP_VERSION;
env.APP_API_BASE_URL = options.APP_API_BASE_URL || env.APP_API_BASE_URL;
env.APP_PLAYER_ID = options.APP_PLAYER_ID || env.APP_PLAYER_ID;
env.APP_FOOTER_TEXT = options.APP_FOOTER_TEXT || env.APP_FOOTER_TEXT;

env.APP_DEFAULT_CONFIG_SOURCE ||= options.APP_DEFAULT_CONFIG_SOURCE;
env.APP_PLAYER_LICENSE_KEY ||= options.APP_PLAYER_LICENSE_KEY;
Expand Down
4 changes: 1 addition & 3 deletions packages/common/src/services/ConfigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ export default class ConfigService {
content: [],
menu: [],
integrations: {},
styling: {
footerText: '',
},
styling: {},
features: {},
};

Expand Down
4 changes: 1 addition & 3 deletions packages/common/src/stores/ConfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ export const useConfigStore = createStore<ConfigState>('ConfigStore', () => ({
useSandbox: true,
},
},
styling: {
footerText: '',
},
styling: {},
},
settings: {
additionalAllowedConfigSources: [],
Expand Down
6 changes: 6 additions & 0 deletions packages/common/src/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ export function debounce<T extends (...args: any[]) => void>(callback: T, wait =
};
}

export const unicodeToChar = (text: string) => {
return text.replace(/\\u[\dA-F]{4}/gi, (match) => {
return String.fromCharCode(parseInt(match.replace(/\\u/g, ''), 16));
});
};

/**
* Parse hex color and return the RGB colors
* @param color
Expand Down
1 change: 0 additions & 1 deletion packages/common/src/utils/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const stylingSchema: SchemaOf<Styling> = object({
backgroundColor: string().nullable(),
highlightColor: string().nullable(),
headerBackground: string().nullable(),
footerText: string().nullable(),
});

export const configSchema: SchemaOf<Config> = object({
Expand Down
1 change: 0 additions & 1 deletion packages/common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ export type Styling = {
backgroundColor?: string | null;
highlightColor?: string | null;
headerBackground?: string | null;
footerText?: string | null;
};

export type Cleeng = {
Expand Down
3 changes: 1 addition & 2 deletions packages/testing/fixtures/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"styling": {
"backgroundColor": null,
"highlightColor": null,
"headerBackground": null,
"footerText": "\u00a9 Blender Foundation | [cloud.blender.org](https://cloud.blender.org)"
"headerBackground": null
},
"description": "Blender demo site",
"analyticsToken": "lDd_MCg4EeuMunbqcIJccw",
Expand Down
8 changes: 5 additions & 3 deletions packages/ui-react/src/containers/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import { useConfigStore } from '@jwp/ott-common/src/stores/ConfigStore';
import { useProfileStore } from '@jwp/ott-common/src/stores/ProfileStore';
import ProfileController from '@jwp/ott-common/src/stores/ProfileController';
import { modalURLFromLocation } from '@jwp/ott-ui-react/src/utils/location';
import { IS_DEVELOPMENT_BUILD } from '@jwp/ott-common/src/utils/common';
import { IS_DEVELOPMENT_BUILD, unicodeToChar } from '@jwp/ott-common/src/utils/common';
import { ACCESS_MODEL } from '@jwp/ott-common/src/constants';
import useSearchQueryUpdater from '@jwp/ott-ui-react/src/hooks/useSearchQueryUpdater';
import { useProfiles, useSelectProfile } from '@jwp/ott-hooks-react/src/useProfiles';
import { PATH_HOME, PATH_USER_PROFILES } from '@jwp/ott-common/src/paths';
import { playlistURL } from '@jwp/ott-common/src/utils/urlFormatting';
import env from '@jwp/ott-common/src/env';

import MarkdownComponent from '../../components/MarkdownComponent/MarkdownComponent';
import Header from '../../components/Header/Header';
Expand All @@ -27,6 +28,8 @@ import Button from '../../components/Button/Button';

import styles from './Layout.module.scss';

const footerText = unicodeToChar(env.APP_FOOTER_TEXT);

const Layout = () => {
const location = useLocation();
const navigate = useNavigate();
Expand All @@ -38,13 +41,12 @@ const Layout = () => {
);
const isLoggedIn = !!useAccountStore(({ user }) => user);
const favoritesEnabled = !!config.features?.favoritesList;
const { menu, assets, siteName, description, styling, features } = config;
const { menu, assets, siteName, description, features } = config;
const metaDescription = description || t('default_description');

const profileController = getModule(ProfileController, false);

const { searchPlaylist } = features || {};
const { footerText } = styling || {};
const currentLanguage = useMemo(() => supportedLanguages.find(({ code }) => code === i18n.language), [i18n.language, supportedLanguages]);

const {
Expand Down
2 changes: 2 additions & 0 deletions platforms/web/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ configureEnv({

APP_DEFAULT_CONFIG_SOURCE: import.meta.env.APP_DEFAULT_CONFIG_SOURCE,
APP_PLAYER_LICENSE_KEY: import.meta.env.APP_PLAYER_LICENSE_KEY,

APP_FOOTER_TEXT: import.meta.env.APP_FOOTER_TEXT,
});

const rootElement = document.getElementById('root');
Expand Down

0 comments on commit 9d8ff15

Please sign in to comment.