Update patchMkdocsYmlPreBuild

Update the `patchMkdocsYmlPreBuild` function to modify `repo_url` and
`edit_uri` independently of each other. Prior to this change both
`repo_url` and `edit_uri` would have to be missing for either to be
generated which caused an issue in the situation where `repo_url`
is provided in the mkdocs.yml and `edit_uri` is not because the default
`edit_uri` value from mkdocs would be used instead. This value uses `master` as
the branch in the link which breaks the edit link for repos that don't use
`master` as the default branch.

Signed-off-by: Isabel Tomb <isabelgtomb@gmail.com>
This commit is contained in:
Isabel Tomb
2024-07-08 13:03:39 -05:00
parent 8711fa8004
commit 949083ddb4
2 changed files with 8 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-techdocs-node': patch
---
Update `patchMkdocsYmlPrebuild` to modify `repo_url` and `edit_uri` independently.
@@ -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(