Skip to content
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

refactor: settings architecture #382

Merged
merged 13 commits into from
Jul 5, 2024
Merged

refactor: settings architecture #382

merged 13 commits into from
Jul 5, 2024

Conversation

songkg7
Copy link
Owner

@songkg7 songkg7 commented Jul 5, 2024

Pull Request

Checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bugfixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

  • Delete duplicate settings and make clear.
  • Auto Archive option for 1.x compativility.
  • fix some typos.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor

    • Unified settings structure by replacing references to JekyllSettings and DocusaurusSettings with O2Plugin.
    • Simplified settings by removing folder-related properties and merging them into ObsidianPathSettings.
    • Enhanced the O2Plugin class to directly manage path settings and validation.
  • New Features

    • Introduced new settings options like isEnableUpdateFrontmatterTimeOnEdit for improved customization.
  • Chores

    • Updated function signatures and removed obsolete methods for streamlined codebase maintenance.

@songkg7 songkg7 self-assigned this Jul 5, 2024
Copy link
Contributor

coderabbitai bot commented Jul 5, 2024

Warning

Rate limit exceeded

@songkg7 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 22 minutes and 19 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 2ac8a0d and 3de1189.

Walkthrough

The modifications focus on reorganizing and refining settings handling in various parts of the codebase, notably transitioning from JekyllSettings and individual settings to a unified O2Plugin structure. This involved updating functions, classes, and references to utilize O2Plugin, streamlining settings management and enhancing consistency across file paths, resource handling, and folder management features.

Changes

File Path Change Summary
src/ResourceLinkConverter.ts Replaced JekyllSettings with O2Plugin for handling resource paths and attachments. Removed convertJekyllResourceLink.
src/core/validation.ts Refactored validateSettings to accept only the plugin parameter, using it directly for setting references.
src/docusaurus/docusaurus.ts Updated path handling in moveFiles function to use plugin.obsidianPathSettings.readyFolder.
src/docusaurus/settings/DocusaurusSettings.ts Removed obsolete folder and auto-achievement settings, focusing on path and date pattern settings.
src/jekyll/chirpy.ts Reorganized plugin settings and updated references to use plugin.obsidianPathSettings. Removed a validation step.
src/jekyll/settings/JekyllSettings.ts Removed outdated folder settings and added isEnableUpdateFrontmatterTimeOnEdit.
src/main.ts Streamlined settings handling, added obsidianPathSettings property to O2Plugin, modified conversion command setup.
src/settings.ts Introduced ObsidianPathSettings class and updated O2SettingTab to use these new settings.
src/utils.ts Refactored to use obsidianPathSettings for file path handling, renamed archiving functions, adjusted file operations.

Poem

Changes made with thoughtful care,
Patterns shifted, settings fair.
Paths aligned, in code they sing,
Better flow to everything.
Obsidian's might, settings bright,
Jekyll's echoes fade from sight.
New structures rise, neat and tight.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Outside diff range and nitpick comments (5)
src/docusaurus/settings/DocusaurusSettings.ts (1)

Line range hint 1-3: Consider importing only necessary modules.

If DateExtractionPattern is not used elsewhere, consider importing only the required pattern to improve readability and reduce potential memory overhead.

src/jekyll/settings/JekyllSettings.ts (3)

1-3: Consider importing only necessary modules.

If only a part of O2PluginSettings is used, consider importing only the required module to improve readability and reduce potential memory overhead.


5-7: Avoid using private properties with public getters/setters.

Using private properties with public getters/setters can be confusing. Consider making the properties public if they need to be accessed externally.


Line range hint 10-12: Remove unnecessary comments.

The FIXME: abstraction comment should be addressed or removed to maintain clean code.

src/main.ts (1)

2-3: Consider sorting imports.

Sorting imports alphabetically can improve readability.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 58b17dc and 9ca1801.

Files selected for processing (9)
  • src/ResourceLinkConverter.ts (2 hunks)
  • src/core/validation.ts (1 hunks)
  • src/docusaurus/docusaurus.ts (1 hunks)
  • src/docusaurus/settings/DocusaurusSettings.ts (1 hunks)
  • src/jekyll/chirpy.ts (6 hunks)
  • src/jekyll/settings/JekyllSettings.ts (3 hunks)
  • src/main.ts (3 hunks)
  • src/settings.ts (7 hunks)
  • src/utils.ts (3 hunks)
Additional comments not posted (19)
src/docusaurus/settings/DocusaurusSettings.ts (1)

Line range hint 14-16: Ensure docusaurusPath is initialized.

The docusaurusPath property is directly used in methods like targetPath and resourcePath. Ensure it is initialized properly to avoid potential runtime errors.

src/jekyll/settings/JekyllSettings.ts (1)

14-16: Ensure properties are initialized.

The properties _isEnableBanner, _isEnableCurlyBraceConvertMode, and _isEnableUpdateFrontmatterTimeOnEdit are used but not initialized. Ensure they are properly initialized to avoid potential runtime errors.

