Skip to content

Commit

Permalink
maybe will work
Browse files Browse the repository at this point in the history
  • Loading branch information
meff34 committed Apr 7, 2019
1 parent 8ef461a commit 57ab3a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/beautify-image-paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ const path = require("path");
const markdownLinkExtractor = require("markdown-link-extractor");
const isUrl = require("is-url");

module.exports = (content, filePath) => {
const isImg = filePath => {
const extName = path.parse(filePath).ext;

return extName === ".jpg" || extName === ".png" || extName === ".gif";
};

module.exports = ({ pathToStatic }) => (content, filePath) => {
let markdown = content;
const dir = path.dirname(filePath);
const static = path.resolve(process.cwd(), pathToStatic);

markdownLinkExtractor(content)
.filter(link => !isUrl(link))
.filter(isImg)
.map(link => ({ origin: link, processed: path.resolve(dir, link) }))
.map(({ origin, processed }) => ({
origin,
processed: path.relative(process.cwd(), processed),
processed: path.relative(static, processed),
}))
.forEach(({ origin, processed }) => {
markdown = markdown.replace(origin, processed);
Expand Down
2 changes: 1 addition & 1 deletion src/markdown-combine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const combineMarkdowns = ({ contents, pathToStatic, mainMdFilename }) => async l

try {
const content = files
.map(({ content, name }) => beautifyImages(content, name))
.map(({ content, name }) => beautifyImages({ pathToStatic })(content, name))
.join("\n\n\n\n");
await writeFile(resultFilePath, content);
} catch (e) {
Expand Down

0 comments on commit 57ab3a6

Please sign in to comment.