export_to_calibre.md
export_to_calibre.md
Section titled “export_to_calibre.md”<%*
/* Pull YAML (front matter) */
const fm = tp.frontmatter || {};
const title = (fm.title ?? tp.file.title).toString();
const authorsRaw = fm.author ?? fm.authors ?? "";
const authors =
Array.isArray(authorsRaw) ? authorsRaw.join(” & ”) : authorsRaw.toString();
const tagsRaw = fm.tags ?? "";
const tags =
Array.isArray(tagsRaw) ? tagsRaw.join(”, ”) : tagsRaw.toString();
const series = (fm.series ?? "").toString();
const seriesIndex =
(fm.series_index ?? fm[“series-index”] ?? fm.seriesIndex ?? "").toString();
const lang = (fm.language ?? fm.lang ?? "").toString();
const publisher = (fm.publisher ?? "").toString();
const comments = (fm.description ?? fm.abstract ?? fm.summary ?? "").toString();
/* Absolute path to the current note */
const file = tp.file.path(true);
/* Build calibredb command */
const lib = “/Users/philwaymouth/Calibre Library”;
function q(s){ return "${s.replace(/"/g, '\\"')}"; }
let cmd = /Applications/calibre.app/Contents/MacOS/calibredb add --with-library ${q(lib)};
if (title) cmd += --title ${q(title)};
if (authors) cmd += --authors ${q(authors)};
if (tags) cmd += --tags ${q(tags)};
if (series) cmd += --series ${q(series)};
if (seriesIndex) cmd += --series-index ${q(seriesIndex)};
if (lang) cmd += --languages ${q(lang)};
if (publisher) cmd += --publisher ${q(publisher)};
if (comments) cmd += --comments ${q(comments)};
cmd += ${q(file)};
/* Run it */
await tp.system.shellexec(cmd);
-%>