Test
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
* 9. Inline #tags → stripped (kept in frontmatter.tags)
|
||||
* 10. Frontmatter → passed through; tags array merged
|
||||
*
|
||||
* VISIBILITY GATE:
|
||||
* Only notes whose frontmatter contains `visible: true` are converted.
|
||||
* Any note missing the field, or with `visible: false`, is silently skipped.
|
||||
*
|
||||
* Usage:
|
||||
* node obsidian-to-nuxt.js --vault ./my-vault --out ./content --base-path /notes
|
||||
*
|
||||
@@ -171,12 +175,23 @@ function parseFrontmatter(content) {
|
||||
if (kv) {
|
||||
currentKey = kv[1];
|
||||
const val = kv[2].trim();
|
||||
fm[currentKey] = val === "" ? [] : val.replace(/^["']|["']$/g, "");
|
||||
// Coerce boolean-like values so `visible: true` becomes the boolean true
|
||||
if (val === "true") fm[currentKey] = true;
|
||||
else if (val === "false") fm[currentKey] = false;
|
||||
else fm[currentKey] = val === "" ? [] : val.replace(/^["']|["']$/g, "");
|
||||
}
|
||||
}
|
||||
return { frontmatter: fm, body };
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true only when the frontmatter contains `visible: true` (boolean).
|
||||
* Missing field, `visible: false`, or any other value → false.
|
||||
*/
|
||||
function isVisible(frontmatter) {
|
||||
return frontmatter.visible === true;
|
||||
}
|
||||
|
||||
function serializeFrontmatter(fm) {
|
||||
const lines = ["---"];
|
||||
for (const [key, val] of Object.entries(fm)) {
|
||||
@@ -350,7 +365,9 @@ function convertFile(content, noteIndex, filename) {
|
||||
const hasTitle = /^#[^#]/.test(trimmed);
|
||||
if (!hasTitle) {
|
||||
const title = frontmatter.title || path.basename(filename, ".md");
|
||||
body = "# " + title + "\n\n" + trimmed;
|
||||
if (title != "index") {
|
||||
body = "# " + title + "\n\n" + trimmed;
|
||||
}
|
||||
}
|
||||
|
||||
const fmString = Object.keys(frontmatter).length
|
||||
@@ -373,10 +390,23 @@ function main() {
|
||||
|
||||
console.log("Found " + files.length + " markdown file(s) in " + VAULT_DIR);
|
||||
|
||||
let doneCount = 0, skipCount = 0;
|
||||
let doneCount = 0, skipCount = 0, hiddenCount = 0;
|
||||
|
||||
for (const file of files) {
|
||||
const rel = path.relative(VAULT_DIR, file);
|
||||
const content = fs.readFileSync(file, "utf8");
|
||||
|
||||
// ── Visibility gate ──────────────────────────────────────────────────────
|
||||
// Parse frontmatter just enough to check the `visible` field.
|
||||
// Notes without `visible: true` are skipped entirely.
|
||||
const { frontmatter: fm } = parseFrontmatter(content);
|
||||
if (!isVisible(fm)) {
|
||||
console.log(" \u23ED " + rel + " (skipped — no visible: true)");
|
||||
hiddenCount++;
|
||||
continue;
|
||||
}
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
|
||||
const outPath = path.join(
|
||||
OUT_DIR,
|
||||
rel.split(path.sep)
|
||||
@@ -384,9 +414,7 @@ function main() {
|
||||
.join(path.sep)
|
||||
);
|
||||
|
||||
const content = fs.readFileSync(file, "utf8");
|
||||
let result;
|
||||
|
||||
try {
|
||||
result = convertFile(content, noteIndex, path.basename(file));
|
||||
} catch (err) {
|
||||
@@ -408,7 +436,11 @@ function main() {
|
||||
doneCount++;
|
||||
}
|
||||
|
||||
console.log("\nDone. " + doneCount + " file(s) converted, " + skipCount + " skipped.");
|
||||
console.log(
|
||||
"\nDone. " + doneCount + " file(s) converted, " +
|
||||
hiddenCount + " hidden (no visible: true), " +
|
||||
skipCount + " skipped (error)."
|
||||
);
|
||||
}
|
||||
|
||||
main();
|
||||
Reference in New Issue
Block a user