saberland/saber

Do you want to work on this issue?

You can request for a bounty in order to promote it!

Allow plugin to modify siteConfig and themeConfig #508

egoist posted onGitHub

<!-- Please don't delete this template or we'll close your issue -->

<!-- Before creating an issue please make sure you are using the latest version of Saber. -->

Feature request

<!-- Please ask questions via following several ways. -->

<!-- https://chat.saber.land/ -->

<!-- https://stackoverflow.com/questions/ask?tags=saberjs -->

What problem does this feature solve?

Plugins should be able to set default value for siteConfig, and probably themeConfig.

e.g. You create a plugin to fetch siteConfig from headless CMS, but you also want the user to be able to override siteConfig via saber-config.yml.

What does the proposed API look like?

A plugin:

exports.name = 'my-plugin-name'

exports.apply = api => {
  api.hooks.getSaberConfig.tapPromise('my-plugin-name', async config => {
    config.siteConfig = merge(await getSiteConfigFromApi(), config.siteConfig)
    return config
  })
}

How should this be implemented in your opinion?

Call the getSaberConfig hook before calling afterPlugins hook:

https://github.com/saberland/saber/blob/83c18a706637fedccdbe0ad34566218dc5780d94/packages/saber/lib/index.js#L185

And call it again when config file is modified:

https://github.com/saberland/saber/blob/83c18a706637fedccdbe0ad34566218dc5780d94/packages/saber/lib/plugins/watch-config.js#L58


Fund this Issue

$0.00
Funded
Only logged in users can fund an issue

Pull requests