This commit is contained in:
2026-07-18 15:00:19 +02:00
parent c0ace47049
commit 12359144cb
5 changed files with 93 additions and 14 deletions

2
template/.gitignore vendored
View File

@@ -23,5 +23,5 @@ logs
.env.*
!.env.example
content
content/
vault

View File

@@ -1,5 +1,5 @@
# ---------- Build Stage ----------
FROM node:20-alpine AS builder
FROM node:24-alpine AS builder
WORKDIR /app
@@ -23,7 +23,7 @@ RUN node convert.js --vault ./vault --out ./content --img-prefix https://cdn.ara
RUN npm run build
# ---------- Production Stage ----------
FROM node:20-alpine
FROM node:24-alpine
WORKDIR /app

View File

@@ -1,11 +1,13 @@
<!-- components/TreeNode.vue -->
<script setup>
import { ref } from 'vue'
defineProps({ nodes: Array, depth: { type: Number, default: 0 } })
const router = useRouter()
const collapsed = ref({})
function getTitle(node) {
if (node.title == "index") return "Index"
if (node.title == "index") return "Index"
return node.title || node._path?.split('/').pop() || 'Home';
}
@@ -13,6 +15,10 @@ function navigate(path) {
if (!path) return
router.push(path)
}
function toggle(key) {
collapsed.value[key] = !collapsed.value[key]
}
</script>
<template>
@@ -27,8 +33,15 @@ function navigate(path) {
</template>
<template v-else>
<span>📁 {{ getTitle(node) }}</span>
<TreeNode :nodes="node.children" :depth="depth + 1" />
<button class="folder-toggle" @click="toggle(node.path ?? node.title)">
<span class="chevron" :class="{ open: !collapsed[node.path ?? node.title] }"></span>
{{ getTitle(node) }}
</button>
<TreeNode
v-if="!collapsed[node.path ?? node.title]"
:nodes="node.children"
:depth="depth + 1"
/>
</template>
</li>
@@ -46,6 +59,36 @@ li {
}
a {
color: var(--text-link);
}
.folder-toggle {
display: flex;
align-items: center;
gap: 0.35rem;
background: none;
border: none;
padding: 0;
cursor: pointer;
color: inherit;
font: inherit;
width: 100%;
text-align: left;
&:hover {
color: var(--text-link);
}
}
.chevron {
display: inline-block;
font-style: normal;
transition: transform 0.15s ease;
transform: rotate(0deg);
line-height: 1;
&.open {
transform: rotate(90deg);
}
}
</style>

View File

@@ -1,4 +1,8 @@
# index
---
visible: true
---
# Millor campana
Hola que tal! Hauria de funcionar

View File

@@ -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();