Skip to content

Commit

Permalink
feat(project): get site metadata from config
Browse files Browse the repository at this point in the history
  • Loading branch information
royschut committed Jun 8, 2021
1 parent 16b134c commit df7ba35
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/providers/ConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const ConfigProvider: FunctionComponent<ProviderProps> = ({
validateConfig(config)
.then((configValidated) => {
setConfig(() => merge({}, defaultConfig, configValidated));
setSiteMetadata(configValidated);
setCssVariables(configValidated.options);
onLoading(false);
setLoading(false);
Expand All @@ -58,6 +59,17 @@ const ConfigProvider: FunctionComponent<ProviderProps> = ({
loadAndValidateConfig(configLocation);
}, [configLocation, onLoading, onValidationError]);

const setSiteMetadata = ({ siteName, description }: Config) => {
if (siteName) document.title = siteName;
if (description) {
const meta = document.getElementsByTagName('meta');
for (let i = 0; i < meta.length; i++) {
if (meta[i].name.toLowerCase() === 'description') {
meta[i].content = description;
}
}
}
};
const setCssVariables = ({ backgroundColor, highlightColor, headerBackground }: Options) => {
const root = document.querySelector(':root') as HTMLElement;

Expand Down

0 comments on commit df7ba35

Please sign in to comment.