Merge pull request #25549 from isabeltomb/update-patch-mkdocs

Update mkdocs pre-build patching
This commit is contained in:
Sydney Achinger
2024-07-24 14:41:05 -04:00
committed by GitHub
3 changed files with 34 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-node': patch
---
Update `patchMkdocsYmlPrebuild` to modify `repo_url` and `edit_uri` independently.
@@ -295,7 +295,32 @@ describe('helpers', () => {
'edit_uri: https://github.com/backstage/backstage/edit/main/docs',
);
expect(updatedMkdocsYml.toString()).not.toContain(
'https://github.com/neworg/newrepo',
'edit_uri: https://github.com/neworg/newrepo',
);
});
it('should add edit_uri to mkdocs.yml with existing repo_url', async () => {
const parsedLocationAnnotation: ParsedLocationAnnotation = {
type: 'url',
target: 'https://github.com/neworg/newrepo/tree/main/',
};
await patchMkdocsYmlPreBuild(
mockDir.resolve('mkdocs_with_repo_url.yml'),
mockLogger,
parsedLocationAnnotation,
scmIntegrations,
);
const updatedMkdocsYml = await fs.readFile(
mockDir.resolve('mkdocs_with_repo_url.yml'),
);
expect(updatedMkdocsYml.toString()).toContain(
'edit_uri: https://github.com/neworg/newrepo/edit/main/docs',
);
expect(updatedMkdocsYml.toString()).toContain(
'repo_url: https://github.com/backstage/backstage',
);
});
@@ -108,7 +108,7 @@ export const patchMkdocsYmlPreBuild = async (
scmIntegrations: ScmIntegrationRegistry,
) => {
await patchMkdocsFile(mkdocsYmlPath, logger, mkdocsYml => {
if (!('repo_url' in mkdocsYml) && !('edit_uri' in mkdocsYml)) {
if (!('repo_url' in mkdocsYml) || !('edit_uri' in mkdocsYml)) {
// Add edit_uri and/or repo_url to mkdocs.yml if it is missing.
// This will enable the Page edit button generated by MkDocs.
// If the either has been set, keep the original value
@@ -119,8 +119,8 @@ export const patchMkdocsYmlPreBuild = async (
);
if (result.repo_url || result.edit_uri) {
mkdocsYml.repo_url = result.repo_url;
mkdocsYml.edit_uri = result.edit_uri;
mkdocsYml.repo_url = mkdocsYml.repo_url || result.repo_url;
mkdocsYml.edit_uri = mkdocsYml.edit_uri || result.edit_uri;
logger.info(
`Set ${JSON.stringify(