Skip to content

Commit

Permalink
fix(docs) use doc link titles as link text in case they are available…
Browse files Browse the repository at this point in the history
… from the object.inv.txt content

Signed-off-by: David Edler <david.edler@canonical.com>
  • Loading branch information
edlerd committed Jun 5, 2024
1 parent 0e5e934 commit 29c9a3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/util/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe("toConfigFields and replaceDocLinks", () => {
);

expect(result).toBe(
'Specify a Pongo2 template string that represents the snapshot name.<br>This template is used for scheduled snapshots and for unnamed snapshots.<br><br>See <a href="https://docs.example.org/reference/instance_options/#instance-options-snapshots-names" target="_blank" rel="noopener noreferrer">instance options snapshots names</a> for more information.',
'Specify a Pongo2 template string that represents the snapshot name.<br>This template is used for scheduled snapshots and for unnamed snapshots.<br><br>See <a href="https://docs.example.org/reference/instance_options/#instance-options-snapshots-names" target="_blank" rel="noopener noreferrer">Automatic snapshot names</a> for more information.',
);
});

Expand Down
8 changes: 7 additions & 1 deletion src/util/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export const configDescriptionToHtml = (
return;
}
const docPath = line.split(": ")[1];
const linkText = token.replaceAll("-", " ");
const linkTextCandidate = line
.split(":")[0]
.replace(/\s\s+/g, " ")
.trim();
const linkText = linkTextCandidate.includes(" ") // some lines in the object.inv.txt file have a description before the : and a link after
? linkTextCandidate.substring(linkTextCandidate.indexOf(" ") + 1)
: token.replaceAll("-", " ");
const link = `<a href="${docBaseLink}/${docPath}" target="_blank" rel="noopener noreferrer">${linkText}</a>`;

result = result.replaceAll(tag, link);
Expand Down

0 comments on commit 29c9a3e

Please sign in to comment.