Code Cleanup & Making code more readable

This commit is contained in:
Hasin Hayder
2022-07-18 01:19:07 +06:00
parent f4a1fff90f
commit 4edef5df4b

View File

@@ -69,7 +69,7 @@ export const ga = {
// log specific events happening // log specific events happening
event: ({ action, params }) => { event: ({ action, params }) => {
try { try {
typeof window !== 'undefined' && window.gtag('event', action, params); window?.gtag('event', action, params);
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@@ -77,36 +77,21 @@ export const ga = {
}; };
export const isThemeDarkish = (theme) => { export const isThemeDarkish = (theme) => {
if ( return ['dark', 'halloween', 'forest', 'black', 'luxury', 'dracula'].includes(
theme === 'dark' || theme
theme === 'halloween' || );
theme === 'forest' ||
theme === 'black' ||
theme === 'luxury' ||
theme === 'dracula'
) {
return true;
} else {
return false;
}
}; };
export const setupHotjar = (hotjarConfig) => { export const setupHotjar = (hotjarConfig) => {
if (hotjarConfig?.id) { if (hotjarConfig?.id) {
let snippetVersion = hotjarConfig?.snippetVersion let snippetVersion = hotjarConfig?.snippetVersion || 6;
? hotjarConfig?.snippetVersion
: 6;
hotjar.initialize(hotjarConfig.id, snippetVersion); hotjar.initialize(hotjarConfig.id, snippetVersion);
} }
}; };
export const sanitizeConfig = (config) => { export const sanitizeConfig = (config) => {
const customTheme = const customTheme = config?.themeConfig?.customTheme || {
typeof config.themeConfig !== 'undefined' &&
typeof config.themeConfig.customTheme !== 'undefined'
? config.themeConfig.customTheme
: {
primary: '#fc055b', primary: '#fc055b',
secondary: '#219aaf', secondary: '#219aaf',
accent: '#e8d03a', accent: '#e8d03a',
@@ -116,11 +101,7 @@ export const sanitizeConfig = (config) => {
'--rounded-btn': '3rem', '--rounded-btn': '3rem',
}; };
const themes = const themes = config?.themeConfig?.themes || [
typeof config.themeConfig !== 'undefined' &&
typeof config.themeConfig.themes !== 'undefined'
? config.themeConfig.themes
: [
'light', 'light',
'dark', 'dark',
'cupcake', 'cupcake',
@@ -156,138 +137,45 @@ export const sanitizeConfig = (config) => {
return { return {
github: { github: {
username: config.github.username, username: config.github.username,
sortBy: sortBy: config.github.sortBy || 'stars',
typeof config.github.sortBy !== 'undefined' limit: config.github.limit || 8,
? config.github.sortBy
: 'stars',
limit:
typeof config.github.limit !== 'undefined' ? config.github.limit : 8,
exclude: { exclude: {
forks: forks: config?.github?.exclude?.forks,
typeof config.github.exclude !== 'undefined' && projects: config?.github?.exclude?.projects || [],
typeof config.github.exclude.forks !== 'undefined'
? config.github.exclude.forks
: false,
projects:
typeof config.github.exclude !== 'undefined' &&
typeof config.github.exclude.projects !== 'undefined'
? config.github.exclude.projects
: [],
}, },
}, },
social: { social: {
linkedin: linkedin: config?.social?.twitter,
typeof config.social !== 'undefined' && twitter: config?.social?.twitter,
typeof config.social.linkedin !== 'undefined' facebook: config?.social?.facebook,
? config.social.linkedin instagram: config?.social?.instagram,
: '', dribbble: config?.social?.dribble,
twitter: behance: config?.social?.behance,
typeof config.social !== 'undefined' && medium: config?.social?.medium,
typeof config.social.twitter !== 'undefined' dev: config?.social?.dev,
? config.social.twitter website: config?.social?.website,
: '', phone: config?.social?.phone,
facebook: email: config?.social?.email,
typeof config.social !== 'undefined' &&
typeof config.social.facebook !== 'undefined'
? config.social.facebook
: '',
instagram:
typeof config.social !== 'undefined' &&
typeof config.social.instagram !== 'undefined'
? config.social.instagram
: '',
dribbble:
typeof config.social !== 'undefined' &&
typeof config.social.dribbble !== 'undefined'
? config.social.dribbble
: '',
behance:
typeof config.social !== 'undefined' &&
typeof config.social.behance !== 'undefined'
? config.social.behance
: '',
medium:
typeof config.social !== 'undefined' &&
typeof config.social.medium !== 'undefined'
? config.social.medium
: '',
dev:
typeof config.social !== 'undefined' &&
typeof config.social.dev !== 'undefined'
? config.social.dev
: '',
website:
typeof config.social !== 'undefined' &&
typeof config.social.website !== 'undefined'
? config.social.website
: '',
phone:
typeof config.social !== 'undefined' &&
typeof config.social.phone !== 'undefined'
? config.social.phone
: '',
email:
typeof config.social !== 'undefined' &&
typeof config.social.email !== 'undefined'
? config.social.email
: '',
}, },
skills: typeof config.skills !== 'undefined' ? config.skills : [], skills: config?.skills || [],
experiences: experiences: config?.experiences || [],
typeof config.experiences !== 'undefined' ? config.experiences : [], education: config?.education || [],
education: typeof config.education !== 'undefined' ? config.education : [],
blog: { blog: {
source: source: config?.blog?.source,
typeof config.blog !== 'undefined' && username: config?.blog?.username,
typeof config.blog.source !== 'undefined' limit: config?.blog?.limit || 5,
? config.blog.source
: '',
username:
typeof config.blog !== 'undefined' &&
typeof config.blog.username !== 'undefined'
? config.blog.username
: '',
limit:
typeof config.blog !== 'undefined' &&
typeof config.blog.limit !== 'undefined'
? config.blog.limit
: 5,
}, },
googleAnalytics: { googleAnalytics: {
id: id: config?.googleAnalytics?.id,
typeof config.googleAnalytics !== 'undefined' &&
typeof config.googleAnalytics.id !== 'undefined'
? config.googleAnalytics.id
: '',
}, },
hotjar: { hotjar: {
id: id: config?.hotjar?.id,
typeof config.hotjar !== 'undefined' && snippetVersion: config?.hotjar?.snippetVersion || 6,
typeof config.hotjar.id !== 'undefined'
? config.hotjar.id
: '',
snippetVersion:
typeof config.hotjar !== 'undefined' &&
typeof config.hotjar.snippetVersion !== 'undefined'
? config.hotjar.snippetVersion
: 6,
}, },
themeConfig: { themeConfig: {
defaultTheme: defaultTheme: config?.themeConfig?.defaultTheme || themes[0],
typeof config.themeConfig !== 'undefined' && disableSwitch: config?.themeConfig?.disableSwitch,
typeof config.themeConfig.defaultTheme !== 'undefined' respectPrefersColorScheme: config?.themeConfig?.respectPrefersColorScheme,
? config.themeConfig.defaultTheme
: themes[0],
disableSwitch:
typeof config.themeConfig !== 'undefined' &&
typeof config.themeConfig.disableSwitch !== 'undefined'
? config.themeConfig.disableSwitch
: false,
respectPrefersColorScheme:
typeof config.themeConfig !== 'undefined' &&
typeof config.themeConfig.respectPrefersColorScheme !== 'undefined'
? config.themeConfig.respectPrefersColorScheme
: false,
themes: themes, themes: themes,
customTheme: customTheme, customTheme: customTheme,
}, },