Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
songkg7 committed Jun 27, 2024
1 parent 133879a commit 48edb37
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/docusaurus/DateExtractionPattern.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* SINGLE: YYYY-MM-DD-my-blog-post-title.md
* MDX: YYYY-MM-DD-my-blog-post-title.mdx
* Single folder + index.md: YYYY-MM-DD-my-blog-post-title/index.md
* Folder named by date: YYYY-MM-DD/my-blog-post-title.md
* Nested folders by date: YYYY/MM/DD/my-blog-post-title.md
* Partially nested folders by date: YYYY/MM-DD/my-blog-post-title.md
* Nested folders + index.md: YYYY/MM/DD/my-blog-post-title/index.md
* Date in the middle of path: category/YYYY/MM-DD-my-blog-post-title.md
*/
export const DateExtractionPattern = {
SINGLE: 'YYYY-MM-DD-my-blog-post-title.md',
MDX: 'YYYY-MM-DD-my-blog-post-title.mdx',
SINGLE_FOLDER_INDEX: 'YYYY-MM-DD-my-blog-post-title/index.md',
FOLDER_NAMED_BY_DATE: 'YYYY-MM-DD/my-blog-post-title.md',
NESTED_FOLDERS_BY_DATE: 'YYYY/MM/DD/my-blog-post-title.md',
PARTIALLY_NESTED_FOLDERS_BY_DATE: 'YYYY/MM-DD/my-blog-post-title.md',
NESTED_FOLDERS_INDEX: 'YYYY/MM/DD/my-blog-post-title/index.md',
DATE_IN_MIDDLE_OF_PATH: 'category/YYYY/MM-DD-my-blog-post-title.md',
} as const;
3 changes: 2 additions & 1 deletion src/docusaurus/settings/DocusaurusSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default class DocusaurusSettings implements O2PluginSettings {
docusaurusPath: string;
docusaurusRelativeResourcePath: string;
isAutoCreateFolder: boolean;
dateExtractionPattern: string;

targetPath(): string {
throw new Error('Method not implemented.');
Expand All @@ -15,6 +16,6 @@ export default class DocusaurusSettings implements O2PluginSettings {
throw new Error('Method not implemented.');
}
afterPropertiesSet(): boolean {
throw new Error('Method not implemented.');
return this.docusaurusPath.length !== 0;
}
}
17 changes: 17 additions & 0 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { App, PluginSettingTab, Setting } from 'obsidian';
import O2Plugin from './main';
import JekyllSetting from './jekyll/settings/JekyllSettings';
import DocusaurusSettings from './docusaurus/settings/DocusaurusSettings';
import { DateExtractionPattern } from './docusaurus/DateExtractionPattern';

export interface O2PluginSettings {
attachmentsFolder: string;
Expand Down Expand Up @@ -46,6 +47,7 @@ export class O2SettingTab extends PluginSettingTab {
text: 'Docusaurus',
});
this.addDocusaurusPathSetting();
this.dateExtractionPatternSetting();

this.containerEl.createEl('h2', {
text: 'Features',
Expand Down Expand Up @@ -174,4 +176,19 @@ export class O2SettingTab extends PluginSettingTab {
await this.plugin.saveSettings();
}));
}

private dateExtractionPatternSetting() {
const docusaurus = this.plugin.docusaurus as DocusaurusSettings;
new Setting(this.containerEl)
.setName('Date extraction pattern')
.setDesc('The pattern to extract date from note title.')
.addDropdown(dropdown => {
dropdown.addOptions(DateExtractionPattern);
dropdown.setValue(docusaurus.dateExtractionPattern);
dropdown.onChange(async (value) => {
docusaurus.dateExtractionPattern = value;
await this.plugin.saveSettings();
});
});
}
}

0 comments on commit 48edb37

Please sign in to comment.