fix(publish-docs): images need to stay images when adjusting links

This commit is contained in:
Thomas Allmer 2021-03-23 07:57:07 +01:00 committed by Thomas Allmer
parent bcdd0710ef
commit b1cd3735b4
5 changed files with 23 additions and 7 deletions

View file

@ -0,0 +1,5 @@
---
'publish-docs': patch
---
Images need to stay images when adjusting links

View file

@ -48,7 +48,8 @@ function rewriteLinksInMdContent(mdContent, filePath, { gitHubUrl, gitRootDir })
* @param {string} title
* @param {string} text
*/
const mdLink = (href, title, text) => `[${text}](${rewrite(href)}${title ? ` ${title}` : ''})`;
const mdLink = (href, title, text) =>
`[${text}](${rewrite(href)}${title ? ` ${title.trim()}` : ''})`;
/** @type {string[]} */
const resultLinks = [];
@ -61,6 +62,10 @@ function rewriteLinksInMdContent(mdContent, filePath, { gitHubUrl, gitRootDir })
const parts = link.match(new RegExp(linkPattern));
if (parts) {
newLink = mdLink(parts[2], parts[3], parts[1]);
if (parts[0][0] === '!') {
// is an image
newLink = `!${newLink}`;
}
}
resultLinks.push(newLink);
});
@ -134,12 +139,6 @@ export class PublishDocs {
await fs.promises.mkdir(targetDir, { recursive: true });
}
await fs.copy(sourceDir, targetDir);
// const assets = await listFiles(this.options.copyDir, this.options.gitRootDir);
// for (const asset of assets) {
// await fs.promises.mkdir(targetDir, { recursive: true });
// await fs.promises.copyFile(asset, path.join(targetDir, path.basename(asset)));
// }
}
async execute() {

View file

@ -60,6 +60,15 @@ describe('PublishDocs', () => {
'Dos not touch [external](https://google.com) links.',
].join(EOL),
);
const details = await readOutput('docs/details.md');
expect(details).to.equal(
[
'# details.md',
'',
`![Some Image](https://github.com/ing-bank/lion/blob/1234/docs/red/assets/image.svg 'the title')`,
].join(EOL),
);
delete process.env.GITHUB_SHA;
});

View file

@ -1 +1,3 @@
# details.md
![Some Image](./assets/image.svg 'the title')