Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update config settings and footer settings separately #81

Merged
merged 1 commit into from
Dec 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 39 additions & 23 deletions classes/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,19 +135,27 @@ class Settings {
const footerContent = footer.content
const navigationContent = navigation.content

const settingsObj = {
config: {
const settingsObj = {}

if (configSettings) {
settingsObj.config = {
payload: configSettings,
currentData: configContent,
},
footer: {
}
}

if (footerSettings) {
settingsObj.footer = {
payload: footerSettings,
currentData: footerContent,
},
navigation: {
}
}

if (navigationSettings) {
settingsObj.navigation = {
payload: navigationSettings,
currentData: navigationContent,
},
}
}

const updatedSettingsObjArr = Object.keys(settingsObj).map((settingsObjKey) => {
Expand All @@ -168,27 +176,35 @@ class Settings {

const { configSettingsObj, footerSettingsObj, navigationSettingsObj } = updatedSettingsObj

// update files
const newConfigContent = Base64.encode(yaml.safeDump(configSettingsObj))
const newFooterContent = Base64.encode(yaml.safeDump(footerSettingsObj))
const newNavigationContent = Base64.encode(yaml.safeDump(navigationSettingsObj))

// To-do: use Git Tree to speed up operations
await configResp.update(newConfigContent, config.sha)
await FooterFile.update(FOOTER_PATH, newFooterContent, footer.sha)
await NavigationFile.update(NAVIGATION_PATH, newNavigationContent, navigation.sha)
if (configSettings) {
const newConfigContent = Base64.encode(yaml.safeDump(configSettingsObj))
await configResp.update(newConfigContent, config.sha)

// Update title in homepage as well if it's changed
if (configContent.title !== configSettingsObj.title) {
const { content: homepageContentObj, sha } = homepage;

homepageContentObj.title = configSettings.title;
const homepageFrontMatter = yaml.safeDump(homepageContentObj);

// Update title in homepage as well if it's changed
if (configContent.title !== updatedSettingsObjArr[0].title) {
const { content: homepageContentObj, sha } = homepage;
homepageContentObj.title = configSettings.title;
const homepageFrontMatter = yaml.safeDump(homepageContentObj);
const homepageContent = ['---\n', homepageFrontMatter, '---'].join('') ;
const newHomepageContent = Base64.encode(homepageContent)

const homepageContent = ['---\n', homepageFrontMatter, '---'].join('') ;
const newHomepageContent = Base64.encode(homepageContent)
await HomepageFile.update(HOMEPAGE_INDEX_PATH, newHomepageContent, sha)
}
}

if (footerSettings) {
const newFooterContent = Base64.encode(yaml.safeDump(footerSettingsObj))
await FooterFile.update(FOOTER_PATH, newFooterContent, footer.sha)
}

await HomepageFile.update(HOMEPAGE_INDEX_PATH, newHomepageContent, sha)
if (navigationSettings) {
const newNavigationContent = Base64.encode(yaml.safeDump(navigationSettingsObj))
await NavigationFile.update(NAVIGATION_PATH, newNavigationContent, navigation.sha)
}

return
}
}
Expand Down