Skip to content

Instantly share code, notes, and snippets.

@jhilker98
Created November 8, 2023 21:59
Show Gist options
  • Save jhilker98/e980cf5200b7a98b6a761b666e54d3b8 to your computer and use it in GitHub Desktop.
Save jhilker98/e980cf5200b7a98b6a761b666e54d3b8 to your computer and use it in GitHub Desktop.
//<%*
const app = this.app;
const dv = app.plugins.plugins["dataview"].api;
// general metadata
const dob = await tp.user.chooseDate(tp, "Date of Birth");
const characterGender = await tp.system.suggester(["Male", "Female", "Non-binary"], ["Male", "Female", "Non-binary"], false, "Character's gender")
const characterOrientation = await tp.system.suggester(["Straight", "Gay", "Bi", "Unknown"], ["Heterosexual", "Homosexual", "Bisexual", "N/A"], false, "Character's sexual orientation")
const characterRole = await tp.system.suggester(["Main Character", "Major Character (Non-POV)", "Side Character", "Extra Character", "Antagonist"], ["_Main", "_Major", "_Side", "_Extra", "_Antagonist"], false, "Character's role in story")
// process if character is dead
let isDead = await tp.system.suggester(["True", "False"], [true, false], false, "Is the character dead?");
// process first appearance
let stories = dv.pages("#Story").file.sort(n => n.frontmatter.longform.title);
let names = stories.name;
let titles = stories.frontmatter.title;
let links = stories.link;
let firstAppChoice = await tp.system.suggester(titles, links, false, "First Appearance");
const firstApp = dv.page(firstAppChoice.path)
if (isDead) {
let dod = await tp.user.chooseDate(tp, "Date of Death")
await app.fileManager.processFrontMatter(tp.config.active_file, (fm) => {
fm.dob = dob
fm.Gender = characterGender
fm.Sexuality = characterOrientation
fm.Role = characterRole
fm.dead = isDead
fm.dod = dod
fm.description = ""
fm.firstAppearance = `[[${firstAppChoice.path}|${firstApp.file.frontmatter.title}]]`
fm.tags = [
"inbox",
`Character/${characterRole}`,
]
})
} else {
await app.fileManager.processFrontMatter(tp.config.target_file, (fm) => {
fm.dob = dob
fm.Gender = characterGender
fm.Sexuality = characterOrientation
fm.Role = characterRole
fm.dead = isDead
fm.description = ""
fm.firstAppearance = `[[${firstAppChoice.path}|${firstApp.file.frontmatter.title}]]`
fm.tags = [
"inbox",
`Character/${characterRole}`,
]})}
// %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment