Skip to content

Commit

Permalink
draft
Browse files Browse the repository at this point in the history
  • Loading branch information
songkg7 committed Dec 12, 2024
1 parent 2b76c83 commit fc04c09
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/ResourceLinkConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions src/jekyll/chirpy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down
12 changes: 8 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
18 changes: 18 additions & 0 deletions src/tests/ResourceLinkConverter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }})`);
});
});

0 comments on commit fc04c09

Please sign in to comment.