mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-05 13:17:23 +02:00
feat(v2): allow to use array of files in customCss field (#3474)
* feat(v2): allow to use array of files in customCss field * customCss array: - fix bug (push instead of concat) - update docs - add theme config validation + tests Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
cc31567459
commit
ae2c063929
8 changed files with 53 additions and 7 deletions
|
@ -15,6 +15,13 @@ function testValidateThemeConfig(themeConfig) {
|
||||||
return normalizeThemeConfig(ThemeConfigSchema, themeConfig);
|
return normalizeThemeConfig(ThemeConfigSchema, themeConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testOk(partialConfig) {
|
||||||
|
expect(testValidateThemeConfig(partialConfig)).toEqual({
|
||||||
|
...DEFAULT_CONFIG,
|
||||||
|
...partialConfig,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
describe('themeConfig', () => {
|
describe('themeConfig', () => {
|
||||||
test('should accept valid theme config', () => {
|
test('should accept valid theme config', () => {
|
||||||
const userConfig = {
|
const userConfig = {
|
||||||
|
@ -110,6 +117,36 @@ describe('themeConfig', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe.only('customCss config', () => {
|
||||||
|
test('should accept customCss undefined', () => {
|
||||||
|
testOk({
|
||||||
|
customCss: undefined,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should accept customCss string', () => {
|
||||||
|
testOk({
|
||||||
|
customCss: './path/to/cssFile.css',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should accept customCss string array', () => {
|
||||||
|
testOk({
|
||||||
|
customCss: ['./path/to/cssFile.css', './path/to/cssFile2.css'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should reject customCss number', () => {
|
||||||
|
expect(() =>
|
||||||
|
testValidateThemeConfig({
|
||||||
|
customCss: 42,
|
||||||
|
}),
|
||||||
|
).toThrowErrorMatchingInlineSnapshot(
|
||||||
|
`"\\"customCss\\" must be one of [array, string]"`,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('color mode config', () => {
|
describe('color mode config', () => {
|
||||||
const withDefaultValues = (colorMode) =>
|
const withDefaultValues = (colorMode) =>
|
||||||
merge({}, DEFAULT_CONFIG.colorMode, colorMode);
|
merge({}, DEFAULT_CONFIG.colorMode, colorMode);
|
||||||
|
|
|
@ -83,8 +83,12 @@ module.exports = function (context, options) {
|
||||||
];
|
];
|
||||||
|
|
||||||
if (customCss) {
|
if (customCss) {
|
||||||
|
if (Array.isArray(customCss)) {
|
||||||
|
modules.push(...customCss);
|
||||||
|
} else {
|
||||||
modules.push(customCss);
|
modules.push(customCss);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return modules;
|
return modules;
|
||||||
},
|
},
|
||||||
|
|
|
@ -165,6 +165,10 @@ const FooterLinkItemSchema = Joi.object({
|
||||||
// (users may need additional attributes like target, aria-role, data-customAttribute...)
|
// (users may need additional attributes like target, aria-role, data-customAttribute...)
|
||||||
.unknown();
|
.unknown();
|
||||||
|
|
||||||
|
const CustomCssSchema = Joi.alternatives()
|
||||||
|
.try(Joi.array().items(Joi.string().required()), Joi.string().required())
|
||||||
|
.optional();
|
||||||
|
|
||||||
const ThemeConfigSchema = Joi.object({
|
const ThemeConfigSchema = Joi.object({
|
||||||
// TODO temporary (@alpha-58)
|
// TODO temporary (@alpha-58)
|
||||||
disableDarkMode: Joi.any().forbidden(false).messages({
|
disableDarkMode: Joi.any().forbidden(false).messages({
|
||||||
|
@ -176,6 +180,7 @@ const ThemeConfigSchema = Joi.object({
|
||||||
'any.unknown':
|
'any.unknown':
|
||||||
'defaultDarkMode theme config is deprecated. Please use the new colorMode attribute. You likely want: config.themeConfig.colorMode.defaultMode = "dark"',
|
'defaultDarkMode theme config is deprecated. Please use the new colorMode attribute. You likely want: config.themeConfig.colorMode.defaultMode = "dark"',
|
||||||
}),
|
}),
|
||||||
|
customCss: CustomCssSchema,
|
||||||
colorMode: ColorModeSchema,
|
colorMode: ColorModeSchema,
|
||||||
image: Joi.string(),
|
image: Joi.string(),
|
||||||
metadatas: Joi.array()
|
metadatas: Joi.array()
|
||||||
|
|
|
@ -95,7 +95,7 @@ module.exports = {
|
||||||
sidebarPath: require.resolve('./sidebars.js'),
|
sidebarPath: require.resolve('./sidebars.js'),
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.css'),
|
customCss: [require.resolve('./src/css/custom.css')],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -220,7 +220,7 @@ module.exports = {
|
||||||
'@docusaurus/preset-classic',
|
'@docusaurus/preset-classic',
|
||||||
{
|
{
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.css'),
|
customCss: [require.resolve('./src/css/custom.css')],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
@ -97,7 +97,7 @@ module.exports = {
|
||||||
debug: undefined,
|
debug: undefined,
|
||||||
// Will be passed to @docusaurus/theme-classic.
|
// Will be passed to @docusaurus/theme-classic.
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.css'),
|
customCss: [require.resolve('./src/css/custom.css')],
|
||||||
},
|
},
|
||||||
// Will be passed to @docusaurus/plugin-content-docs (false to disable)
|
// Will be passed to @docusaurus/plugin-content-docs (false to disable)
|
||||||
docs: {},
|
docs: {},
|
||||||
|
|
|
@ -19,7 +19,7 @@ module.exports = {
|
||||||
{
|
{
|
||||||
// highlight-start
|
// highlight-start
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.css'),
|
customCss: [require.resolve('./src/css/custom.css')],
|
||||||
},
|
},
|
||||||
// highlight-end
|
// highlight-end
|
||||||
},
|
},
|
||||||
|
@ -164,7 +164,7 @@ module.exports = {
|
||||||
{
|
{
|
||||||
// ...
|
// ...
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.scss'),
|
customCss: [require.resolve('./src/css/custom.scss')],
|
||||||
},
|
},
|
||||||
// ...
|
// ...
|
||||||
},
|
},
|
||||||
|
|
|
@ -207,7 +207,7 @@ module.exports = {
|
||||||
remarkPlugins: [require('./src/plugins/remark-npm2yarn')],
|
remarkPlugins: [require('./src/plugins/remark-npm2yarn')],
|
||||||
},
|
},
|
||||||
theme: {
|
theme: {
|
||||||
customCss: require.resolve('./src/css/custom.css'),
|
customCss: [require.resolve('./src/css/custom.css')],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
Loading…
Add table
Reference in a new issue