What I’m trying to do
i want this code to add to a template i already have, but whenever i run the script it replaces the entire template. i would like to have the output added to the note, not replaced to it.
can someone help?
code:
<%*
let series = tp.file.title;
let show = series.toLowerCase();
show = show.replace(/^the /,''); //remove leading The
show = show.replace(/^a /,''); //remove leading A
show = show.replace(/^an /,''); //remove leading An
show = show.replace(/\s+/g,''); //remove spaces
show = show.replace(/[^\p{L}\p{N}]/gu, ''); //remove punctuation
tR = `# ${series}\n\n`;
const apiRoot = 'https://epguides.frecar.no/show/';
const cmd = `PowerShell -Command "(Invoke-WebRequest -Uri '${apiRoot}${show}/').Content"`;
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
const result = await exec(cmd);
const json = result.stdout.trim();
if ((json.length < 10) || json.startsWith('{"error":'))
{
tR += 'Failed to find the episode list\n';
tR += '```\n' + cmd + '\n```\n';
}
else
{
let eps = JSON.parse(json);
let seasons = Object.keys(eps);
for (let i = 0; i < seasons.length; i++)
{
let season = seasons[i];
tR += `## Season ${season}\n`;
let j = 0;
let widthNum = 1;
let widthTitle = 5;
for (j = 0; j < eps[season].length; j++)
{
let num = `${eps[season][j].number}`;
if (num.length > widthNum) { widthNum = num.length; }
if (eps[season][j].title.length > widthTitle) { widthTitle = eps[season][j].title.length; }
}
tR += `| ${'#'.padStart(widthNum,' ')} | ${"Title".padEnd(widthTitle,' ')} | ${' Released '} |\n`;
tR += `|-${'-'.padStart(widthNum,'-')}:|-${'-'.padEnd(widthTitle,'-')}-|------------|\n`;
for (let j = 0; j < eps[season].length; j++)
{
let num = `${eps[season][j].number}`;
tR += `| ${num.padStart(widthNum,' ')} | ${eps[season][j].title.padEnd(widthTitle,' ')} | ${eps[season][j].release_date} |\n`;
}
tR += '\n';
}
}
-%>