What I’m trying to do
I’m trying to create a template that creates a new note for each string in a list of strings that I paste into a prompt with a file name equal to that string using a user script
Things I have tried
This is the code I currently have:
// Define a function to create notes from lines of text
async function createNotesFromText(tp) {
// Get the content
const fen = await tp.system.prompt("FEN Strings", "", true, true);
// Split the input text into an array of lines using line breaks as the delimiter
var lines = fen.split('\n');
// Iterate over the lines and create a new note for each one
lines.forEach((line) => {
// Trim any leading or trailing whitespace from the line to ensure a clean title
const noteTitle = line.replace(/\//g, '-').replace(/\s\d+\s\d+$/, '').trim();
// Check if a note with the same title already exists
if (!tp.file.exists(noteTitle)) {
// Create a new note with the extracted title
tp.file.create_new("", noteTitle, false);
}
});
}
module.exports = createNotesFromText;
This is resulting in “undefined” getting inserted in my current note when I try to use the template, which contains this:
<%* const exe_val = await tp.user.chessPositionMassCreation(tp) %>
<%* tR += exe_val %>
Just for reference, the list of strings are FEN notated positions in chess, such as these
rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR b KQkq e3 0 1
rnbqkbnr/pp1ppppp/8/2p5/4P3/8/PPPP1PPP/RNBQKBNR w KQkq c6 0 2
rnbqkbnr/pp1ppppp/8/2p5/4P3/5N2/PPPP1PPP/RNBQKB1R b KQkq - 1 2
Any help would be greatly appreciated. Thanks!!!