From fc04c093573d38b90fbb5e5bfd428c289a32521c Mon Sep 17 00:00:00 2001 From: haril song Date: Thu, 12 Dec 2024 11:36:47 +0900 Subject: [PATCH] draft --- package-lock.json | 2 +- src/ResourceLinkConverter.ts | 11 ++++++++++- src/jekyll/chirpy.ts | 5 +++++ src/settings.ts | 12 ++++++++---- src/tests/ResourceLinkConverter.test.ts | 18 ++++++++++++++++++ 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 970a28b..7744197 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "builtin-modules": "4.0.0", "esbuild": "0.24.0", "jest": "^29.7.0", - "obsidian": "*", + "obsidian": "latest", "process": "^0.11.10", "ts-jest": "^29.1.4", "tslib": "2.8.1", diff --git a/src/ResourceLinkConverter.ts b/src/ResourceLinkConverter.ts index 5edb994..4d6ae6e 100644 --- a/src/ResourceLinkConverter.ts +++ b/src/ResourceLinkConverter.ts @@ -10,13 +10,22 @@ export class ResourceLinkConverter implements Converter { private readonly absolutePath: string; private readonly attachmentsFolder: string; private readonly relativeResourcePath: string; + private readonly liquidFilterOptions: { useRelativeUrl: boolean }; - constructor(fileName: string, resourcePath: string, absolutePath: string, attachmentsFolder: string, relativeResourcePath: string) { + constructor( + fileName: string, + resourcePath: string, + absolutePath: string, + attachmentsFolder: string, + relativeResourcePath: string, + liquidFilterOptions?: { useRelativeUrl: boolean }, + ) { this.fileName = fileName; this.resourcePath = resourcePath; this.absolutePath = absolutePath; this.attachmentsFolder = attachmentsFolder; this.relativeResourcePath = relativeResourcePath; + this.liquidFilterOptions = liquidFilterOptions ?? { useRelativeUrl: false }; } convert(input: string): string { diff --git a/src/jekyll/chirpy.ts b/src/jekyll/chirpy.ts index bfd86ec..6d70fdf 100644 --- a/src/jekyll/chirpy.ts +++ b/src/jekyll/chirpy.ts @@ -13,6 +13,10 @@ import { CurlyBraceConverter } from '../CurlyBraceConverter'; import JekyllSettings from './settings/JekyllSettings'; import { convertFileName } from '../FilenameConverter'; +interface LiquidFilterOptions { + useRelativeUrl: boolean; +} + export async function convertToChirpy(plugin: O2Plugin) { const settings = plugin.jekyll as JekyllSettings; try { @@ -31,6 +35,7 @@ export async function convertToChirpy(plugin: O2Plugin) { vaultAbsolutePath(plugin), plugin.obsidianPathSettings.attachmentsFolder, settings.jekyllRelativeResourcePath, + { useRelativeUrl: false } as LiquidFilterOptions, ); const curlyBraceConverter = new CurlyBraceConverter( settings.isEnableCurlyBraceConvertMode, diff --git a/src/settings.ts b/src/settings.ts index a73ecbe..7a68565 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -36,14 +36,14 @@ export class O2SettingTab extends PluginSettingTab { text: 'Settings for O2 plugin', }); - this.containerEl.createEl('h2', { + this.containerEl.createEl('h3', { text: 'Path Settings', }); this.addReadyFolderSetting(); this.addArchiveFolderSetting(); this.addAttachmentsFolderSetting(); - this.containerEl.createEl('h2', { + this.containerEl.createEl('h3', { text: 'Features', }); this.enableCurlyBraceSetting(); @@ -52,14 +52,18 @@ export class O2SettingTab extends PluginSettingTab { this.enableAutoArchiveSetting(); // jekyll settings - this.containerEl.createEl('h2', { + this.containerEl.createEl('h3', { text: 'Jekyll', }); this.addJekyllPathSetting(); this.addJekyllRelativeResourcePathSetting(); + //// liquidFilter; + this.containerEl.createEl('h5', { + text: 'Liquid Filter', + }); // docusaurus settings - this.containerEl.createEl('h2', { + this.containerEl.createEl('h3', { text: 'Docusaurus', }); this.addDocusaurusPathSetting(); diff --git a/src/tests/ResourceLinkConverter.test.ts b/src/tests/ResourceLinkConverter.test.ts index 28818b8..ad4e661 100644 --- a/src/tests/ResourceLinkConverter.test.ts +++ b/src/tests/ResourceLinkConverter.test.ts @@ -132,3 +132,21 @@ _This is a test image._ }); }); + +describe('liquid filter', () => { + it('should enable a relative_url', () => { + const converter = new ResourceLinkConverter( + '2023-01-01-post-mock', + 'assets', + 'test', + 'attachments', + 'assets', + { useRelativeUrl: true }, + ); + + const context = `![[test.png]]`; + const result = converter.convert(context); + + expect(result).toEqual(`![image]({{ "/assets/2023-01-01-post-mock/test.png" | relative_url }})`); + }); +});