I’m using the “adapted” script below which meets my needs.
However, I’d like to add a tag where variable “name” would have the space between names replaced by “_”. Is this possible?
Eg. If name = John Doe ==> the variable would be John_Doe
Any help? Thanks!!
let f = () => {
// prompt for title and tags
let p = Prompt.create();
p.title = "New book? :)"
p.message = "Let's go!"
p.addTextField("title", "Book's title", "");
p.addTextField("name", "Author's name", "");
p.addTextField("tags", "tags", "books , smartnotes");
p.addButton("Create");
if (!p.show()) { return false; }
let tags = p.fieldValues["tags"].split(",").map(s => s.trim());
let name = p.fieldValues["name"];
let title = p.fieldValues["title"];
if (tags.length == 0 || name.length == 0) {
alert("Name and at least one tag are required to create a project.");
return false;
}
let d = Draft.create();
for (let tag of tags) {
d.addTag(tag);
}
d.addTag(name)
d.content = `# ${title}
by [[${name}]]
# `;
d.isFlagged = false;
d.update();
editor.load(d);
return true;
}
if (!f()) {
context.cancel();
}