Use month week and random name
This commit is contained in:
parent
f75037547f
commit
9c65740da2
1101
adjectives.ts
Normal file
1101
adjectives.ts
Normal file
File diff suppressed because it is too large
Load diff
65
main.ts
65
main.ts
|
@ -7,6 +7,9 @@ import {
|
|||
Vault,
|
||||
Notice,
|
||||
} from "obsidian";
|
||||
import { nouns } from "./nouns.js";
|
||||
import { adjectives } from "./adjectives.js";
|
||||
import { capitalize, sample } from "lodash-es";
|
||||
|
||||
interface ScrapsPluginSettings {
|
||||
scrapsRootDir: string;
|
||||
|
@ -16,10 +19,16 @@ interface ScrapsPluginSettings {
|
|||
|
||||
const DEFAULT_SETTINGS: ScrapsPluginSettings = {
|
||||
scrapsRootDir: "_Scraps",
|
||||
scrapsPathFormat: "MM MMM/DD",
|
||||
scrapsPathFormat: "MM MMM/R",
|
||||
scrapsFileName: "ddd MMM DD hhmmssa",
|
||||
};
|
||||
|
||||
function getFormattedDate(format: string): string {
|
||||
const momentFormatted = moment().format(format);
|
||||
const currentWeek = Math.ceil(moment().date() / 7);
|
||||
return momentFormatted.replace("R", `Week ${currentWeek}`);
|
||||
}
|
||||
|
||||
async function mkdirp(vault: Vault, folderPath: string): Promise<void> {
|
||||
const pathParts = folderPath.split("/");
|
||||
|
||||
|
@ -46,19 +55,27 @@ export default class ScrapsPlugin extends Plugin {
|
|||
settings: ScrapsPluginSettings;
|
||||
|
||||
async ensureScrapDir(): Promise<string> {
|
||||
const pathname = `${this.settings.scrapsRootDir}/${moment().format(
|
||||
this.settings.scrapsPathFormat
|
||||
)}`;
|
||||
const pathname = `${this.getScrapDir()}`;
|
||||
|
||||
await mkdirp(this.app.vault, pathname);
|
||||
|
||||
return pathname;
|
||||
}
|
||||
|
||||
getScrapFilePath(): string {
|
||||
return `${this.settings.scrapsRootDir}/${moment().format(
|
||||
getScrapDir(): string {
|
||||
return `${this.settings.scrapsRootDir}/${getFormattedDate(
|
||||
this.settings.scrapsPathFormat
|
||||
)}/${moment().format(this.settings.scrapsFileName)}.md`;
|
||||
)}`;
|
||||
}
|
||||
|
||||
getScrapFileName(): string {
|
||||
const adj = capitalize(sample(adjectives));
|
||||
const noun = capitalize(sample(nouns));
|
||||
return `Scrap ${adj} ${noun}.md`;
|
||||
}
|
||||
|
||||
getScrapFilePath(): string {
|
||||
return `${this.getScrapDir()}/${this.getScrapFileName()}`;
|
||||
}
|
||||
|
||||
async createScrap() {
|
||||
|
@ -71,6 +88,22 @@ export default class ScrapsPlugin extends Plugin {
|
|||
await this.app.workspace.getLeaf(false).openFile(newScrap);
|
||||
}
|
||||
|
||||
async convertToScrap() {
|
||||
const currentFile = this.app.workspace.getActiveFile();
|
||||
|
||||
if (currentFile === null) {
|
||||
new Notice("No file is currently open");
|
||||
return;
|
||||
}
|
||||
|
||||
await this.ensureScrapDir();
|
||||
|
||||
await this.app.fileManager.renameFile(
|
||||
currentFile,
|
||||
this.getScrapFilePath()
|
||||
);
|
||||
}
|
||||
|
||||
async onload() {
|
||||
await this.loadSettings();
|
||||
this.addSettingTab(new ScrapsSettingTab(this.app, this));
|
||||
|
@ -92,21 +125,11 @@ export default class ScrapsPlugin extends Plugin {
|
|||
id: "scraps-convert",
|
||||
name: "Scraps: Convert current file to Scrap",
|
||||
icon: "file-plus",
|
||||
editorCallback: async () => {
|
||||
const currentFile = this.app.workspace.getActiveFile();
|
||||
editorCallback: async () => this.convertToScrap(),
|
||||
});
|
||||
|
||||
if (currentFile === null) {
|
||||
new Notice("No file is currently open");
|
||||
return;
|
||||
}
|
||||
|
||||
await this.ensureScrapDir();
|
||||
|
||||
await this.app.fileManager.renameFile(
|
||||
currentFile,
|
||||
this.getScrapFilePath()
|
||||
);
|
||||
},
|
||||
this.addRibbonIcon("file-plus", "Convert file to Scrap", async () => {
|
||||
this.convertToScrap();
|
||||
});
|
||||
|
||||
this.addCommand({
|
||||
|
|
26
package-lock.json
generated
26
package-lock.json
generated
|
@ -9,11 +9,13 @@
|
|||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "0.17.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
|
@ -581,6 +583,23 @@
|
|||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash": {
|
||||
"version": "4.17.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.12.tgz",
|
||||
"integrity": "sha512-sviUmCE8AYdaF/KIHLDJBQgeYzPBI0vf/17NaYehBJfYD1j6/L95Slh07NlyK2iNyBNaEkb3En2jRt+a8y3xZQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/lodash-es": {
|
||||
"version": "4.17.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
|
||||
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@types/lodash": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/node": {
|
||||
"version": "16.18.114",
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-16.18.114.tgz",
|
||||
|
@ -1779,6 +1798,13 @@
|
|||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/lodash-es": {
|
||||
"version": "4.17.21",
|
||||
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
|
||||
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/lodash.merge": {
|
||||
"version": "4.6.2",
|
||||
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",
|
||||
|
|
|
@ -12,11 +12,13 @@
|
|||
"author": "",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@types/lodash-es": "^4.17.12",
|
||||
"@types/node": "^16.11.6",
|
||||
"@typescript-eslint/eslint-plugin": "5.29.0",
|
||||
"@typescript-eslint/parser": "5.29.0",
|
||||
"builtin-modules": "3.3.0",
|
||||
"esbuild": "0.17.3",
|
||||
"lodash-es": "^4.17.21",
|
||||
"obsidian": "latest",
|
||||
"tslib": "2.4.0",
|
||||
"typescript": "4.7.4"
|
||||
|
|
Loading…
Reference in a new issue