From 2ac8a0d153829a182b4c5535f59d0364d3849d60 Mon Sep 17 00:00:00 2001 From: haril Date: Fri, 5 Jul 2024 14:26:56 +0900 Subject: [PATCH] . --- src/ResourceLinkConverter.ts | 41 --------------------------------- src/jekyll/chirpy.ts | 44 +++--------------------------------- 2 files changed, 3 insertions(+), 82 deletions(-) diff --git a/src/ResourceLinkConverter.ts b/src/ResourceLinkConverter.ts index b925a84..5edb994 100644 --- a/src/ResourceLinkConverter.ts +++ b/src/ResourceLinkConverter.ts @@ -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; diff --git a/src/jekyll/chirpy.ts b/src/jekyll/chirpy.ts index 346a92d..bfd86ec 100644 --- a/src/jekyll/chirpy.ts +++ b/src/jekyll/chirpy.ts @@ -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;