Compare commits
37 commits
Author | SHA1 | Date | |
---|---|---|---|
|
3f7ec6561e | ||
|
8e7860d510 | ||
|
141c39dbb7 | ||
|
0a208ea8ef | ||
|
d2f99e548a | ||
|
66c00b24c2 | ||
|
437547f02e | ||
|
0712d9f61a | ||
|
d3b6938e48 | ||
|
b2a43d9ca3 | ||
|
9bbeeff386 | ||
|
4a7ed4730c | ||
|
3412745204 | ||
|
fee3421508 | ||
|
b2ef959464 | ||
|
86ca1199cc | ||
|
d865d61e23 | ||
|
ec21413d55 | ||
|
fbf7977188 | ||
|
2b847ddcc9 | ||
|
aabd175d5d | ||
|
f43895645f | ||
|
5e970cad74 | ||
|
de3172ee95 | ||
|
759b4d949c | ||
|
9885035ac8 | ||
|
2cc592c13e | ||
|
88a3bd1a2a | ||
|
547fb32f95 | ||
|
9cdab1d1d7 | ||
|
44dfcb9fe3 | ||
|
566f8531b5 | ||
|
496d708117 | ||
|
3871f71aae | ||
|
909e954c3e | ||
|
76ac1fbc86 | ||
|
da44785003 |
12 changed files with 376 additions and 26 deletions
28
README.md
28
README.md
|
@ -1,34 +1,36 @@
|
|||
# Better Word Count
|
||||
|
||||
  
|
||||
|
||||
**IMPORTANT NOTICE:** Due to the introduction of the new Live Preview feature, this plugin needed to be almost entirely rewritten. It will be unstable for a while so please report bugs on github.
|
||||
|
||||
This plugin is the same as the built-in **Word Count** plugin, except when you select text, it will count the selected word instead of the whole document. I recommend turning off the built-in **Word Count** because this plugin is designed to replace that. This plugin also has the ability to store statistics about your vault.
|
||||
   
|
||||
|
||||

