Skip to content
This repository has been archived by the owner on Apr 24, 2023. It is now read-only.

Commit

Permalink
feat(theme): add compact for deprecated options
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 31, 2022
1 parent 1d66e6c commit 5309995
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/theme/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,39 @@ const defaultThemeConfig: HopeThemeConfig = {
editLinks: true,
};

const convertThemeConfig = (
themeConfig: HopeThemeConfig & Record<string, unknown>
): void => {
// FIXME: Compact Code
[
// v1 options
["namedChunk", "chunkRename"],
["addthis", "addThis"],
["markdown", "mdEnhance"],
["lastUpdatedTransformer", "lastUpdate"],
].forEach(([oldOptions, newOptions]) => {
if (oldOptions in themeConfig) {
console.warn(
`"${oldOptions}" is deprecated, you should use "${newOptions}" instead.`
);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line
options[newOptions] = options[oldOptions];
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
// eslint-disable-next-line
delete options[oldOptions];
}
});
};

export const resolveThemeConfig = (
themeConfig: HopeThemeConfig,
context: Context
): ResolvedHopeThemeConfig => {
convertThemeConfig(themeConfig as HopeThemeConfig & Record<string, unknown>);

// merge default themeConfig
deepAssignReverse(defaultThemeConfig, themeConfig);

Expand Down

0 comments on commit 5309995

Please sign in to comment.