feat: derive source pipeline from raw path claims
This commit is contained in:
32
.obsidian/plugins/webinar-dash/main.js
vendored
32
.obsidian/plugins/webinar-dash/main.js
vendored
@@ -21,6 +21,36 @@ const DEFAULTS = {
|
||||
conceptDir: "wiki/concepts",
|
||||
};
|
||||
|
||||
const RAW_PATH_RE = /^\s*-\s*\*\*Raw path:\*\*\s*`([^`]+)`/m;
|
||||
|
||||
function extractRawPath(text) {
|
||||
const m = String(text).match(RAW_PATH_RE);
|
||||
return m ? m[1].trim() : null;
|
||||
}
|
||||
|
||||
function derivePipeline({ rawFiles, sourcePages }) {
|
||||
const claimed = new Map();
|
||||
for (const page of sourcePages) {
|
||||
if (page.rawPath) claimed.set(page.rawPath, page);
|
||||
}
|
||||
|
||||
const processed = [];
|
||||
const unprocessed = [];
|
||||
for (const file of rawFiles) {
|
||||
const page = claimed.get(file.path);
|
||||
if (page) processed.push(Object.assign({}, file, { page }));
|
||||
else unprocessed.push(file);
|
||||
}
|
||||
|
||||
const rawPaths = new Set(rawFiles.map((f) => f.path));
|
||||
const orphaned = sourcePages.filter((p) => !p.rawPath || !rawPaths.has(p.rawPath));
|
||||
|
||||
unprocessed.sort((a, b) => a.name.localeCompare(b.name));
|
||||
processed.sort((a, b) => b.page.name.localeCompare(a.page.name));
|
||||
|
||||
return { processed, unprocessed, orphaned };
|
||||
}
|
||||
|
||||
function parseConfig(source) {
|
||||
const cfg = Object.assign({}, DEFAULTS);
|
||||
for (const line of String(source).split(/\r?\n/)) {
|
||||
@@ -45,4 +75,4 @@ class WebinarDashPlugin extends PluginBase {
|
||||
|
||||
module.exports = WebinarDashPlugin;
|
||||
module.exports.default = WebinarDashPlugin;
|
||||
module.exports.__test__ = { parseConfig, STATIONS, DEFAULTS };
|
||||
module.exports.__test__ = { parseConfig, extractRawPath, derivePipeline, STATIONS, DEFAULTS };
|
||||
|
||||
Reference in New Issue
Block a user