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

Feature: add Obsidian folder option #14

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
siteName: "Quartz",
slugifyEnabled: true,
contentFolder: "content",
obsidianRootFolder: "",

Check failure on line 25 in main.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Delete `↹`
mbbroberg marked this conversation as resolved.
Show resolved Hide resolved

// Timestamp related settings
showCreatedTimestamp: false,
Expand Down
1 change: 1 addition & 0 deletions src/models/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default interface QuartzSyncerSettings {
slugifyEnabled: boolean;

contentFolder: string;
obsidianRootFolder: string;

showCreatedTimestamp: boolean;
createdTimestampKey: string;
Expand Down
13 changes: 7 additions & 6 deletions src/repositoryConnection/QuartzSyncerSiteManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
}

await this.userSyncerConnection.updateFile({
path: ".env",
path: ".env".replace(this.settings.obsidianRootFolder, this.settings.contentFolder),

Check failure on line 96 in src/repositoryConnection/QuartzSyncerSiteManager.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Replace `this.settings.obsidianRootFolder,·this.settings.contentFolder` with `⏎↹↹↹↹this.settings.obsidianRootFolder,⏎↹↹↹↹this.settings.contentFolder,⏎↹↹↹`
content: base64Settings,
message: "Update settings",
sha: currentFile?.sha,
Expand Down Expand Up @@ -135,7 +135,7 @@
for (const note of notes) {
const vaultPath = note.path.replace(
this.settings.contentFolder,
"",
this.settings.obsidianRootFolder,
);

const actualVaultPath = vaultPath.startsWith("/")
Expand All @@ -160,15 +160,16 @@
);
const hashes: Record<string, string> = {};

for (const img of images) {
const vaultPath = decodeURI(
img.path.replace(this.settings.contentFolder, ""),
for (const image of images) {
const vaultPath = image.path.replace(
this.settings.contentFolder,
this.settings.obsidianRootFolder,
);

const actualVaultPath = vaultPath.startsWith("/")
? vaultPath.substring(1)
: vaultPath;
hashes[actualVaultPath] = img.sha;
hashes[actualVaultPath] = image.sha;
}

return hashes;
Expand Down
16 changes: 16 additions & 0 deletions src/views/SettingsView/GithubSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
this.initializeGitHubUserNameSetting();
this.initializeGitHubTokenSetting();
this.initializeGitHubContentFolder();
this.initializeObsidianRootFolder();
}

initializeHeader = () => {
Expand Down Expand Up @@ -121,6 +122,21 @@
);
}

private initializeObsidianRootFolder() {
new Setting(this.settingsRootElement)
.setName("Obsidian root folder name")

Check failure on line 127 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
.setDesc('The root folder in your Obsidian structure. For example, "My Garden"')

Check failure on line 128 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Replace `.setDesc('The·root·folder·in·your·Obsidian·structure.·For·example,·"My·Garden"'` with `↹.setDesc(⏎↹↹↹↹'The·root·folder·in·your·Obsidian·structure.·For·example,·"My·Garden"',⏎↹↹↹`
.addText((text) =>

Check failure on line 129 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
text

Check failure on line 130 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
.setPlaceholder("My Garden")

Check failure on line 131 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
.setValue(this.settings.settings.obsidianRootFolder)

Check failure on line 132 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
.onChange(async (value) => {

Check failure on line 133 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
this.settings.settings.obsidianRootFolder = value;

Check failure on line 134 in src/views/SettingsView/GithubSettings.ts

View workflow job for this annotation

GitHub Actions / lint-and-check-formatting

Insert `↹`
await this.checkConnectionAndSaveSettings();
}),
);
}

private initializeGitHubUserNameSetting() {
new Setting(this.settingsRootElement)
.setName("GitHub Username")
Expand Down
Loading