Skip to content

Commit

Permalink
fix: o2-53 create folder in assets/img without resource (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
songkg7 authored Mar 9, 2023
1 parent d8e6b12 commit 3d79ff0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/jekyll/ResourceLinkConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ export class ResourceLinkConverter extends AbstractConverter {
convert(input: string): string {
const jekyllSetting = this.plugin.settings.jekyllSetting();
const resourcePath = `${jekyllSetting.resourcePath()}/${this.title}`;
fs.mkdirSync(resourcePath, { recursive: true });

const relativeResourcePath = jekyllSetting.jekyllRelativeResourcePath;

extractImageName(input)?.forEach((resourceName) => {
const resourceNames = extractResourceNames(input);
if (!(resourceNames === undefined || resourceNames.length === 0)) {
fs.mkdirSync(resourcePath, { recursive: true });
}
resourceNames?.forEach((resourceName) => {
fs.copyFile(
`${(vaultAbsolutePath(this.plugin))}/${jekyllSetting.attachmentsFolder}/${resourceName}`,
`${resourcePath}/${(resourceName.replace(/\s/g, '-'))}`,
Expand All @@ -36,6 +37,7 @@ export class ResourceLinkConverter extends AbstractConverter {
);
});

const relativeResourcePath = jekyllSetting.jekyllRelativeResourcePath;
const replacer = (match: string, p1: string) =>
`![image](/${relativeResourcePath}/${this.title}/${p1.replace(/\s/g, '-')})`;

Expand All @@ -45,7 +47,7 @@ export class ResourceLinkConverter extends AbstractConverter {
}
}

export function extractImageName(content: string) {
export function extractResourceNames(content: string) {
const regExpMatchArray = content.match(ObsidianRegex.IMAGE_LINK);
return regExpMatchArray?.map(
(value) => {
Expand Down
4 changes: 2 additions & 2 deletions src/tests/ResourceLinkConverter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { extractImageName } from "../jekyll/ResourceLinkConverter";
import { extractResourceNames } from "../jekyll/ResourceLinkConverter";

jest.mock('obsidian', () => ({}), { virtual: true });

Expand All @@ -10,7 +10,7 @@ describe("extract image name", () => {
test
![[image.png]]
`;
const result = extractImageName(context);
const result = extractResourceNames(context);
expect(result).toEqual(['test.png', 'image.png']);
});

Expand Down

0 comments on commit 3d79ff0

Please sign in to comment.