Skip to content

Commit cfa194c

Browse files
authored
Merge pull request lukeleppan#112 from NullCub3/stats-location-config
2 parents 49ed5c1 + 7ff940f commit cfa194c

File tree

6 files changed

+27
-12
lines changed

6 files changed

+27
-12
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "better-word-count",
33
"name": "Better Word Count",
4-
"version": "0.10.0",
4+
"version": "0.10.1",
55
"description": "Counts the words of selected text in the editor.",
66
"author": "Luke Leppan",
77
"authorUrl": "https://lukeleppan.com",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "better-word-count",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "Counts the words of selected text in the editor.",
55
"main": "main.js",
66
"types": "src/api.d.ts",

src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export const VIEW_TYPE_STATS = "vault-stats";
2-
export const STATS_FILE = ".obsidian/vault-stats.json";
32
export const STATS_ICON = `<g transform="matrix(0.95,0,0,0.95,2.5,2.5)"><path fill="currentColor" stroke="currentColor" d="M3.77,100L22.421,100C24.503,100 26.19,98.013 26.19,95.561L26.19,34.813C26.19,32.361 24.503,30.374 22.421,30.374L3.77,30.374C1.688,30.374 -0,32.361 -0,34.813L-0,95.561C-0,98.013 1.688,100 3.77,100ZM40.675,100L59.325,100C61.408,100 63.095,98.013 63.095,95.561L63.095,4.439C63.095,1.987 61.408,-0 59.325,-0L40.675,-0C38.592,-0 36.905,1.987 36.905,4.439L36.905,95.561C36.905,98.013 38.592,100 40.675,100ZM77.579,100L96.23,100C98.312,100 100,98.013 100,95.561L100,46.495C100,44.043 98.312,42.056 96.23,42.056L77.579,42.056C75.497,42.056 73.81,44.043 73.81,46.495L73.81,95.561C73.81,98.013 75.497,100 77.579,100Z" style="fill:none;fill-rule:nonzero;stroke-width:8px;"/></g>`;
43
export const STATS_ICON_NAME = "stats-graph";
54
export const MATCH_HTML_COMMENT = new RegExp(

src/settings/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export interface BetterWordCountSettings {
4343
collectStats: boolean;
4444
pageWords: number;
4545
displaySectionCounts: boolean;
46+
statsPath: string;
4647
}
4748

4849
export const DEFAULT_SETTINGS: BetterWordCountSettings = {
@@ -78,4 +79,5 @@ export const DEFAULT_SETTINGS: BetterWordCountSettings = {
7879
collectStats: false,
7980
displaySectionCounts: false,
8081
pageWords: 300,
82+
statsPath: ".obsidian/vault-stats.json",
8183
};

src/settings/SettingsTab.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab {
1818
new Setting(containerEl)
1919
.setName("Collect Statistics")
2020
.setDesc(
21-
"Reload Required for change to take effect. Turn on to start collecting daily statistics of your writing. Stored in the vault-stats.json file in the .obsidian of your vault. This is required for counts of the day as well as total counts."
21+
"Reload required for change to take effect. Turn on to start collecting daily statistics of your writing. Stored in the path specified below. This is required for counts of the day as well as total counts."
2222
)
2323
.addToggle((cb: ToggleComponent) => {
2424
cb.setValue(this.plugin.settings.collectStats);
@@ -61,6 +61,21 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab {
6161
});
6262
});
6363

64+
// Advanced Settings
65+
containerEl.createEl("h4", { text: "Advanced Settings" });
66+
new Setting(containerEl)
67+
.setName("Vault Stats File Path")
68+
.setDesc("Reload required for change to take effect. The location of the vault statistics file, relative to the vault root.")
69+
.addText((text: TextComponent) => {
70+
text.setPlaceholder(".obsidian/vault-stats.json");
71+
text.setValue(this.plugin.settings.statsPath.toString());
72+
text.onChange(async (value: string) => {
73+
this.plugin.settings.statsPath = value;
74+
await this.plugin.saveSettings();
75+
});
76+
});
77+
78+
6479
// Status Bar Settings
6580
addStatusBarSettings(this.plugin, containerEl);
6681
}

src/stats/StatsManager.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { debounce, Debouncer, TFile, Vault, Workspace } from "obsidian";
22
import type BetterWordCount from "../main";
3-
import { STATS_FILE } from "../constants";
43
import type { Day, VaultStatistics } from "./Stats";
54
import moment from "moment";
65
import {
@@ -45,32 +44,32 @@ export default class StatsManager {
4544
}
4645
});
4746

48-
this.vault.adapter.exists(STATS_FILE).then(async (exists) => {
47+
this.vault.adapter.exists(this.plugin.settings.statsPath).then(async (exists) => {
4948
if (!exists) {
5049
const vaultSt: VaultStatistics = {
5150
history: {},
5251
modifiedFiles: {},
5352
};
54-
await this.vault.adapter.write(STATS_FILE, JSON.stringify(vaultSt));
55-
this.vaultStats = JSON.parse(await this.vault.adapter.read(STATS_FILE));
53+
await this.vault.adapter.write(this.plugin.settings.statsPath, JSON.stringify(vaultSt));
54+
this.vaultStats = JSON.parse(await this.vault.adapter.read(this.plugin.settings.statsPath));
5655
} else {
57-
this.vaultStats = JSON.parse(await this.vault.adapter.read(STATS_FILE));
56+
this.vaultStats = JSON.parse(await this.vault.adapter.read(this.plugin.settings.statsPath));
5857
if (!this.vaultStats.hasOwnProperty("history")) {
5958
const vaultSt: VaultStatistics = {
6059
history: {},
6160
modifiedFiles: {},
6261
};
63-
await this.vault.adapter.write(STATS_FILE, JSON.stringify(vaultSt));
62+
await this.vault.adapter.write(this.plugin.settings.statsPath, JSON.stringify(vaultSt));
6463
}
65-
this.vaultStats = JSON.parse(await this.vault.adapter.read(STATS_FILE));
64+
this.vaultStats = JSON.parse(await this.vault.adapter.read(this.plugin.settings.statsPath));
6665
}
6766

6867
await this.updateToday();
6968
});
7069
}
7170

7271
async update(): Promise<void> {
73-
this.vault.adapter.write(STATS_FILE, JSON.stringify(this.vaultStats));
72+
this.vault.adapter.write(this.plugin.settings.statsPath, JSON.stringify(this.vaultStats));
7473
}
7574

7675
async updateToday(): Promise<void> {

0 commit comments

Comments
 (0)