feat(techdocs): Add support for mkdocs material palette conditional hashes (#26821)

Signed-off-by: Adrian Kosinski <adrian.kosinski@allegro.com>
This commit is contained in:
Adrian Kosiński
2024-10-01 21:53:24 +02:00
committed by GitHub
parent fbdc63116c
commit e918061043
4 changed files with 48 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs': patch
---
Add support for mkdocs material palette conditional hashes.
@@ -0,0 +1,38 @@
/*
* Copyright 2024 The Backstage Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { RuleOptions } from './types';
import { Theme } from '@material-ui/core/styles';
const themeHashes: Record<Theme['palette']['type'], ReadonlyArray<string>> = {
dark: ['#only-light', '#gh-light-mode-only'],
light: ['#only-dark', '#gh-dark-mode-only'],
};
export default ({ theme }: RuleOptions) => `
/*================== Palette ==================*/
/*
When color palette toggle is enabled in material theme for Mkdocs, there is a possibility to show conditionally
images by adding #only-dark or #only-light to resource hash. Backstage doesn't use mkdocs color palette mechanism,
so there is a need to add css rules from palette*.css manually.
*/
${themeHashes[theme.palette.type]
.map(hash => `img[src$="${hash}"]`)
.join(', ')} {
display: none;
}
`;
@@ -20,6 +20,7 @@ import { default as layout } from './layout';
import { default as typeset } from './typeset';
import { default as animations } from './animations';
import { default as extensions } from './extensions';
import palette from './palette';
/**
* A list of style rules that will be applied to an element in the order they were added.
@@ -35,4 +36,5 @@ export const rules = [
typeset,
animations,
extensions,
palette,
];
@@ -47,6 +47,9 @@ describe('Transformers > Styles', () => {
expect(style).toHaveTextContent(
'/*================== Extensions ==================*/',
);
expect(style).toHaveTextContent(
'/*================== Palette ==================*/',
);
});
it('should use headers relative font-size value as the factor for the md-typeset variable', () => {