March 28 2023

mj v5 is really good. check out those shadows! check out the detail of the reliefs! (notice: my publishing process automatically compresses images for the web so this image is actually higher quality in its original form)

mj v5 gothic home.png

Gen-1 has me reminiscing of using Runway back in 2019 (b4 generative art was cool!)

runway gen 1 release.png

Code

A quick improvement to the rename image code for the Ghost Publish plugin. Now has an optional modal for file renaming before it moves folders!

// modal
export const renameFileModal = async (
	app: App,
	vault: Vault,
	fileName: string,
) => {
	const folderCreationModal = new FileRenameModal(
		app,
		fileName
	);

	folderCreationModal.open();
	const result = await folderCreationModal.waitForModalValue();

    return result;
};

class FileRenameModal extends Modal {
	result: string;
	fileName: string;
	modalPromise: Promise<string>;
	resolveModalPromise: (value: string) => void;

	constructor(
		app: App,
		fileName: string
	) {
		super(app);

		this.result = fileName;
		this.modalPromise = new Promise((resolve) => {
			this.resolveModalPromise = resolve;
		});
	}

	onOpen() {
		const { contentEl } = this;

		contentEl.createEl("h2", {
			text: `Rename image`,
		});

        new Setting(contentEl).addText((text) =>
			text
				.setPlaceholder("File Name")
				.setValue(this.fileName)
				.onChange((value) => {
					this.fileName = value;
				})
		);

		new Setting(contentEl).addButton((btn) =>
			btn
				.setButtonText("Submit")
				.setTooltip("Rename File")
				.setCta()
				.onClick(() => {
					this.resolveModalPromise(this.fileName);
					this.close();
				})
		);


	}

	waitForModalValue() {
		return this.modalPromise;
	}

	onClose() {
		const { contentEl } = this;
		contentEl.empty();
	}
}

// in addCommand()...

let renamedFile = sourceFile.name;

const result = await renameFileModal(
	this.app,
	this.app.vault,
	sourceFile.name
);

if (result) {
	if (result !== sourceFile.name && result !== "") {
		renamedFile = result;
	}
} else {
	return;
}


this.app.fileManager.renameFile(
	sourceFile,
	`${newParentFolderName}/${renamedFile}.png`
);



console.log(
	`Successfully moved/renamed ${fileName} to ${newParentFolderName}/${renamedFile}.png`
);


bramadams.dev is a reader-supported published Zettelkasten. Both free and paid subscriptions are available. If you want to support my work, the best way is by taking out a paid subscription.

Tweets