validate_config.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. module.exports = ctx => {
  3. const { config, log } = ctx;
  4. log.info('Validating config');
  5. // Validation for config.url && config.root
  6. if (typeof config.url !== 'string') {
  7. throw new TypeError(`Invalid config detected: "url" should be string, not ${typeof config.url}!`);
  8. }
  9. try {
  10. // eslint-disable-next-line no-new
  11. new URL(config.url);
  12. } catch {
  13. throw new TypeError('Invalid config detected: "url" should be a valid URL!');
  14. }
  15. if (typeof config.root !== 'string') {
  16. throw new TypeError(`Invalid config detected: "root" should be string, not ${typeof config.root}!`);
  17. }
  18. if (config.root.trim().length <= 0) {
  19. throw new TypeError('Invalid config detected: "root" should not be empty!');
  20. }
  21. // Soft deprecate use_date_for_updated
  22. if (typeof config.use_date_for_updated === 'boolean') {
  23. log.warn('Deprecated config detected: "use_date_for_updated" is deprecated, please use "updated_option" instead. See https://hexo.io/docs/configuration for more details.');
  24. }
  25. // Soft deprecate external_link Boolean
  26. if (typeof config.external_link === 'boolean') {
  27. log.warn('Deprecated config detected: "external_link" with a Boolean value is deprecated. See https://hexo.io/docs/configuration for more details.');
  28. }
  29. };