Giter Club home page Giter Club logo

Comments (3)

AlisAquilae avatar AlisAquilae commented on June 20, 2024 1

I changed it to this:

async function newNote () {
    // Load Templater API
    const templater = app.plugins.plugins["templater-obsidian"].templater;
    const tp = templater.current_functions_object;

    let course;
    let noteType;
    let noteSubType;
    
    // Clear file path
    await tp.file.move("/" + tp.file.title);
    
    // Filter out media files and send them to their own folder
    if (tp.file.path(true).includes(".jpg") || tp.file.path(true).includes(".png")) {
        (await tp.file.move("/Media/" + tp.file.title));
    } else {
        // Suggester for course selection
        course = await tp.system.suggester(["Water 1", "Water 2"], ["Water 1", "Water 2",], true);

        // Find note type base
        noteType = await tp.system.suggester(["Courses", "Notes", "Terminology", "Questions"], ["Courses", "Notes", "Terminology", "Questions"], true);

        // Start conditional based on noteType
        if (noteType == 'Courses') {
            await tp.file.move("/" + noteType + "/" + tp.file.title);
        } else if (noteType == 'Terminology') {
            noteSubType = await tp.system.suggester(["Concepts", "Events", "Theories"], ["Concepts", "Events", "Theories"], true);
            await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
        } else if (noteType == 'Questions') {
            noteSubType = await tp.system.suggester(["Practice Questions", "Questions of Understanding"], ["Practice Questions", "Questions of Understanding"], true);
            await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
        } else if (noteType == 'Notes') {
            noteSubType = await tp.system.suggester(["Lecture Notes", "Literature Notes", "Summaries", "Project Notes", "Meeting Notes", "Writing Notes"], ["Lecture Notes", "Literature Notes", "Summaries", "Project Notes", "Meeting Notes", "Writing Notes"], true);
            await tp.file.move("/" + noteType + "/" + noteSubType + "/" + course + "/" + tp.file.title);
        } else { window.alert("Error: Something went wrong in the note type selection");};
    };

    // Update noteType based on whether noteSubType was defined
    if (noteSubType != undefined && noteSubType !== null) {
        noteType = noteSubType;
    }; 

    // Define frontmatter based on noteType
    switch (noteType) {
        case 'Courses':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
Course Code: 
Period: 
Duration: 
Timeslot: 
Year: 
---`;
            break;
        case 'Concepts':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
aliases: 
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        case 'Events':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
aliases: 
Event Date: 
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        case 'Theories':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
aliases: 
Authors: 
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        case 'Practice Questions':
        case 'Questions of Understanding':
        case 'Lecture Notes':
        case 'Summaries':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        case 'Literature Notes':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
Authors: 
Year of Publication: 
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        case 'Meeting Notes':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
Meeting Date: 
People Involved: 
Related Projects:
Related Courses:
---`;
            break;
        case 'Project Notes':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status: 
Project Type: 
People Involved: 
Related Notes: 
Related Courses: 
---`;
            break;
        case 'Writing Notes':
            Frontmatter = `
---
fileClass: Base, ${noteType}
title: 
Parents: 
Draft: 
Status:
People Involved: 
Related Projects:  
Related Notes: 
Related Terminology: 
Related Courses: 
---`;
            break;
        default:
            window.alert("Error: Seomthing failed in the metadata selection");
    }

    Frontmatter = Frontmatter.trim();
    return Frontmatter;
};

module.exports = newNote;

Basically, I moved the newly created file to the root directory earlier, and made sure all variables were initialised as part of the function to prevent cluttering.

from templater.

AlisAquilae avatar AlisAquilae commented on June 20, 2024

I just redid all my code and made some minor adjustments which I did not think would have any meaningful impact, yet somehow doing so has fixed the issue. That means my code did have an issue after all, and this was not caused by the templater plugin. Apologies for the faulty bug report.

from templater.

Zachatoo avatar Zachatoo commented on June 20, 2024

What changes did you make?

from templater.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.