src/main.ts (1)

11-13: Ensure obsidianPathSettings is initialized.

The obsidianPathSettings property is directly used in various methods. Ensure it is initialized properly to avoid potential runtime errors.

src/docusaurus/docusaurus.ts (3)

Line range hint 8-13:
LGTM!

The markPublished function processes front matter for files in the ready folder, setting a published date if not already present. No changes necessary.


Line range hint 15-24:
LGTM!

The checkPublished function processes front matter to check for a published date and returns it. No changes necessary.


Line range hint 27-69:
LGTM!

The convertToDocusaurus function converts markdown files to Docusaurus format and moves them to the target folder. The use of plugin.obsidianPathSettings.readyFolder is correctly integrated. No changes necessary.

src/jekyll/chirpy.ts (2)

Line range hint 34-46:
LGTM!

The convertToChirpyV2 function converts markdown files to Chirpy format. The use of plugin.obsidianPathSettings.readyFolder is correctly integrated. No changes necessary.


Line range hint 70-89:
LGTM!

The convertToChirpy function converts markdown files to Chirpy format. The use of plugin.obsidianPathSettings is correctly integrated. No changes necessary.

src/ResourceLinkConverter.ts (1)

12-21: LGTM!

The convertJekyllResourceLink function converts resource links in Jekyll format. The use of plugin: O2Plugin is correctly integrated. No changes necessary.

src/utils.ts (1)

76-84: LGTM!

The archiving function moves files from the ready folder to the archive folder if auto-archive is enabled. The use of plugin.obsidianPathSettings is correctly integrated. No changes necessary.

src/settings.ts (9)

Line range hint 15-19:
LGTM!

The updates to the O2PluginSettings interface look good.


38-53: LGTM!

The updates to the display method look good. The new settings are correctly added and displayed.


Line range hint 55-68:
LGTM!

The addition of the enableUpdateFrontmatterTimeOnEditSetting method looks good. The setting is correctly managed.


87-89: LGTM!

The addition of the enableAutoCreateFolderSetting method looks good. The setting is correctly managed.


141-143: LGTM!

The addition of the addAttachmentsFolderSetting method looks good. The setting is correctly managed.


154-156: LGTM!

The addition of the addReadyFolderSetting method looks good. The setting is correctly managed.


167-169: LGTM!

The addition of the addArchiveFolderSetting method looks good. The setting is correctly managed.


210-212: LGTM!

The addition of the enableAutoArchiveSetting method looks good. The setting is correctly managed.


7-13: LGTM! Verify the usage of the new properties.

The addition of the ObsidianPathSettings class looks good. Ensure that all occurrences of these new properties are correctly used in the codebase.

Verification successful

Verified: All new properties are correctly used in the codebase.

The properties readyFolder, archiveFolder, attachmentsFolder, isAutoArchive, and isAutoCreateFolder in the ObsidianPathSettings class are correctly referenced and utilized across multiple files.

  • readyFolder: Found in src/utils.ts, src/settings.ts, src/jekyll/chirpy.ts, src/docusaurus/docusaurus.ts, src/core/validation.ts.
  • archiveFolder: Found in src/utils.ts, src/settings.ts, src/core/validation.ts.
  • attachmentsFolder: Found in src/settings.ts, src/ResourceLinkConverter.ts, src/jekyll/chirpy.ts, src/core/validation.ts.
  • isAutoArchive: Found in src/utils.ts, src/settings.ts, src/main.ts.
  • isAutoCreateFolder: Found in src/settings.ts, src/core/validation.ts.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new properties in the codebase.

# Test: Search for the usage of the new properties. Expect: Correct usage in all instances.
rg --type python $'obsidianPathSettings'

Length of output: 70


Script:

#!/bin/bash
# Description: Verify the usage of the new properties in the codebase.

# Test: Search for the usage of each property in the ObsidianPathSettings class within TypeScript/JavaScript files.
properties=("readyFolder" "archiveFolder" "attachmentsFolder" "isAutoArchive" "isAutoCreateFolder")

for property in "${properties[@]}"; do
  echo "Searching for property: $property"
  rg --type-add 'ts:*.{ts,tsx}' --type ts "$property"
done

Length of output: 5561

src/core/validation.ts Show resolved Hide resolved
src/main.ts Show resolved Hide resolved
src/main.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 9ca1801 and 2ac8a0d.

Files selected for processing (2)
  • src/ResourceLinkConverter.ts (1 hunks)
  • src/jekyll/chirpy.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/ResourceLinkConverter.ts
Additional comments not posted (4)
src/jekyll/chirpy.ts (4)

3-6: Verify the usage of ResourceLinkConverter and FrontMatterConverter.

Ensure that these converters are correctly utilized within the file and that there are no redundant imports.

Verification successful

Imports of ResourceLinkConverter and FrontMatterConverter are valid and used correctly.

  • ResourceLinkConverter is imported and instantiated in src/jekyll/chirpy.ts.
  • FrontMatterConverter is imported and instantiated in src/jekyll/chirpy.ts.

The imports are not redundant and are correctly utilized within the file.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `ResourceLinkConverter` and `FrontMatterConverter`.

# Test: Search for the usage of `ResourceLinkConverter` and `FrontMatterConverter`. Expect: Only relevant occurrences.
rg --type ts 'ResourceLinkConverter|FrontMatterConverter'

Length of output: 1835


15-19: Verify the settings usage from the plugin object.

Ensure that the settings accessed from the plugin object are correctly used and initialized.

Verification successful

Verified the settings usage from the plugin object.

The settings accessed from the plugin object are correctly initialized and used across the codebase.

  • src/jekyll/chirpy.ts: The settings are accessed as plugin.jekyll and plugin.obsidianPathSettings.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the settings usage from the `plugin` object.

# Test: Search for the initialization and usage of settings in the `plugin` object. Expect: Correct initialization and usage.
rg --type ts 'plugin.jekyll|plugin.obsidianPathSettings'

Length of output: 3914


51-51: Verify the readyFolder setting usage.

Ensure that the readyFolder setting from plugin.obsidianPathSettings is correctly used.

Verification successful

The readyFolder setting is correctly used.

The readyFolder setting from plugin.obsidianPathSettings is consistently and correctly utilized across various files for filtering, renaming, setting values, constructing paths, and validating existence.

  • src/utils.ts: Filtering files and renaming paths.
  • src/settings.ts: Setting and getting the value in the settings UI.
  • src/jekyll/chirpy.ts: Constructing paths for moving files.
  • src/core/validation.ts: Checking and creating the folder if necessary.
  • src/docusaurus/docusaurus.ts: Constructing paths for moving files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `readyFolder` setting.

# Test: Search for the usage of `readyFolder` setting. Expect: Correct usage.
rg --type ts 'plugin.obsidianPathSettings.readyFolder'

Length of output: 1244


Script:

#!/bin/bash
# Extract lines around the usage of `readyFolder` in each file to verify correct usage.

# Extract lines from src/utils.ts
rg --type ts --context 5 'plugin.obsidianPathSettings.readyFolder' src/utils.ts

# Extract lines from src/settings.ts
rg --type ts --context 5 'plugin.obsidianPathSettings.readyFolder' src/settings.ts

# Extract lines from src/jekyll/chirpy.ts
rg --type ts --context 5 'plugin.obsidianPathSettings.readyFolder' src/jekyll/chirpy.ts

# Extract lines from src/core/validation.ts
rg --type ts --context 5 'plugin.obsidianPathSettings.readyFolder' src/core/validation.ts

# Extract lines from src/docusaurus/docusaurus.ts
rg --type ts --context 5 'plugin.obsidianPathSettings.readyFolder' src/docusaurus/docusaurus.ts

Length of output: 3548


32-32: Ensure the attachmentsFolder setting is correctly used.

Verify that the attachmentsFolder setting from plugin.obsidianPathSettings is correctly used.

Verification successful

The attachmentsFolder setting is used correctly.

The attachmentsFolder setting from plugin.obsidianPathSettings is utilized appropriately across different contexts in the codebase. The setting is correctly set and saved in src/settings.ts, passed as a parameter in src/jekyll/chirpy.ts, and validated for existence in src/core/validation.ts.

  • src/settings.ts: Used in a UI setting component for setting and saving the folder path.
  • src/jekyll/chirpy.ts: Passed as an argument to a ResourceLinkConverter.
  • src/core/validation.ts: Checked for existence and potentially created if it does not exist.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `attachmentsFolder` setting.

# Test: Search for the usage of `attachmentsFolder` setting. Expect: Correct usage.
rg --type ts 'plugin.obsidianPathSettings.attachmentsFolder'

Length of output: 905


Script:

#!/bin/bash
# Extracting relevant code snippets to review the context of `attachmentsFolder` usage.

# Extract context from src/settings.ts
echo "Context from src/settings.ts:"
rg --context 5 'plugin.obsidianPathSettings.attachmentsFolder' src/settings.ts

# Extract context from src/jekyll/chirpy.ts
echo -e "\nContext from src/jekyll/chirpy.ts:"
rg --context 5 'plugin.obsidianPathSettings.attachmentsFolder' src/jekyll/chirpy.ts

# Extract context from src/core/validation.ts
echo -e "\nContext from src/core/validation.ts:"
rg --context 5 'plugin.obsidianPathSettings.attachmentsFolder' src/core/validation.ts

Length of output: 2308

@songkg7 songkg7 added the enhancement New feature or request label Jul 5, 2024
@songkg7 songkg7 enabled auto-merge (squash) July 5, 2024 05:35
@songkg7 songkg7 disabled auto-merge July 5, 2024 05:35
@songkg7 songkg7 merged commit ef7bb40 into main Jul 5, 2024
20 checks passed
@songkg7 songkg7 deleted the fix-settings branch July 5, 2024 05:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size/L
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant