fix(publish-docs): images need to stay images when adjusting links
This commit is contained in:
parent
bcdd0710ef
commit
b1cd3735b4
5 changed files with 23 additions and 7 deletions
5
.changeset/tall-walls-marry.md
Normal file
5
.changeset/tall-walls-marry.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'publish-docs': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Images need to stay images when adjusting links
|
||||||
|
|
@ -48,7 +48,8 @@ function rewriteLinksInMdContent(mdContent, filePath, { gitHubUrl, gitRootDir })
|
||||||
* @param {string} title
|
* @param {string} title
|
||||||
* @param {string} text
|
* @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[]} */
|
/** @type {string[]} */
|
||||||
const resultLinks = [];
|
const resultLinks = [];
|
||||||
|
|
@ -61,6 +62,10 @@ function rewriteLinksInMdContent(mdContent, filePath, { gitHubUrl, gitRootDir })
|
||||||
const parts = link.match(new RegExp(linkPattern));
|
const parts = link.match(new RegExp(linkPattern));
|
||||||
if (parts) {
|
if (parts) {
|
||||||
newLink = mdLink(parts[2], parts[3], parts[1]);
|
newLink = mdLink(parts[2], parts[3], parts[1]);
|
||||||
|
if (parts[0][0] === '!') {
|
||||||
|
// is an image
|
||||||
|
newLink = `!${newLink}`;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resultLinks.push(newLink);
|
resultLinks.push(newLink);
|
||||||
});
|
});
|
||||||
|
|
@ -134,12 +139,6 @@ export class PublishDocs {
|
||||||
await fs.promises.mkdir(targetDir, { recursive: true });
|
await fs.promises.mkdir(targetDir, { recursive: true });
|
||||||
}
|
}
|
||||||
await fs.copy(sourceDir, targetDir);
|
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() {
|
async execute() {
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,15 @@ describe('PublishDocs', () => {
|
||||||
'Dos not touch [external](https://google.com) links.',
|
'Dos not touch [external](https://google.com) links.',
|
||||||
].join(EOL),
|
].join(EOL),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const details = await readOutput('docs/details.md');
|
||||||
|
expect(details).to.equal(
|
||||||
|
[
|
||||||
|
'# details.md',
|
||||||
|
'',
|
||||||
|
``,
|
||||||
|
].join(EOL),
|
||||||
|
);
|
||||||
delete process.env.GITHUB_SHA;
|
delete process.env.GITHUB_SHA;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
|
||||||
|
|
@ -1 +1,3 @@
|
||||||
# details.md
|
# details.md
|
||||||
|
|
||||||
|

|
||||||
|
|
|
||||||
Loading…
Reference in a new issue