mirror of
https://github.com/pedersen/obsidian-testing-vault.git
synced 2026-07-22 07:30:23 +00:00
Refactored into multiple .ts files to make this more friendly to read and review.
This commit is contained in:
parent
c1e9988548
commit
90c01a1ef9
6 changed files with 267 additions and 508 deletions
126
loremnotes.ts
Normal file
126
loremnotes.ts
Normal file
|
|
@ -0,0 +1,126 @@
|
|||
import {randomChoice, randomDateInRange, randomInt, randomSubset} from "./random";
|
||||
import {loremIpsum} from "lorem-ipsum";
|
||||
|
||||
let wrap = require('word-wrap');
|
||||
|
||||
export interface INoteGenerator {
|
||||
title?: string; // ''
|
||||
minTitleWords?: number; // 4
|
||||
maxTitleWords?: number; // 10
|
||||
minSentenceWords?: number; // 5
|
||||
maxSentenceWords?: number; // 20
|
||||
minSentences?: number; // 4
|
||||
maxSentences?: number; // 20
|
||||
minParagraphs?: number; // 1
|
||||
maxParagraphs?: number; // 10
|
||||
minTags?: number; // 0
|
||||
maxTags?: number; // 5
|
||||
aliasPercent?: number; // 10
|
||||
publishPercent?: number; // 50
|
||||
frontMatterPercent?: number; // 90
|
||||
alltitles?: Array<string>; // []
|
||||
emptyFilesPercent?: number; // 3
|
||||
orphanedNotesPercent?: number; // 5
|
||||
leafNotesPercent?: number; // 25
|
||||
minLinks?: number; // 1
|
||||
maxLinks?: number; // 10
|
||||
}
|
||||
|
||||
const tags = Array.from(new Set(loremIpsum({count: 100, units: "words"})
|
||||
.split(' ').map((word) => {
|
||||
return `#${word}`
|
||||
})))
|
||||
const cssclasses = Array.from(new Set(loremIpsum({count: 100, units: "words"})
|
||||
.split(' ')));
|
||||
|
||||
function newFrontMatter({
|
||||
publishPercent = 50,
|
||||
aliasPercent = 10,
|
||||
title = '',
|
||||
minTags = 0,
|
||||
maxTags = 5
|
||||
}: INoteGenerator): string {
|
||||
const cssclass = cssclasses[randomInt(0, cssclasses.length - 1)];
|
||||
const publish = Math.random() >= publishPercent / 100.0 ? "true" : " false";
|
||||
// generate aliases here
|
||||
let alias = '';
|
||||
const aliasresult = Math.random();
|
||||
if (aliasresult <= aliasPercent / 100.0) {
|
||||
alias = title.split(' ').map((word) => {
|
||||
return word[0]
|
||||
}).join('');
|
||||
}
|
||||
// generate tags here
|
||||
const numTags = randomInt(minTags, maxTags);
|
||||
const chosenTags = randomSubset(tags, numTags).join(',')
|
||||
const status = randomChoice(["Backlog", "In progress", "Done"]);
|
||||
const published = randomChoice([0, 1]);
|
||||
const weight = randomInt(1, 100);
|
||||
const start = new Date(Date.now());
|
||||
const end = new Date(start.getTime() + 31536000000); // magic number, milliseconds in a year
|
||||
const duedate = randomDateInRange(start, end);
|
||||
|
||||
return `---\ntags: ${chosenTags}\ncssclass: ${cssclass}\n`
|
||||
+ `aliases: ${alias}\npublish: ${publish}\n`
|
||||
+ `status: ${status}\npublished: ${published}\n`
|
||||
+ `due: ${duedate.toISOString().substring(0, 10)}\n`
|
||||
+ `weight: ${weight}\n`
|
||||
+ `---\n`;
|
||||
}
|
||||
|
||||
export function newTitle(titleWords: number): string {
|
||||
return loremIpsum({count: titleWords, units: "words"}).toLowerCase().split(' ').map((word) => {
|
||||
return word[0].toUpperCase() + word.substring(1)
|
||||
}).join(' ');
|
||||
}
|
||||
|
||||
export function newLoremNote({
|
||||
title = '',
|
||||
minTitleWords = 4,
|
||||
maxTitleWords = 10,
|
||||
minSentenceWords = 5,
|
||||
maxSentenceWords = 20,
|
||||
minSentences = 4,
|
||||
maxSentences = 20,
|
||||
minParagraphs = 1,
|
||||
maxParagraphs = 10,
|
||||
minTags = 0,
|
||||
maxTags = 5,
|
||||
aliasPercent = 10,
|
||||
publishPercent = 50,
|
||||
frontMatterPercent = 90,
|
||||
alltitles = [],
|
||||
minLinks = 1,
|
||||
maxLinks = 10
|
||||
}: INoteGenerator): { note: string, title: string } {
|
||||
const titleWords = randomInt(minTitleWords, maxTitleWords);
|
||||
const numParagraphs = randomInt(minParagraphs, maxParagraphs, 4);
|
||||
if (title.length == 0) {
|
||||
title = newTitle(titleWords);
|
||||
}
|
||||
let text = loremIpsum({
|
||||
count: numParagraphs, units: "paragraphs", format: "plain",
|
||||
paragraphLowerBound: minSentences, paragraphUpperBound: maxSentences,
|
||||
sentenceLowerBound: minSentenceWords, sentenceUpperBound: maxSentenceWords,
|
||||
suffix: "\n\n"
|
||||
});
|
||||
if (alltitles?.length > 0) {
|
||||
const numberofLinks = randomInt(minLinks, maxLinks);
|
||||
const linkedTitles = randomSubset(alltitles, numberofLinks);
|
||||
let paragraphs = text.split('\n');
|
||||
for (let i = 0; i < linkedTitles.length; i++) {
|
||||
let paragraphNumber = randomInt(0, paragraphs.length);
|
||||
paragraphs[paragraphNumber] = `${paragraphs[paragraphNumber]}[[${linkedTitles[i]}]]`
|
||||
}
|
||||
text = paragraphs.join('\n');
|
||||
}
|
||||
const wrapped = wrap(text, {width: 75, trim: true, indent: ''});
|
||||
const frontmatter = Math.random() <= frontMatterPercent / 100.0 ? newFrontMatter({
|
||||
publishPercent: publishPercent,
|
||||
aliasPercent: aliasPercent,
|
||||
title: title,
|
||||
minTags: minTags,
|
||||
maxTags: maxTags
|
||||
}) : '';
|
||||
return {"title": title, "note": frontmatter + wrapped};
|
||||
}
|
||||
207
main.ts
207
main.ts
|
|
@ -1,8 +1,6 @@
|
|||
import {App, Editor, MarkdownView, Modal, Notice, Plugin, PluginSettingTab, Setting, Vault} from 'obsidian';
|
||||
import {loremIpsum} from "lorem-ipsum";
|
||||
import {lineNumbers} from "@codemirror/view";
|
||||
|
||||
let wrap = require('word-wrap');
|
||||
import {App, Modal, Notice, Plugin, PluginSettingTab, Setting, SliderComponent} from 'obsidian';
|
||||
import {newLoremNote} from "./loremnotes";
|
||||
import {fillVault} from "./vault";
|
||||
|
||||
/*
|
||||
Defaults for the plugin:
|
||||
|
|
@ -14,194 +12,6 @@ let wrap = require('word-wrap');
|
|||
which might be interesting for linguistic-related plugins
|
||||
*/
|
||||
|
||||
interface INoteGenerator {
|
||||
title?: string; // ''
|
||||
minTitleWords?: number; // 4
|
||||
maxTitleWords?: number; // 10
|
||||
minSentenceWords?: number; // 5
|
||||
maxSentenceWords?: number; // 20
|
||||
minSentences?: number; // 4
|
||||
maxSentences?: number; // 20
|
||||
minParagraphs?: number; // 1
|
||||
maxParagraphs?: number; // 10
|
||||
minTags?: number; // 0
|
||||
maxTags?: number; // 5
|
||||
aliasPercent?: number; // 10
|
||||
publishPercent?: number; // 50
|
||||
frontMatterPercent?: number; // 90
|
||||
alltitles?: Array<string>; // []
|
||||
emptyFilesPercent?: number; // 3
|
||||
orphanedNotesPercent?: number; // 5
|
||||
leafNotesPercent?: number; // 25
|
||||
minLinks?: number; // 1
|
||||
maxLinks?: number; // 10
|
||||
}
|
||||
|
||||
const tags = Array.from(new Set(loremIpsum({count: 100, units: "words"})
|
||||
.split(' ').map((word) => {
|
||||
return `#${word}`
|
||||
})))
|
||||
|
||||
const cssclasses = Array.from(new Set(loremIpsum({count: 100, units: "words"})
|
||||
.split(' ')));
|
||||
|
||||
function randomInt(min: number, max: number, power: number = 1): number {
|
||||
return Math.floor(Math.pow(Math.random() * (max - min + 1), power)) + min;
|
||||
}
|
||||
|
||||
function randomSubset(arr: Array<any>, size: number): Array<any> {
|
||||
let shuffled = arr.slice(0), i = arr.length, temp, index;
|
||||
while (i--) {
|
||||
index = Math.floor((i + 1) * Math.random());
|
||||
temp = shuffled[index];
|
||||
shuffled[index] = shuffled[i];
|
||||
shuffled[i] = temp;
|
||||
}
|
||||
return shuffled.slice(0, size);
|
||||
}
|
||||
|
||||
function randomChoice(arr: Array<any>): any {
|
||||
return arr[randomInt(0, arr.length - 1)];
|
||||
}
|
||||
|
||||
function randomDateInRange(start: Date, end: Date): Date {
|
||||
const range = end.getTime() - start.getTime();
|
||||
const newMs = randomInt(0, range);
|
||||
return new Date(start.getTime() + newMs);
|
||||
}
|
||||
|
||||
function newFrontMatter({publishPercent=50, aliasPercent=10, title='', minTags=0, maxTags=5}: INoteGenerator): string {
|
||||
const cssclass = cssclasses[randomInt(0, cssclasses.length - 1)];
|
||||
const publish = Math.random() >= publishPercent / 100.0 ? "true" : " false";
|
||||
// generate aliases here
|
||||
let alias = '';
|
||||
const aliasresult = Math.random();
|
||||
if (aliasresult <= aliasPercent / 100.0) {
|
||||
alias = title.split(' ').map((word) => {
|
||||
return word[0]
|
||||
}).join('');
|
||||
}
|
||||
// generate tags here
|
||||
const numTags = randomInt(minTags, maxTags);
|
||||
const chosenTags = randomSubset(tags, numTags).join(',')
|
||||
const status = randomChoice(["Backlog", "In progress", "Done"]);
|
||||
const published = randomChoice([0, 1]);
|
||||
const weight = randomInt(1, 100);
|
||||
const start = new Date(Date.now());
|
||||
const end = new Date(start.getTime() + 31536000000); // magic number, milliseconds in a year
|
||||
const duedate = randomDateInRange(start, end);
|
||||
|
||||
return `---\ntags: ${chosenTags}\ncssclass: ${cssclass}\n`
|
||||
+ `aliases: ${alias}\npublish: ${publish}\n`
|
||||
+ `status: ${status}\npublished: ${published}\n`
|
||||
+ `due: ${duedate.toISOString().substring(0, 10)}\n`
|
||||
+ `weight: ${weight}\n`
|
||||
+ `---\n`;
|
||||
}
|
||||
|
||||
function newTitle(titleWords: number): string {
|
||||
return loremIpsum({count: titleWords, units: "words"}).toLowerCase().split(' ').map((word) => {
|
||||
return word[0].toUpperCase() + word.substring(1)}).join(' ');
|
||||
}
|
||||
function newLoremNote({title = '', minTitleWords = 4, maxTitleWords = 10, minSentenceWords = 5, maxSentenceWords = 20,
|
||||
minSentences = 4, maxSentences = 20, minParagraphs = 1, maxParagraphs = 10, minTags = 0, maxTags = 5,
|
||||
aliasPercent = 10, publishPercent = 50,
|
||||
frontMatterPercent = 90, alltitles=[], minLinks=1, maxLinks=10}: INoteGenerator): { note: string, title: string } {
|
||||
const titleWords = randomInt(minTitleWords, maxTitleWords);
|
||||
const numParagraphs = randomInt(minParagraphs, maxParagraphs, 4);
|
||||
if (title.length == 0) {
|
||||
title = newTitle(titleWords);
|
||||
}
|
||||
let text = loremIpsum({
|
||||
count: numParagraphs, units: "paragraphs", format: "plain",
|
||||
paragraphLowerBound: minSentences, paragraphUpperBound: maxSentences,
|
||||
sentenceLowerBound: minSentenceWords, sentenceUpperBound: maxSentenceWords,
|
||||
suffix: "\n\n"
|
||||
});
|
||||
if (alltitles?.length > 0) {
|
||||
const numberofLinks = randomInt(minLinks, maxLinks);
|
||||
const linkedTitles = randomSubset(alltitles, numberofLinks);
|
||||
let paragraphs = text.split('\n');
|
||||
for (let i=0; i<linkedTitles.length; i++) {
|
||||
let paragraphNumber = randomInt(0, paragraphs.length);
|
||||
paragraphs[paragraphNumber] = `${paragraphs[paragraphNumber]}[[${linkedTitles[i]}]]`
|
||||
}
|
||||
text = paragraphs.join('\n');
|
||||
}
|
||||
const wrapped = wrap(text, {width: 75, trim: true, indent: ''});
|
||||
const frontmatter = Math.random() <= frontMatterPercent / 100.0 ? newFrontMatter({publishPercent:publishPercent, aliasPercent:aliasPercent, title:title, minTags:minTags, maxTags:maxTags}) : '';
|
||||
return {"title": title, "note": frontmatter + wrapped};
|
||||
}
|
||||
|
||||
async function fillVault(maxNotes: number=100, notice: Notice, vault: Vault, {emptyFilesPercent=3,
|
||||
orphanedNotesPercent=5, leafNotesPercent=25, minTitleWords=4, maxTitleWords=10,
|
||||
minSentenceWords=5, maxSentenceWords=20, minSentences=4, maxSentences=20, minParagraphs=1, maxParagraphs=10,
|
||||
minTags=0, maxTags=5, aliasPercent=10, publishPercent=50, frontMatterPercent=90,
|
||||
minLinks=1, maxLinks=10}: INoteGenerator) {
|
||||
let titles = Array.apply(null, Array(maxNotes)).map(function () {});
|
||||
await notice.setMessage("Generating titles");
|
||||
for (let i=0; i<maxNotes; i++) {
|
||||
let titleWords = randomInt(minTitleWords, maxTitleWords);
|
||||
titles[i] = newTitle(titleWords);
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Empty Notes");
|
||||
let generated = 0;
|
||||
const emptyFilesCount = Math.floor(maxNotes*(emptyFilesPercent/100.0));
|
||||
for (let i=0; i<emptyFilesCount; i++) {
|
||||
await vault.create(`${titles[generated]}.md`, '');
|
||||
generated++;
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Orphaned Notes");
|
||||
const orphanedNotesCount = Math.floor(maxNotes*(orphanedNotesPercent/100.0));
|
||||
for (let i=0; i<orphanedNotesCount; i++) {
|
||||
if ((i>=1) && (i%20==0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({title: titles[generated],
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
generated++;
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Leaf Notes");
|
||||
const linksBegin = generated;
|
||||
const leafCount = Math.floor(maxNotes*(leafNotesPercent/100.0));
|
||||
for (let i=0; i<leafCount; i++) {
|
||||
if ((i>=1) && (i%20==0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({title: titles[generated], alltitles: titles.slice(linksBegin),
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
generated++;
|
||||
}
|
||||
|
||||
for (let i=generated; i < maxNotes; i++) {
|
||||
if ((i>=1) && (i%20==0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({title: titles[i], alltitles: titles.slice(linksBegin),
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
}
|
||||
await notice.setMessage(`Vault generated ${maxNotes} notes`);
|
||||
setTimeout(() => notice.hide(), 4000);
|
||||
}
|
||||
|
||||
interface TestingVaultPluginSettings {
|
||||
mySetting: string;
|
||||
}
|
||||
|
|
@ -241,9 +51,7 @@ export default class TestingVaultPlugin extends Plugin {
|
|||
id: 'open-sample-modal-simple',
|
||||
name: 'Open sample modal (simple)',
|
||||
callback: () => {
|
||||
new SampleModal(this.app).open();
|
||||
let note = newLoremNote({});
|
||||
this.app.vault.create(`${note.title}.md`, note.note);
|
||||
new TestingVaultModal(this.app).open();
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
|
@ -261,7 +69,7 @@ export default class TestingVaultPlugin extends Plugin {
|
|||
id: 'testing-vault-fill-vault',
|
||||
name: 'Make a group of randomized notes in your vault',
|
||||
callback: () => {
|
||||
const maxnotes=100;
|
||||
const maxnotes = 100;
|
||||
let task_status = new Notice('Generating new testing vault', 0);
|
||||
fillVault(maxnotes, task_status, this.app.vault, {});
|
||||
}
|
||||
|
|
@ -334,14 +142,15 @@ export default class TestingVaultPlugin extends Plugin {
|
|||
}
|
||||
}
|
||||
|
||||
class SampleModal extends Modal {
|
||||
class TestingVaultModal extends Modal {
|
||||
constructor(app: App) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
onOpen() {
|
||||
const {contentEl} = this;
|
||||
contentEl.setText('Woah!');
|
||||
const slider = new SliderComponent(contentEl);
|
||||
slider.setLimits(1, 100, 1);
|
||||
}
|
||||
|
||||
onClose() {
|
||||
|
|
|
|||
317
package-lock.json
generated
317
package-lock.json
generated
|
|
@ -1,15 +1,16 @@
|
|||
{
|
||||
"name": "obsidian-sample-plugin",
|
||||
"name": "obsidian-testing-vault",
|
||||
"version": "1.0.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "obsidian-sample-plugin",
|
||||
"name": "obsidian-testing-vault",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"lorem-ipsum": "^2.0.8",
|
||||
"svelte": "^3.55.1",
|
||||
"word-wrap": "^1.2.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
@ -642,118 +643,6 @@
|
|||
"esbuild-windows-arm64": "0.14.47"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-android-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-android-64/-/esbuild-android-64-0.14.47.tgz",
|
||||
"integrity": "sha512-R13Bd9+tqLVFndncMHssZrPWe6/0Kpv2/dt4aA69soX4PRxlzsVpCvoJeFE8sOEoeVEiBkI0myjlkDodXlHa0g==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-android-arm64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-android-arm64/-/esbuild-android-arm64-0.14.47.tgz",
|
||||
"integrity": "sha512-OkwOjj7ts4lBp/TL6hdd8HftIzOy/pdtbrNA4+0oVWgGG64HrdVzAF5gxtJufAPOsEjkyh1oIYvKAUinKKQRSQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"android"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-darwin-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-darwin-64/-/esbuild-darwin-64-0.14.47.tgz",
|
||||
"integrity": "sha512-R6oaW0y5/u6Eccti/TS6c/2c1xYTb1izwK3gajJwi4vIfNs1s8B1dQzI1UiC9T61YovOQVuePDcfqHLT3mUZJA==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-darwin-arm64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-darwin-arm64/-/esbuild-darwin-arm64-0.14.47.tgz",
|
||||
"integrity": "sha512-seCmearlQyvdvM/noz1L9+qblC5vcBrhUaOoLEDDoLInF/VQ9IkobGiLlyTPYP5dW1YD4LXhtBgOyevoIHGGnw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"darwin"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-freebsd-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-freebsd-64/-/esbuild-freebsd-64-0.14.47.tgz",
|
||||
"integrity": "sha512-ZH8K2Q8/Ux5kXXvQMDsJcxvkIwut69KVrYQhza/ptkW50DC089bCVrJZZ3sKzIoOx+YPTrmsZvqeZERjyYrlvQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-freebsd-arm64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-freebsd-arm64/-/esbuild-freebsd-arm64-0.14.47.tgz",
|
||||
"integrity": "sha512-ZJMQAJQsIOhn3XTm7MPQfCzEu5b9STNC+s90zMWe2afy9EwnHV7Ov7ohEMv2lyWlc2pjqLW8QJnz2r0KZmeAEQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"freebsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-32": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-32/-/esbuild-linux-32-0.14.47.tgz",
|
||||
"integrity": "sha512-FxZOCKoEDPRYvq300lsWCTv1kcHgiiZfNrPtEhFAiqD7QZaXrad8LxyJ8fXGcWzIFzRiYZVtB3ttvITBvAFhKw==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.14.47.tgz",
|
||||
|
|
@ -770,198 +659,6 @@
|
|||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-arm": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-arm/-/esbuild-linux-arm-0.14.47.tgz",
|
||||
"integrity": "sha512-ZGE1Bqg/gPRXrBpgpvH81tQHpiaGxa8c9Rx/XOylkIl2ypLuOcawXEAo8ls+5DFCcRGt/o3sV+PzpAFZobOsmA==",
|
||||
"cpu": [
|
||||
"arm"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-arm64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-arm64/-/esbuild-linux-arm64-0.14.47.tgz",
|
||||
"integrity": "sha512-ywfme6HVrhWcevzmsufjd4iT3PxTfCX9HOdxA7Hd+/ZM23Y9nXeb+vG6AyA6jgq/JovkcqRHcL9XwRNpWG6XRw==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-mips64le": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-mips64le/-/esbuild-linux-mips64le-0.14.47.tgz",
|
||||
"integrity": "sha512-mg3D8YndZ1LvUiEdDYR3OsmeyAew4MA/dvaEJxvyygahWmpv1SlEEnhEZlhPokjsUMfRagzsEF/d/2XF+kTQGg==",
|
||||
"cpu": [
|
||||
"mips64el"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-ppc64le": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-ppc64le/-/esbuild-linux-ppc64le-0.14.47.tgz",
|
||||
"integrity": "sha512-WER+f3+szmnZiWoK6AsrTKGoJoErG2LlauSmk73LEZFQ/iWC+KhhDsOkn1xBUpzXWsxN9THmQFltLoaFEH8F8w==",
|
||||
"cpu": [
|
||||
"ppc64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-riscv64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-riscv64/-/esbuild-linux-riscv64-0.14.47.tgz",
|
||||
"integrity": "sha512-1fI6bP3A3rvI9BsaaXbMoaOjLE3lVkJtLxsgLHqlBhLlBVY7UqffWBvkrX/9zfPhhVMd9ZRFiaqXnB1T7BsL2g==",
|
||||
"cpu": [
|
||||
"riscv64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-linux-s390x": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-linux-s390x/-/esbuild-linux-s390x-0.14.47.tgz",
|
||||
"integrity": "sha512-eZrWzy0xFAhki1CWRGnhsHVz7IlSKX6yT2tj2Eg8lhAwlRE5E96Hsb0M1mPSE1dHGpt1QVwwVivXIAacF/G6mw==",
|
||||
"cpu": [
|
||||
"s390x"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"linux"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-netbsd-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-netbsd-64/-/esbuild-netbsd-64-0.14.47.tgz",
|
||||
"integrity": "sha512-Qjdjr+KQQVH5Q2Q1r6HBYswFTToPpss3gqCiSw2Fpq/ua8+eXSQyAMG+UvULPqXceOwpnPo4smyZyHdlkcPppQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"netbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-openbsd-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-openbsd-64/-/esbuild-openbsd-64-0.14.47.tgz",
|
||||
"integrity": "sha512-QpgN8ofL7B9z8g5zZqJE+eFvD1LehRlxr25PBkjyyasakm4599iroUpaj96rdqRlO2ShuyqwJdr+oNqWwTUmQw==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"openbsd"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-sunos-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-sunos-64/-/esbuild-sunos-64-0.14.47.tgz",
|
||||
"integrity": "sha512-uOeSgLUwukLioAJOiGYm3kNl+1wJjgJA8R671GYgcPgCx7QR73zfvYqXFFcIO93/nBdIbt5hd8RItqbbf3HtAQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"sunos"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-32": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-32/-/esbuild-windows-32-0.14.47.tgz",
|
||||
"integrity": "sha512-H0fWsLTp2WBfKLBgwYT4OTfFly4Im/8B5f3ojDv1Kx//kiubVY0IQunP2Koc/fr/0wI7hj3IiBDbSrmKlrNgLQ==",
|
||||
"cpu": [
|
||||
"ia32"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.14.47.tgz",
|
||||
"integrity": "sha512-/Pk5jIEH34T68r8PweKRi77W49KwanZ8X6lr3vDAtOlH5EumPE4pBHqkCUdELanvsT14yMXLQ/C/8XPi1pAtkQ==",
|
||||
"cpu": [
|
||||
"x64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/esbuild-windows-arm64": {
|
||||
"version": "0.14.47",
|
||||
"resolved": "https://registry.npmjs.org/esbuild-windows-arm64/-/esbuild-windows-arm64-0.14.47.tgz",
|
||||
"integrity": "sha512-HFSW2lnp62fl86/qPQlqw6asIwCnEsEoNIL1h2uVMgakddf+vUuMcCbtUY1i8sst7KkgHrVKCJQB33YhhOweCQ==",
|
||||
"cpu": [
|
||||
"arm64"
|
||||
],
|
||||
"dev": true,
|
||||
"optional": true,
|
||||
"os": [
|
||||
"win32"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
}
|
||||
},
|
||||
"node_modules/escape-string-regexp": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz",
|
||||
|
|
@ -2009,6 +1706,14 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/svelte": {
|
||||
"version": "3.55.1",
|
||||
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.55.1.tgz",
|
||||
"integrity": "sha512-S+87/P0Ve67HxKkEV23iCdAh/SX1xiSfjF1HOglno/YTbSTW7RniICMCofWGdJJbdjw3S+0PfFb1JtGfTXE0oQ==",
|
||||
"engines": {
|
||||
"node": ">= 8"
|
||||
}
|
||||
},
|
||||
"node_modules/text-table": {
|
||||
"version": "0.2.0",
|
||||
"resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "obsidian-sample-plugin",
|
||||
"name": "obsidian-testing-vault",
|
||||
"version": "1.0.0",
|
||||
"description": "This is a sample plugin for Obsidian (https://obsidian.md)",
|
||||
"description": "This Obsidian plugin allows the user to generate a vault randomly, complete with orphaned notes, empty notes, and linked notes.",
|
||||
"main": "main.js",
|
||||
"scripts": {
|
||||
"dev": "node esbuild.config.mjs",
|
||||
|
|
@ -9,7 +9,7 @@
|
|||
"version": "node version-bump.mjs && git add manifest.json versions.json"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"author": "Michael J. Pedersen <m.pedersen@icelus.org>",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/node": "^16.11.6",
|
||||
|
|
@ -23,6 +23,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"lorem-ipsum": "^2.0.8",
|
||||
"svelte": "^3.55.1",
|
||||
"word-wrap": "^1.2.3"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
24
random.ts
Normal file
24
random.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
export function randomInt(min: number, max: number, power: number = 1): number {
|
||||
return Math.floor(Math.pow(Math.random() * (max - min + 1), power)) + min;
|
||||
}
|
||||
|
||||
export function randomSubset(arr: Array<any>, size: number): Array<any> {
|
||||
let shuffled = arr.slice(0), i = arr.length, temp, index;
|
||||
while (i--) {
|
||||
index = Math.floor((i + 1) * Math.random());
|
||||
temp = shuffled[index];
|
||||
shuffled[index] = shuffled[i];
|
||||
shuffled[i] = temp;
|
||||
}
|
||||
return shuffled.slice(0, size);
|
||||
}
|
||||
|
||||
export function randomChoice(arr: Array<any>): any {
|
||||
return arr[randomInt(0, arr.length - 1)];
|
||||
}
|
||||
|
||||
export function randomDateInRange(start: Date, end: Date): Date {
|
||||
const range = end.getTime() - start.getTime();
|
||||
const newMs = randomInt(0, range);
|
||||
return new Date(start.getTime() + newMs);
|
||||
}
|
||||
94
vault.ts
Normal file
94
vault.ts
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
import {Notice, Vault} from "obsidian";
|
||||
import {INoteGenerator, newLoremNote, newTitle} from "./loremnotes";
|
||||
import {randomInt} from "./random";
|
||||
|
||||
export async function fillVault(maxNotes: number = 100, notice: Notice, vault: Vault, {
|
||||
emptyFilesPercent = 3,
|
||||
orphanedNotesPercent = 5,
|
||||
leafNotesPercent = 25,
|
||||
minTitleWords = 4,
|
||||
maxTitleWords = 10,
|
||||
minSentenceWords = 5,
|
||||
maxSentenceWords = 20,
|
||||
minSentences = 4,
|
||||
maxSentences = 20,
|
||||
minParagraphs = 1,
|
||||
maxParagraphs = 10,
|
||||
minTags = 0,
|
||||
maxTags = 5,
|
||||
aliasPercent = 10,
|
||||
publishPercent = 50,
|
||||
frontMatterPercent = 90,
|
||||
minLinks = 1,
|
||||
maxLinks = 10
|
||||
}: INoteGenerator) {
|
||||
let titles = Array.apply(null, Array(maxNotes)).map(function () {
|
||||
});
|
||||
await notice.setMessage("Generating titles");
|
||||
for (let i = 0; i < maxNotes; i++) {
|
||||
let titleWords = randomInt(minTitleWords, maxTitleWords);
|
||||
titles[i] = newTitle(titleWords);
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Empty Notes");
|
||||
let generated = 0;
|
||||
const emptyFilesCount = Math.floor(maxNotes * (emptyFilesPercent / 100.0));
|
||||
for (let i = 0; i < emptyFilesCount; i++) {
|
||||
await vault.create(`${titles[generated]}.md`, '');
|
||||
generated++;
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Orphaned Notes");
|
||||
const orphanedNotesCount = Math.floor(maxNotes * (orphanedNotesPercent / 100.0));
|
||||
for (let i = 0; i < orphanedNotesCount; i++) {
|
||||
if ((i >= 1) && (i % 20 == 0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({
|
||||
title: titles[generated],
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks
|
||||
});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
generated++;
|
||||
}
|
||||
|
||||
await notice.setMessage("Generating Leaf Notes");
|
||||
const linksBegin = generated;
|
||||
const leafCount = Math.floor(maxNotes * (leafNotesPercent / 100.0));
|
||||
for (let i = 0; i < leafCount; i++) {
|
||||
if ((i >= 1) && (i % 20 == 0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({
|
||||
title: titles[generated], alltitles: titles.slice(linksBegin),
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks
|
||||
});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
generated++;
|
||||
}
|
||||
|
||||
for (let i = generated; i < maxNotes; i++) {
|
||||
if ((i >= 1) && (i % 20 == 0)) {
|
||||
await notice.setMessage(`Progress: Created ${i}/${maxNotes} notes so far`);
|
||||
}
|
||||
let note = newLoremNote({
|
||||
title: titles[i], alltitles: titles.slice(linksBegin),
|
||||
minTitleWords: minLinks, maxTitleWords: maxTitleWords, minSentenceWords: minSentenceWords,
|
||||
maxSentenceWords: maxSentenceWords, minSentences: minSentences, maxSentences: maxSentences,
|
||||
minParagraphs: minParagraphs, maxParagraphs: maxParagraphs, minTags: minTags, maxTags: maxTags,
|
||||
aliasPercent: aliasPercent, publishPercent: publishPercent, frontMatterPercent: frontMatterPercent,
|
||||
minLinks: minLinks, maxLinks: maxLinks
|
||||
});
|
||||
await vault.create(`${note.title}.md`, note.note);
|
||||
}
|
||||
await notice.setMessage(`Vault generated ${maxNotes} notes`);
|
||||
setTimeout(() => notice.hide(), 4000);
|
||||
}
|
||||
Loading…
Reference in a new issue