Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
songkg7 committed Jul 5, 2024
1 parent 9ca1801 commit 2ac8a0d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 82 deletions.
41 changes: 0 additions & 41 deletions src/ResourceLinkConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,6 @@ import { ObsidianRegex } from './core/ObsidianRegex';
import { Notice } from 'obsidian';
import { Converter } from './core/Converter';
import { removeTempPrefix } from './FilenameConverter';
import O2Plugin from './main';

export const convertJekyllResourceLink = (
input: string,
fileName: string,
absolutePath: string,
plugin: O2Plugin,
) => {
const resourcePath = `${plugin.jekyll.resourcePath}/${fileName}`;
const resourceNames = extractResourceNames(input);
if (!(resourceNames === undefined || resourceNames.length === 0)) {
fs.mkdirSync(resourcePath, { recursive: true });
}
resourceNames?.forEach((resourceName) => {
fs.copyFile(
`${absolutePath}/${plugin.obsidianPathSettings.attachmentsFolder}/${resourceName}`,
`${resourcePath}/${(resourceName.replace(/\s/g, '-'))}`,
(err) => {
if (err) {
// ignore error
console.error(err);
new Notice(err.message);
}
},
);
});

const replacer = (match: string,
contents: string,
suffix: string,
width: string | undefined,
height: string | undefined,
space: string | undefined,
caption: string | undefined) =>
`![image](/${plugin.jekyll.jekyllRelativeResourcePath}/${fileName}/${contents.replace(/\s/g, '-')}.${suffix})`
+ `${convertImageSize(width, height)}`
+ `${convertImageCaption(caption)}`;

return input.replace(ObsidianRegex.ATTACHMENT_LINK, replacer);
};


export class ResourceLinkConverter implements Converter {
private readonly fileName: string;
Expand Down
44 changes: 3 additions & 41 deletions src/jekyll/chirpy.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,17 @@
import O2Plugin from '../main';
import { WikiLinkConverter } from '../WikiLinkConverter';
import { convertJekyllResourceLink, ResourceLinkConverter } from '../ResourceLinkConverter';
import { ResourceLinkConverter } from '../ResourceLinkConverter';
import { Notice } from 'obsidian';
import { CalloutConverter } from '../CalloutConverter';
import { convertFrontMatter, FrontMatterConverter } from '../FrontMatterConverter';
import { FrontMatterConverter } from '../FrontMatterConverter';
import { copyMarkdownFile, moveFiles, vaultAbsolutePath } from '../utils';
import { FootnotesConverter } from '../FootnotesConverter';
import { ConverterChain } from '../core/ConverterChain';
import { CommentsConverter } from '../CommentsConverter';
import { EmbedsConverter } from '../EmbedsConverter';
import { convertCurlyBrace, CurlyBraceConverter } from '../CurlyBraceConverter';
import { CurlyBraceConverter } from '../CurlyBraceConverter';
import JekyllSettings from './settings/JekyllSettings';
import { convertFileName } from '../FilenameConverter';
import { Contents } from '../core/Converter';

// WIP
// TODO: implement this function
export const convertToChirpyV2 = async (plugin: O2Plugin) => {
const settings = plugin.jekyll as JekyllSettings;
const markdownFiles = await copyMarkdownFile(plugin);
for (const file of markdownFiles) {
const fileName = convertFileName(file.name);
const contents: Contents = await plugin.app.vault.read(file);

const result =
convertCurlyBrace(
settings.isEnableCurlyBraceConvertMode,
convertFrontMatter(
convertJekyllResourceLink(
contents,
fileName,
vaultAbsolutePath(plugin),
plugin
),
),
);

await plugin.app.vault.modify(file, result)
.then(() => {
new Notice('Converted to Chirpy successfully.', 5000);
});

// move files to chirpy folder
await moveFiles(
`${vaultAbsolutePath(plugin)}/${plugin.obsidianPathSettings.readyFolder}`,
settings.targetPath(),
settings.pathReplacer,
)
.then(() => new Notice('Moved files to Chirpy successfully.', 5000));
}
};

export async function convertToChirpy(plugin: O2Plugin) {
const settings = plugin.jekyll as JekyllSettings;
Expand Down

0 comments on commit 2ac8a0d

Please sign in to comment.