|
||||
|
||||
This plugin is the same as the built-in **Word Count** plugin, except when you select text, it will count the selected word instead of the whole document. I recommend turning off the built-in **Word Count** because this plugin is designed to replace that. This plugin also has the ability to store statistics about your vault.
|
||||
|
||||
## Features
|
||||
|
||||
- Allows you to store statistics about your vault.
|
||||
- Works with all languages.
|
||||
- Can display a variety of different stats. Including:
|
||||
- Words, Characters and Sentences in current file.
|
||||
- Total Words, Characters and Sentences in vault.
|
||||
- Words, Characters and Sentences typed today.
|
||||
- Total Files in vault.
|
||||
- Words, Characters, Sentences, Footnotes, and Pandoc Citations in current file.
|
||||
- Total Words, Characters, Sentences, Footnotes, Pandoc Citations, and Files in vault.
|
||||
- Words, Characters, Sentences, Footnotes, and Pandoc Citations typed today.
|
||||
- Highly Customizable status bar that can be adapted to your needs.
|
||||
|
||||
## Contributors
|
||||
|
||||
- @leoccyao
|
||||
- Added all word, char, sentence count when not viewing a markdown file.
|
||||
- @lishid
|
||||
- Helped solve the performace issue.
|
||||
- @THeK3nger
|
||||
- Fixed issue that occured when renaming files.
|
||||
- @chrisgrieser
|
||||
- Added Footnotes and Citation Counting.
|
||||
- @bakuzan
|
||||
- Added page counts.
|
||||
- Fixed issue that caused errors at start up.
|
||||
- @THeK3nger
|
||||
- Fixed issue that occurred when renaming files.
|
||||
- @lishid
|
||||
- Helped solve the performance issue.
|
||||
- @Noxellar
|
||||
- Fixed alt bar spacing issue.
|
||||
|
||||
### Special Thanks
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "better-word-count",
|
||||
"name": "Better Word Count",
|
||||
"version": "0.9.2",
|
||||
"version": "0.9.6",
|
||||
"description": "Counts the words of selected text in the editor.",
|
||||
"author": "Luke Leppan",
|
||||
"authorUrl": "https://lukeleppan.com",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "better-word-count",
|
||||
"version": "0.9.2",
|
||||
"version": "0.9.6",
|
||||
"description": "Counts the words of selected text in the editor.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
import { Transaction } from "@codemirror/state";
|
||||
import {
|
||||
ViewUpdate,
|
||||
PluginValue,
|
||||
|
@ -22,9 +23,19 @@ class EditorPlugin implements PluginValue {
|
|||
}
|
||||
|
||||
const tr = update.transactions[0];
|
||||
if (!tr) return;
|
||||
|
||||
if (!tr) {
|
||||
return;
|
||||
}
|
||||
|
||||
// When selecting text with Shift+Home the userEventType is undefined.
|
||||
// This is probably a bug in codemirror, for the time being doing an explict check
|
||||
// for the type allows us to update the stats for the selection.
|
||||
const userEventTypeUndefined =
|
||||
tr.annotation(Transaction.userEvent) === undefined;
|
||||
|
||||
if (
|
||||
tr.isUserEvent("select") &&
|
||||
(tr.isUserEvent("select") || userEventTypeUndefined) &&
|
||||
tr.newSelection.ranges[0].from !== tr.newSelection.ranges[0].to
|
||||
) {
|
||||
let text = "";
|
||||
|
|
|
@ -33,7 +33,7 @@ export default class BetterWordCount extends Plugin {
|
|||
|
||||
// Handle Statistics
|
||||
if (this.settings.collectStats) {
|
||||
this.statsManager = new StatsManager(this.app.vault, this.app.workspace);
|
||||
this.statsManager = new StatsManager(this.app.vault, this.app.workspace, this);
|
||||
}
|
||||
|
||||
// Handle Status Bar
|
||||
|
|
|
@ -2,6 +2,9 @@ export enum MetricCounter {
|
|||
words,
|
||||
characters,
|
||||
sentences,
|
||||
footnotes,
|
||||
citations,
|
||||
pages,
|
||||
files,
|
||||
}
|
||||
|
||||
|
@ -38,6 +41,7 @@ export interface BetterWordCountSettings {
|
|||
altBar: StatusBarItem[];
|
||||
countComments: boolean;
|
||||
collectStats: boolean;
|
||||
pageWords: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_SETTINGS: BetterWordCountSettings = {
|
||||
|
@ -62,7 +66,7 @@ export const DEFAULT_SETTINGS: BetterWordCountSettings = {
|
|||
altBar: [
|
||||
{
|
||||
prefix: "",
|
||||
suffix: "files",
|
||||
suffix: " files",
|
||||
metric: {
|
||||
type: MetricType.total,
|
||||
counter: MetricCounter.files,
|
||||
|
@ -71,4 +75,5 @@ export const DEFAULT_SETTINGS: BetterWordCountSettings = {
|
|||
],
|
||||
countComments: false,
|
||||
collectStats: false,
|
||||
pageWords: 300,
|
||||
};
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { App, PluginSettingTab, Setting, ToggleComponent } from "obsidian";
|
||||
import { App, PluginSettingTab, Setting, ToggleComponent, TextComponent } from "obsidian";
|
||||
import type BetterWordCount from "src/main";
|
||||
import { addStatusBarSettings } from "./StatusBarSettings";
|
||||
|
||||
|
@ -37,6 +37,18 @@ export default class BetterWordCountSettingsTab extends PluginSettingTab {
|
|||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
new Setting(containerEl)
|
||||
.setName("Page Word Count")
|
||||
.setDesc("Set how many words count as one \"page\"")
|
||||
.addText((text: TextComponent) => {
|
||||
text.inputEl.type = "number";
|
||||
text.setPlaceholder("300");
|
||||
text.setValue(this.plugin.settings.pageWords.toString());
|
||||
text.onChange(async (value: string) => {
|
||||
this.plugin.settings.pageWords = parseInt(value);
|
||||
await this.plugin.saveSettings();
|
||||
});
|
||||
});
|
||||
|
||||
// Status Bar Settings
|
||||
addStatusBarSettings(this.plugin, containerEl);
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
return "Chars in Note"
|
||||
case MetricCounter.sentences:
|
||||
return "Sentences in Note"
|
||||
case MetricCounter.footnotes:
|
||||
return "Footnotes in Note"
|
||||
case MetricCounter.citations:
|
||||
return "Citations in Note"
|
||||
case MetricCounter.pages:
|
||||
return "Pages in Note"
|
||||
case MetricCounter.files:
|
||||
return "Total Notes"
|
||||
}
|
||||
|
@ -29,6 +35,12 @@
|
|||
return "Daily Chars"
|
||||
case MetricCounter.sentences:
|
||||
return "Daily Sentences"
|
||||
case MetricCounter.footnotes:
|
||||
return "Daily Footnotes"
|
||||
case MetricCounter.citations:
|
||||
return "Daily Citations"
|
||||
case MetricCounter.pages:
|
||||
return "Daily Pages"
|
||||
case MetricCounter.files:
|
||||
return "Total Notes"
|
||||
}
|
||||
|
@ -40,6 +52,12 @@
|
|||
return "Total Chars"
|
||||
case MetricCounter.sentences:
|
||||
return "Total Sentences"
|
||||
case MetricCounter.footnotes:
|
||||
return "Total Footnotes"
|
||||
case MetricCounter.citations:
|
||||
return "Total Citations"
|
||||
case MetricCounter.pages:
|
||||
return "Total Pages"
|
||||
case MetricCounter.files:
|
||||
return "Total Notes"
|
||||
}
|
||||
|
@ -181,6 +199,9 @@
|
|||
<option value={MetricCounter.words}>Words</option>
|
||||
<option value={MetricCounter.characters}>Characters</option>
|
||||
<option value={MetricCounter.sentences}>Sentences</option>
|
||||
<option value={MetricCounter.footnotes}>Footnotes</option>
|
||||
<option value={MetricCounter.citations}>Citations</option>
|
||||
<option value={MetricCounter.pages}>Pages</option>
|
||||
<option value={MetricCounter.files}>Files</option>
|
||||
</select>
|
||||
</div>
|
||||
|
@ -348,6 +369,9 @@
|
|||
<option value={MetricCounter.words}>Words</option>
|
||||
<option value={MetricCounter.characters}>Characters</option>
|
||||
<option value={MetricCounter.sentences}>Sentences</option>
|
||||
<option value={MetricCounter.footnotes}>Footnotes</option>
|
||||
<option value={MetricCounter.citations}>Citations</option>
|
||||
<option value={MetricCounter.pages}>Pages</option>
|
||||
<option value={MetricCounter.files}>Files</option>
|
||||
</select>
|
||||
</div>
|
||||
|
|
|
@ -9,18 +9,27 @@ export interface Day {
|
|||
words: number;
|
||||
characters: number;
|
||||
sentences: number;
|
||||
pages: number;
|
||||
files: number;
|
||||
footnotes: number;
|
||||
citations: number;
|
||||
totalWords: number;
|
||||
totalCharacters: number;
|
||||
totalSentences: number;
|
||||
totalFootnotes: number;
|
||||
totalCitations: number;
|
||||
totalPages: number;
|
||||
}
|
||||
|
||||
export type ModifiedFiles = Record<string, FileStat>;
|
||||
|
||||
export interface FileStat {
|
||||
footnotes: CountDiff;
|
||||
citations: CountDiff;
|
||||
words: CountDiff;
|
||||
characters: CountDiff;
|
||||
sentences: CountDiff;
|
||||
pages: CountDiff;
|
||||
}
|
||||
|
||||
export interface CountDiff {
|
||||
|
|
|
@ -1,23 +1,30 @@
|
|||
import { debounce, Debouncer, TFile, Vault, Workspace } from "obsidian";
|
||||
import type BetterWordCount from "../main";
|
||||
import { STATS_FILE } from "../constants";
|
||||
import type { Day, VaultStatistics } from "./Stats";
|
||||
import moment from "moment";
|
||||
import {
|
||||
getCharacterCount,
|
||||
getSentenceCount,
|
||||
getPageCount,
|
||||
getWordCount,
|
||||
getCitationCount,
|
||||
getFootnoteCount,
|
||||
cleanComments,
|
||||
} from "../utils/StatUtils";
|
||||
|
||||
export default class StatsManager {
|
||||
private vault: Vault;
|
||||
private workspace: Workspace;
|
||||
private plugin: BetterWordCount;
|
||||
private vaultStats: VaultStatistics;
|
||||
private today: string;
|
||||
public debounceChange;
|
||||
|
||||
constructor(vault: Vault, workspace: Workspace) {
|
||||
constructor(vault: Vault, workspace: Workspace, plugin: BetterWordCount) {
|
||||
this.vault = vault;
|
||||
this.workspace = workspace;
|
||||
this.plugin = plugin;
|
||||
this.debounceChange = debounce(
|
||||
(text: string) => this.change(text),
|
||||
50,
|
||||
|
@ -25,9 +32,17 @@ export default class StatsManager {
|
|||
);
|
||||
|
||||
this.vault.on("rename", (new_name, old_path) => {
|
||||
const content = this.vaultStats.modifiedFiles[old_path];
|
||||
delete this.vaultStats.modifiedFiles[old_path];
|
||||
this.vaultStats.modifiedFiles[new_name.path] = content;
|
||||
if (this.vaultStats.modifiedFiles.hasOwnProperty(old_path)) {
|
||||
const content = this.vaultStats.modifiedFiles[old_path];
|
||||
delete this.vaultStats.modifiedFiles[old_path];
|
||||
this.vaultStats.modifiedFiles[new_name.path] = content;
|
||||
}
|
||||
});
|
||||
|
||||
this.vault.on("delete", (deleted_file) => {
|
||||
if (this.vaultStats.modifiedFiles.hasOwnProperty(deleted_file.path)) {
|
||||
delete this.vaultStats.modifiedFiles[deleted_file.path];
|
||||
}
|
||||
});
|
||||
|
||||
this.vault.adapter.exists(STATS_FILE).then(async (exists) => {
|
||||
|
@ -68,15 +83,24 @@ export default class StatsManager {
|
|||
const totalWords = await this.calcTotalWords();
|
||||
const totalCharacters = await this.calcTotalCharacters();
|
||||
const totalSentences = await this.calcTotalSentences();
|
||||
const totalFootnotes = await this.calcTotalFootnotes();
|
||||
const totalCitations = await this.calcTotalCitations();
|
||||
const totalPages = await this.calcTotalPages();
|
||||
|
||||
const newDay: Day = {
|
||||
words: 0,
|
||||
characters: 0,
|
||||
sentences: 0,
|
||||
pages: 0,
|
||||
files: 0,
|
||||
footnotes: 0,
|
||||
citations: 0,
|
||||
totalWords: totalWords,
|
||||
totalCharacters: totalCharacters,
|
||||
totalSentences: totalSentences,
|
||||
totalFootnotes: totalFootnotes,
|
||||
totalCitations: totalCitations,
|
||||
totalPages: totalPages,
|
||||
};
|
||||
|
||||
this.vaultStats.modifiedFiles = {};
|
||||
|
@ -85,10 +109,17 @@ export default class StatsManager {
|
|||
}
|
||||
|
||||
public async change(text: string) {
|
||||
if (this.plugin.settings.countComments) {
|
||||
text = cleanComments(text);
|
||||
}
|
||||
const fileName = this.workspace.getActiveFile().path;
|
||||
const currentWords = getWordCount(text);
|
||||
const currentCharacters = getCharacterCount(text);
|
||||
const currentSentences = getSentenceCount(text);
|
||||
const currentCitations = getCitationCount(text);
|
||||
const currentFootnotes = getFootnoteCount(text);
|
||||
const currentPages = getPageCount(text, this.plugin.settings.pageWords);
|
||||
|
||||
if (
|
||||
this.vaultStats.history.hasOwnProperty(this.today) &&
|
||||
this.today === moment().format("YYYY-MM-DD")
|
||||
|
@ -102,9 +133,19 @@ export default class StatsManager {
|
|||
currentCharacters - modFiles[fileName].characters.current;
|
||||
this.vaultStats.history[this.today].totalSentences +=
|
||||
currentSentences - modFiles[fileName].sentences.current;
|
||||
this.vaultStats.history[this.today].totalFootnotes +=
|
||||
currentSentences - modFiles[fileName].footnotes.current;
|
||||
this.vaultStats.history[this.today].totalCitations +=
|
||||
currentSentences - modFiles[fileName].citations.current;
|
||||
this.vaultStats.history[this.today].totalPages +=
|
||||
currentPages - modFiles[fileName].pages.current;
|
||||
|
||||
modFiles[fileName].words.current = currentWords;
|
||||
modFiles[fileName].characters.current = currentCharacters;
|
||||
modFiles[fileName].sentences.current = currentSentences;
|
||||
modFiles[fileName].footnotes.current = currentFootnotes;
|
||||
modFiles[fileName].citations.current = currentCitations;
|
||||
modFiles[fileName].pages.current = currentPages;
|
||||
} else {
|
||||
modFiles[fileName] = {
|
||||
words: {
|
||||
|
@ -119,6 +160,18 @@ export default class StatsManager {
|
|||
initial: currentSentences,
|
||||
current: currentSentences,
|
||||
},
|
||||
footnotes: {
|
||||
initial: currentFootnotes,
|
||||
current: currentFootnotes,
|
||||
},
|
||||
citations: {
|
||||
initial: currentCitations,
|
||||
current: currentCitations,
|
||||
},
|
||||
pages: {
|
||||
initial: currentPages,
|
||||
current: currentPages,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -138,9 +191,27 @@ export default class StatsManager {
|
|||
)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
|
||||
const footnotes = Object.values(modFiles)
|
||||
.map((counts) =>
|
||||
Math.max(0, counts.footnotes.current - counts.footnotes.initial)
|
||||
)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
const citations = Object.values(modFiles)
|
||||
.map((counts) =>
|
||||
Math.max(0, counts.citations.current - counts.citations.initial)
|
||||
).reduce((a, b) => a + b, 0);
|
||||
const pages = Object.values(modFiles)
|
||||
.map((counts) =>
|
||||
Math.max(0, counts.pages.current - counts.pages.initial)
|
||||
)
|
||||
.reduce((a, b) => a + b, 0);
|
||||
|
||||
this.vaultStats.history[this.today].words = words;
|
||||
this.vaultStats.history[this.today].characters = characters;
|
||||
this.vaultStats.history[this.today].sentences = sentences;
|
||||
this.vaultStats.history[this.today].footnotes = footnotes;
|
||||
this.vaultStats.history[this.today].citations = citations;
|
||||
this.vaultStats.history[this.today].pages = pages;
|
||||
this.vaultStats.history[this.today].files = this.getTotalFiles();
|
||||
|
||||
await this.update();
|
||||
|
@ -159,6 +230,9 @@ export default class StatsManager {
|
|||
todayHist.totalWords = await this.calcTotalWords();
|
||||
todayHist.totalCharacters = await this.calcTotalCharacters();
|
||||
todayHist.totalSentences = await this.calcTotalSentences();
|
||||
todayHist.totalFootnotes = await this.calcTotalFootnotes();
|
||||
todayHist.totalCitations = await this.calcTotalCitations();
|
||||
todayHist.totalPages = await this.calcTotalPages();
|
||||
this.update();
|
||||
} else {
|
||||
this.updateToday();
|
||||
|
@ -200,9 +274,46 @@ export default class StatsManager {
|
|||
sentence += getSentenceCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
|
||||
return sentence;
|
||||
}
|
||||
|
||||
private async calcTotalPages(): Promise<number> {
|
||||
let pages = 0;
|
||||
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
pages += getPageCount(await this.vault.cachedRead(file), this.plugin.settings.pageWords);
|
||||
}
|
||||
}
|
||||
|
||||
return pages;
|
||||
}
|
||||
|
||||
private async calcTotalFootnotes(): Promise<number> {
|
||||
let footnotes = 0;
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
footnotes += getFootnoteCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
return footnotes;
|
||||
}
|
||||
|
||||
private async calcTotalCitations(): Promise<number> {
|
||||
let citations = 0;
|
||||
const files = this.vault.getFiles();
|
||||
for (const i in files) {
|
||||
const file = files[i];
|
||||
if (file.extension === "md") {
|
||||
citations += getCitationCount(await this.vault.cachedRead(file));
|
||||
}
|
||||
}
|
||||
return citations;
|
||||
}
|
||||
|
||||
public getDailyWords(): number {
|
||||
return this.vaultStats.history[this.today].words;
|
||||
|
@ -216,6 +327,18 @@ export default class StatsManager {
|
|||
return this.vaultStats.history[this.today].sentences;
|
||||
}
|
||||
|
||||
|
||||
public getDailyFootnotes(): number {
|
||||
return this.vaultStats.history[this.today].footnotes;
|
||||
}
|
||||
|
||||
public getDailyCitations(): number {
|
||||
return this.vaultStats.history[this.today].citations;
|
||||
}
|
||||
public getDailyPages(): number {
|
||||
return this.vaultStats.history[this.today].pages;
|
||||
}
|
||||
|
||||
public getTotalFiles(): number {
|
||||
return this.vault.getMarkdownFiles().length;
|
||||
}
|
||||
|
@ -234,4 +357,19 @@ export default class StatsManager {
|
|||
if (!this.vaultStats) return await this.calcTotalSentences();
|
||||
return this.vaultStats.history[this.today].totalSentences;
|
||||
}
|
||||
|
||||
public async getTotalFootnotes(): Promise<number> {
|
||||
if (!this.vaultStats) return await this.calcTotalFootnotes();
|
||||
return this.vaultStats.history[this.today].totalFootnotes;
|
||||
}
|
||||
|
||||
public async getTotalCitations(): Promise<number> {
|
||||
if (!this.vaultStats) return await this.calcTotalCitations();
|
||||
return this.vaultStats.history[this.today].totalCitations;
|
||||
}
|
||||
|
||||
public async getTotalPages(): Promise<number> {
|
||||
if (!this.vaultStats) return await this.calcTotalPages();
|
||||
return this.vaultStats.history[this.today].totalPages;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,10 @@ import {
|
|||
getWordCount,
|
||||
getCharacterCount,
|
||||
getSentenceCount,
|
||||
getCitationCount,
|
||||
getFootnoteCount,
|
||||
getPageCount,
|
||||
cleanComments,
|
||||
} from "src/utils/StatUtils";
|
||||
import { debounce } from "obsidian";
|
||||
|
||||
|
@ -22,7 +26,7 @@ export default class StatusBar {
|
|||
);
|
||||
|
||||
this.statusBarEl.classList.add("mod-clickable");
|
||||
this.statusBarEl.setAttribute("aria-label", "Coming Soon");
|
||||
this.statusBarEl.setAttribute("aria-label", "!!!");
|
||||
this.statusBarEl.setAttribute("aria-label-position", "top");
|
||||
this.statusBarEl.addEventListener("click", (ev: MouseEvent) =>
|
||||
this.onClick(ev)
|
||||
|
@ -41,6 +45,10 @@ export default class StatusBar {
|
|||
const sb = this.plugin.settings.statusBar;
|
||||
let display = "";
|
||||
|
||||
if (!this.plugin.settings.countComments) {
|
||||
text = cleanComments(text);
|
||||
}
|
||||
|
||||
for (let i = 0; i < sb.length; i++) {
|
||||
const sbItem = sb[i];
|
||||
|
||||
|
@ -107,6 +115,66 @@ export default class StatusBar {
|
|||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.footnotes) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + getFootnoteCount(text);
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyFootnotes()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalFootnotes()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.citations) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + getCitationCount(text);
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyCitations()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalCitations()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.pages) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + getPageCount(text, this.plugin.settings.pageWords);
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyPages()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalPages()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.files) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
|
@ -209,6 +277,66 @@ export default class StatusBar {
|
|||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.footnotes) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + 0;
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyFootnotes()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalFootnotes()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.citations) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + 0;
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyCitations()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalCitations()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.pages) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
display = display + 0;
|
||||
break;
|
||||
case MetricType.daily:
|
||||
display =
|
||||
display +
|
||||
(this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getDailyPages()
|
||||
: 0);
|
||||
break;
|
||||
case MetricType.total:
|
||||
display =
|
||||
display +
|
||||
(await (this.plugin.settings.collectStats
|
||||
? this.plugin.statsManager.getTotalPages()
|
||||
: 0));
|
||||
break;
|
||||
}
|
||||
} else if (metric.counter === MetricCounter.files) {
|
||||
switch (metric.type) {
|
||||
case MetricType.file:
|
||||
|
|
|
@ -27,6 +27,23 @@ export function getCharacterCount(text: string): number {
|
|||
return text.length;
|
||||
}
|
||||
|
||||
export function getFootnoteCount(text: string): number {
|
||||
const regularFn = text.match(/\[\^\S+](?!:)/g);
|
||||
const inlineFn = text.match(/\^\[[^^].+?]/g);
|
||||
|
||||
let overallFn = 0;
|
||||
if (regularFn) overallFn += regularFn.length;
|
||||
if (inlineFn) overallFn += inlineFn.length;
|
||||
return overallFn;
|
||||
}
|
||||
|
||||
export function getCitationCount(text: string): number {
|
||||
const pandocCitations = text.match(/@[A-Za-z0-9-]+[,;\]](?!\()/gi);
|
||||
if (!pandocCitations) return 0;
|
||||
const uniqueCitations = [...new Set(pandocCitations)].length;
|
||||
return uniqueCitations;
|
||||
}
|
||||
|
||||
export function getSentenceCount(text: string): number {
|
||||
const sentences: number = (
|
||||
(text || "").match(
|
||||
|
@ -37,6 +54,10 @@ export function getSentenceCount(text: string): number {
|
|||
return sentences;
|
||||
}
|
||||
|
||||
export function getPageCount(text: string, pageWords: number): number {
|
||||
return parseFloat((getWordCount(text) / pageWords).toFixed(1));
|
||||
}
|
||||
|
||||
export function getTotalFileCount(vault: Vault): number {
|
||||
return vault.getMarkdownFiles().length;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue