update documentation and improve types
Signed-off-by: Karthik <karthik.jk11@gmail.com>
This commit is contained in:
@@ -491,8 +491,14 @@ docs_dir: docs
|
||||
theme:
|
||||
name: material
|
||||
font: false
|
||||
`,
|
||||
'mkdocs_with_theme_non_material.yml': `site_name: Test Site
|
||||
docs_dir: docs
|
||||
theme:
|
||||
name: test-theme
|
||||
`,
|
||||
});
|
||||
mockLogger.debug.mockClear();
|
||||
});
|
||||
|
||||
it('should create theme section with font disabled when no theme exists', async () => {
|
||||
@@ -562,6 +568,18 @@ theme:
|
||||
expect(parsedYml.theme?.name).toBe('material');
|
||||
expect(parsedYml.theme?.font).toBe(false);
|
||||
});
|
||||
|
||||
it('should not patch when theme name is not material', async () => {
|
||||
const fixturePath = mockDir.resolve('mkdocs_with_theme_non_material.yml');
|
||||
const before = await fs.readFile(fixturePath, 'utf8');
|
||||
|
||||
await patchMkdocsYmlWithFontDisabled(fixturePath, mockLogger);
|
||||
|
||||
await expect(fs.readFile(fixturePath, 'utf8')).resolves.toEqual(before);
|
||||
expect(mockLogger.debug).toHaveBeenCalledWith(
|
||||
'mkdocs.yml theme is not "material"; skipping font disabling patch',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('patchIndexPreBuild', () => {
|
||||
|
||||
@@ -27,15 +27,21 @@ import { LoggerService } from '@backstage/backend-plugin-api';
|
||||
|
||||
const MATERIAL_THEME = 'material';
|
||||
|
||||
type MkDocsThemeObject = {
|
||||
name?: string;
|
||||
font?: boolean;
|
||||
};
|
||||
|
||||
function isThemeObject(theme: unknown): theme is MkDocsThemeObject {
|
||||
return typeof theme === 'object' && theme !== null && !Array.isArray(theme);
|
||||
}
|
||||
|
||||
type MkDocsObject = {
|
||||
plugins?: string[];
|
||||
docs_dir: string;
|
||||
repo_url?: string;
|
||||
edit_uri?: string;
|
||||
theme?: {
|
||||
name?: string;
|
||||
font?: boolean;
|
||||
};
|
||||
theme?: MkDocsThemeObject;
|
||||
};
|
||||
|
||||
const patchMkdocsFile = async (
|
||||
@@ -210,25 +216,18 @@ export const patchMkdocsYmlWithFontDisabled = async (
|
||||
return true;
|
||||
}
|
||||
|
||||
// Theme section exists. Only modify it when the configured theme is Material
|
||||
if (
|
||||
mkdocsYml.theme &&
|
||||
typeof mkdocsYml.theme === 'object' &&
|
||||
(mkdocsYml.theme as any).name === MATERIAL_THEME &&
|
||||
!('font' in mkdocsYml.theme)
|
||||
) {
|
||||
mkdocsYml.theme.font = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (
|
||||
mkdocsYml.theme &&
|
||||
typeof mkdocsYml.theme === 'object' &&
|
||||
(mkdocsYml.theme as any).name !== MATERIAL_THEME
|
||||
) {
|
||||
logger.debug(
|
||||
'mkdocs.yml theme is not "material"; skipping font disabling patch',
|
||||
);
|
||||
const theme = mkdocsYml.theme;
|
||||
if (isThemeObject(theme)) {
|
||||
// Theme section exists. Only modify it when the configured theme is Material
|
||||
if (theme.name === MATERIAL_THEME && !('font' in theme)) {
|
||||
theme.font = false;
|
||||
return true;
|
||||
}
|
||||
if (theme.name !== MATERIAL_THEME) {
|
||||
logger.debug(
|
||||
'mkdocs.yml theme is not "material"; skipping font disabling patch',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user