-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for multiple authors and update settings UI #395
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { PlatformType } from './enums/PlatformType'; | ||
import { | ||
AuthorStrategy, | ||
|
||
|
||
} from './strategies/authors/AuthorStrategy'; | ||
import { DocusaurusAuthorStrategy } from './strategies/authors/DocusaurusAuthorStrategy'; | ||
import { JekyllAuthorStrategy } from './strategies/authors/JekyllAuthorStrategy'; | ||
import { DefaultAuthorStrategy } from './strategies/authors/DefaultAuthorStrategy'; | ||
|
||
export class AuthorStrategyFactory { | ||
static createStrategy(platform: PlatformType, authors: string): AuthorStrategy { | ||
if (!authors) { | ||
return new DefaultAuthorStrategy(); | ||
} | ||
switch (platform) { | ||
case PlatformType.Jekyll: | ||
return new JekyllAuthorStrategy(); | ||
case PlatformType.Docusaurus: | ||
return new DocusaurusAuthorStrategy(); | ||
default: | ||
return new DefaultAuthorStrategy(); | ||
} | ||
} | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export enum PlatformType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in TS, export const PlatformType = {
DEFAULT, DOCUSAURUS, JEKYLL
} or refer to src/core/ObsidianRegex.ts |
||
Default, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Clarify the Purpose of The
Consider renaming it to a more specific name or adding a comment to explain its purpose. 🔗 Analysis chainClarify the purpose of the The Could you provide more context on the intended use of the To help understand the usage, let's search for its occurrences in the codebase: Action Required: Please run the following shell script to search for usages of 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Search for usages of PlatformType.Default
rg --type typescript "PlatformType\.Default"
Length of output: 81 Script: #!/bin/bash
# Search for usages of PlatformType.Default in TypeScript files
rg "PlatformType\.Default" --glob "*.ts" --glob "*.tsx"
Length of output: 135 |
||
Jekyll, | ||
Docusaurus, | ||
// 추가 플랫폼은 여기에 열거할 수 있습니다. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import { O2PluginSettings } from '../../settings'; | ||
import { PlatformType } from '../../enums/PlatformType'; | ||
|
||
export default class JekyllSettings implements O2PluginSettings { | ||
private _jekyllPath: string; | ||
private _jekyllRelativeResourcePath: string; | ||
authors: string = ''; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider revising the While the plural name Consider the following improvements:
These changes would better support multiple authors and maintain consistency with the class's existing design patterns. |
||
platform: PlatformType = PlatformType.Jekyll; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Consider encapsulating the The private _platform: PlatformType = PlatformType.Jekyll;
get platform(): PlatformType {
return this._platform;
}
set platform(value: PlatformType) {
this._platform = value;
} This change would align the |
||
|
||
pathReplacer(year: string, month: string, day: string, title: string): string { | ||
return `${year}-${month}-${day}-${title}.md`; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,13 +57,42 @@ export class O2SettingTab extends PluginSettingTab { | |
}); | ||
this.addJekyllPathSetting(); | ||
this.addJekyllRelativeResourcePathSetting(); | ||
this.addJekyllAuthorsSettings(); | ||
|
||
// docusaurus settings | ||
this.containerEl.createEl('h2', { | ||
text: 'Docusaurus', | ||
}); | ||
this.addDocusaurusPathSetting(); | ||
this.dateExtractionPatternSetting(); | ||
this.addDocusaurusAuthorsSettings(); | ||
} | ||
private addJekyllAuthorsSettings() { | ||
const jekyllSettings = this.plugin.jekyll as JekyllSettings; | ||
new Setting(this.containerEl) | ||
.setName('Jekyll Authors') | ||
.setDesc('Enter authors separated by commas. For single author, enter only one name.') | ||
.addText(text => text | ||
.setPlaceholder('author1, author2, ...') | ||
.setValue(jekyllSettings.authors) | ||
.onChange(async (value) => { | ||
jekyllSettings.authors = value; | ||
await this.plugin.saveSettings(); | ||
})); | ||
} | ||
|
||
private addDocusaurusAuthorsSettings() { | ||
const docusaurusSettings = this.plugin.docusaurus as DocusaurusSettings; | ||
new Setting(this.containerEl) | ||
.setName('Docusaurus Authors') | ||
.setDesc('Enter authors separated by commas. For single author, enter only one name.') | ||
.addText(text => text | ||
.setPlaceholder('author1, author2, ...') | ||
.setValue(docusaurusSettings.authors) | ||
.onChange(async (value) => { | ||
docusaurusSettings.authors = value; | ||
await this.plugin.saveSettings(); | ||
})); | ||
Comment on lines
+70
to
+95
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
} | ||
|
||
private enableUpdateFrontmatterTimeOnEditSetting() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { FrontMatter } from '../../FrontMatterConverter'; | ||
|
||
export interface AuthorStrategy { | ||
applyAuthors(frontMatter: FrontMatter, authors: string): FrontMatter; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AuthorStrategy } from './AuthorStrategy'; | ||
import { FrontMatter } from '../../FrontMatterConverter'; | ||
|
||
export class DefaultAuthorStrategy implements AuthorStrategy { | ||
applyAuthors(frontMatter: FrontMatter, authors: string): FrontMatter { | ||
return frontMatter; | ||
} | ||
Comment on lines
+5
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The current implementation of Update the method to use the applyAuthors(frontMatter: FrontMatter, authors: string | string[]): FrontMatter {
if (!frontMatter.authors) {
const authorList = Array.isArray(authors) ? authors : [authors];
return { ...frontMatter, authors: authorList };
}
return frontMatter;
} This implementation supports both single and multiple default authors, aligning with Docusaurus's use of plural 'authors'. |
||
} | ||
Comment on lines
+1
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Implementation doesn't fulfill the PR objectives The current implementation of Consider updating the applyAuthors(frontMatter: FrontMatter, authors: string): FrontMatter {
if (!frontMatter.authors && authors) {
return { ...frontMatter, authors: [authors] };
}
return frontMatter;
} This implementation adds the default author to the |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||
import { AuthorStrategy } from './AuthorStrategy'; | ||||||
import { FrontMatter } from '../../FrontMatterConverter'; | ||||||
|
||||||
export class DocusaurusAuthorStrategy implements AuthorStrategy { | ||||||
applyAuthors(frontMatter: FrontMatter, authors: string): FrontMatter { | ||||||
const authorsList = authors.split(',').map(author => author.trim()); | ||||||
delete frontMatter.author; | ||||||
songkg7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (authorsList.length === 1) { | ||||||
frontMatter.authors = authorsList[0]; | ||||||
} else { | ||||||
frontMatter.authors = `[${authorsList.join(', ')}]`; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reconsider the representation of multiple authors for Docusaurus. The current implementation encloses multiple authors in square brackets as a string. However, Docusaurus typically expects an array of strings for multiple authors. Consider modifying the implementation to use an actual array: - frontMatter.authors = `[${authorsList.join(', ')}]`;
+ frontMatter.authors = authorsList; This change ensures that the 📝 Committable suggestion
Suggested change
|
||||||
} | ||||||
return frontMatter; | ||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,15 @@ | ||||||||||||||||||||||||||||||||||||||||||
import { AuthorStrategy } from './AuthorStrategy'; | ||||||||||||||||||||||||||||||||||||||||||
import { FrontMatter } from '../../FrontMatterConverter'; | ||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||
export class JekyllAuthorStrategy implements AuthorStrategy { | ||||||||||||||||||||||||||||||||||||||||||
applyAuthors(frontMatter: FrontMatter, authors: string): FrontMatter { | ||||||||||||||||||||||||||||||||||||||||||
const authorsList = authors.split(',').map(author => author.trim()); | ||||||||||||||||||||||||||||||||||||||||||
delete frontMatter.authors; | ||||||||||||||||||||||||||||||||||||||||||
if (authorsList.length === 1) { | ||||||||||||||||||||||||||||||||||||||||||
frontMatter.author = authorsList[0]; | ||||||||||||||||||||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||||||||||||||||||||
frontMatter.authors = `[${authorsList.join(', ')}]`; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
return frontMatter; | ||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+5
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider revising the The implementation handles both single and multiple authors correctly. However, the format for multiple authors might not be compatible with Jekyll's expected format. Jekyll typically expects multiple authors to be in a YAML array format. Consider modifying line 11 to: - frontMatter.authors = `[${authorsList.join(', ')}]`;
+ frontMatter.authors = authorsList; This change ensures that the 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome
|
||||||||||||||||||||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Consider refactoring the class into a simple function.
The
AuthorStrategyFactory
class contains only a single static method. To improve code simplicity and follow functional programming principles, consider refactoring this class into a simple function.Apply this diff to refactor the class into a function:
This change addresses the static analysis warning and simplifies the code structure.
📝 Committable suggestion
🧰 Tools
🪛 Biome