MCPcopy
hub / github.com/webpro/reveal-md / copyAssetsAndWriteFile

Function copyAssetsAndWriteFile

lib/static.js:70–94  ·  view source on GitHub ↗
(sourceDir, file, targetDir)

Source from the content-addressed store, hash-verified

68};
69
70const copyAssetsAndWriteFile = async (sourceDir, file, targetDir) => {
71 const sourcePath = path.join(sourceDir, file);
72 const targetPath = path.join(targetDir, file).replace(/\.md$/, '.html');
73 const markdown = (await fs.readFile(sourcePath)).toString();
74 const awaits = await copyAssetsFromOptions(markdown);
75 const base = relativeDir(file, '.');
76 const markup = await renderFile(path.join(sourceDir, file), { base });
77
78 const markdownImages = markdown.matchAll(markdownImageRE);
79 const htmlImages = markdown.matchAll(htmlImageRE);
80 const backgroundImages = markdown.matchAll(markdownImageBackgroundRE);
81 const allImages = [...markdownImages, ...htmlImages, ...backgroundImages];
82
83 for (let image of allImages) {
84 const [, imgPath] = image;
85 if (!isAbsoluteURL(imgPath)) {
86 const relPath = path.join(path.dirname(file), imgPath);
87 awaits.push(cp(path.join(sourceDir, relPath), path.join(targetDir, relPath)).catch(err => console.warn(err)));
88 }
89 }
90
91 awaits.push(write(targetPath, markup));
92 awaits.push(featuredSlide(file, path.join(targetDir, path.dirname(file))));
93 return Promise.all(awaits);
94};
95
96const writeMarkupFiles = async (sourceDir, targetDir) => {
97 if (await isDirectory(sourceDir)) {

Callers 1

writeMarkupFilesFunction · 0.85

Calls 6

renderFileFunction · 0.90
isAbsoluteURLFunction · 0.90
copyAssetsFromOptionsFunction · 0.85
relativeDirFunction · 0.85
cpFunction · 0.85
writeFunction · 0.85

Tested by

no test coverage detected