From e1171c53a50868b4b973750d1cd19ba85f933560 Mon Sep 17 00:00:00 2001 From: Ross Keenan Date: Thu, 25 Nov 2021 10:49:56 +0200 Subject: [PATCH] feat(CSV Crumbs): :sparkles: Allow CSV items to be wikilinks (The secret is that it doesn't have to be a CSV file! So using wikilinks allows the items to be auto updated) (fix #196) --- main.js | 9 ++++++++- src/main.ts | 7 +++---- src/sharedFunctions.ts | 6 ++++++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main.js b/main.js index 7121a03f..be3041d9 100644 --- a/main.js +++ b/main.js @@ -23681,6 +23681,12 @@ function makeWiki(wikiQ, str) { } return copy; } +function dropWikilinks(str) { + let copy = str.slice(); + if (copy.startsWith("[[") && copy.endsWith("]]")) + copy = copy.slice(2, -2); + return copy; +} /** * Get all the fields in `dir`. * Returns all fields if `dir === 'all'` @@ -50090,10 +50096,11 @@ class BCPlugin extends require$$0.Plugin { const rowObj = {}; row .split(",") - .map((head) => head.trim()) + .map((head) => dropWikilinks(head.trim())) .forEach((item, i) => { rowObj[headers[i]] = item; }); + loglevel.debug({ rowObj }); CSVRows.push(rowObj); }); return CSVRows; diff --git a/src/main.ts b/src/main.ts index 6e28c125..316b1408 100644 --- a/src/main.ts +++ b/src/main.ts @@ -40,7 +40,6 @@ import { addEdgeIfNot, addNodesIfNot, getFieldInfo, - getInNeighbours, getOppDir, getOppFields, getReflexiveClosure, @@ -60,8 +59,7 @@ import type { } from "./interfaces"; import { createOrUpdateYaml, - // debugGroupEnd, - // debugGroupStart, + dropWikilinks, getBaseFromPath, getDVBasename, getFields, @@ -495,10 +493,11 @@ export default class BCPlugin extends Plugin { const rowObj = {}; row .split(",") - .map((head) => head.trim()) + .map((head) => dropWikilinks(head.trim())) .forEach((item, i) => { rowObj[headers[i]] = item; }); + debug({ rowObj }); CSVRows.push(rowObj); }); return CSVRows; diff --git a/src/sharedFunctions.ts b/src/sharedFunctions.ts index c2478a48..0bd1f84f 100644 --- a/src/sharedFunctions.ts +++ b/src/sharedFunctions.ts @@ -138,6 +138,12 @@ export function makeWiki(wikiQ: boolean, str: string) { return copy; } +export function dropWikilinks(str: string) { + let copy = str.slice(); + if (copy.startsWith("[[") && copy.endsWith("]]")) copy = copy.slice(2, -2); + return copy; +} + /** * Get all the fields in `dir`. * Returns all fields if `dir === 'all'`