Planung in webinar/mail-strecke/ mit Noahs Texten, rechtlicher Einordnung der Kaltmails, WebinarGeek statt Google Meet und Versandplan. Neue Dashboard-Seite Aufgaben mit 54 Todos in zeitlicher Reihenfolge (daten/aufgaben.json), abhaken lokal wie bei der Roadmap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
185 lines
7.7 KiB
JavaScript
185 lines
7.7 KiB
JavaScript
// Dokumente: alle Markdown-Dateien im Hub lesen und durchsuchen.
|
|
|
|
import { S } from "../app.js";
|
|
import { esc, md, slug, dokLink, zeitstempel } from "../hilfen.js";
|
|
|
|
const STANDARD = "Brainstorming Kickoff/Strategie/Content-Strategie.md";
|
|
|
|
// Reihenfolge der Ordner in der Liste: das, was man täglich braucht, zuerst.
|
|
const ORDNER = [
|
|
["Brainstorming Kickoff/Strategie", "Strategie"],
|
|
["webinar", "Webinar"],
|
|
["webinar/mail-strecke", "Webinar: Mail-Strecke"],
|
|
["webinar/01-crm-marketing-vertrieb", "Webinar: CRM"],
|
|
["webinar/02-automation", "Webinar: Automation"],
|
|
["webinar/03-drumherum", "Webinar: Drumherum"],
|
|
["webinar/04-ueberraschung", "Webinar: Überraschung"],
|
|
["webinar/slides", "Webinar: Slides"],
|
|
["Ressourcen", "Ressourcen"],
|
|
["Ressourcen/Reel-Analyse", "Reel-Analyse"],
|
|
["Ressourcen/Reel-Analyse/analysen", "Reel-Analysen"],
|
|
["Brainstorming Kickoff/Kontext", "Kontext"],
|
|
["Brainstorming Kickoff/Research", "Recherche"],
|
|
["Brainstorming Kickoff", "Brainstorming Kickoff"],
|
|
["", "Hub"],
|
|
];
|
|
|
|
let suche = { begriff: "", treffer: [], laeuft: null };
|
|
const textCache = new Map();
|
|
|
|
async function dokText(pfad) {
|
|
const eintrag = S.dokumente.find((d) => d.pfad === pfad);
|
|
const zeit = eintrag?.zeit;
|
|
const alt = textCache.get(pfad);
|
|
if (alt && alt.zeit === zeit) return alt.text;
|
|
const r = await fetch("/" + pfad.split("/").map(encodeURIComponent).join("/"), { cache: "no-store" });
|
|
if (!r.ok) throw new Error(`${pfad} nicht gefunden`);
|
|
const text = await r.text();
|
|
textCache.set(pfad, { zeit, text });
|
|
return text;
|
|
}
|
|
|
|
// Kurze Titel für die Liste. "HiveGrid: " fällt weg, und bei Recherche und
|
|
// Auswertungen sagt der Ordner schon, worum es geht.
|
|
// Aus "Recherche zum Marketing-Brainstorming: Übersicht" wird "Übersicht".
|
|
const kurzTitel = (titel) => titel.replace(/^HiveGrid:\s*/, "").replace(/^(Recherche[^:]*|Auswertung):\s*/, "");
|
|
|
|
function liste(aktiv) {
|
|
if (suche.begriff.length >= 2) {
|
|
const n = suche.treffer.length;
|
|
const muster = new RegExp(suche.begriff.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "gi");
|
|
return `<div class="klein" style="margin-bottom:6px">${n >= 300 ? "Über 300" : n} Treffer</div>
|
|
${suche.treffer.map((t) => `<a class="treffer" href="${dokLink(t.pfad, `?q=${encodeURIComponent(suche.begriff)}`)}">
|
|
<b>${esc(kurzTitel(t.titel))}</b>${t.ueberschrift ? `<span class="klein" style="display:block">${esc(t.ueberschrift)}</span>` : ""}${esc(t.text).replace(muster, (m) => `<mark>${m}</mark>`)}</a>`).join("")}`;
|
|
}
|
|
const gruppen = new Map(ORDNER.map(([o]) => [o, []]));
|
|
for (const d of S.dokumente) {
|
|
if (!gruppen.has(d.ordner)) gruppen.set(d.ordner, []);
|
|
gruppen.get(d.ordner).push(d);
|
|
}
|
|
return [...gruppen.entries()].filter(([, l]) => l.length).map(([ordner, l]) => {
|
|
const name = (ORDNER.find(([o]) => o === ordner) || [, ordner.split("/").at(-1)])[1];
|
|
return `<div class="dok-ordner">${esc(name)}</div>${l.map((d) =>
|
|
`<a class="dok-link ${d.pfad === aktiv ? "aktiv" : ""}" href="${dokLink(d.pfad)}">${esc(kurzTitel(d.titel))}</a>`).join("")}`;
|
|
}).join("");
|
|
}
|
|
|
|
// Relative Links zwischen Markdown-Dateien bleiben im Dashboard.
|
|
function linksUmbiegen(wurzel, pfad) {
|
|
const basis = pfad.split("/").slice(0, -1);
|
|
wurzel.querySelectorAll("a[href]").forEach((a) => {
|
|
const href = a.getAttribute("href");
|
|
if (/^(https?:|mailto:|#)/.test(href)) {
|
|
if (/^https?:/.test(href)) { a.target = "_blank"; a.rel = "noopener"; }
|
|
return;
|
|
}
|
|
const [ziel, anker] = href.split("#");
|
|
const teile = [...basis];
|
|
for (const t of decodeURIComponent(ziel).split("/")) {
|
|
if (t === "..") teile.pop();
|
|
else if (t && t !== ".") teile.push(t);
|
|
}
|
|
const voll = teile.join("/");
|
|
if (voll.endsWith(".md")) a.setAttribute("href", dokLink(voll, anker ? `?abschnitt=${encodeURIComponent(anker)}` : ""));
|
|
else a.setAttribute("href", "/" + teile.map(encodeURIComponent).join("/"));
|
|
});
|
|
}
|
|
|
|
function markieren(wurzel, begriff) {
|
|
if (!begriff) return null;
|
|
const quelle = esc(begriff).replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
// Ohne "g" zum Prüfen: ein globaler Ausdruck merkt sich die letzte Stelle
|
|
// und würde jeden zweiten Treffer überspringen.
|
|
const pruefen = new RegExp(begriff.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "i");
|
|
const gaenger = document.createTreeWalker(wurzel, NodeFilter.SHOW_TEXT);
|
|
const knoten = [];
|
|
while (gaenger.nextNode()) if (pruefen.test(gaenger.currentNode.nodeValue)) knoten.push(gaenger.currentNode);
|
|
let erster = null;
|
|
for (const k of knoten) {
|
|
const span = document.createElement("span");
|
|
span.innerHTML = esc(k.nodeValue).replace(new RegExp(quelle, "gi"), (m) => `<mark class="fund">${m}</mark>`);
|
|
k.replaceWith(span);
|
|
erster = erster || span.querySelector("mark");
|
|
}
|
|
return erster;
|
|
}
|
|
|
|
export async function zeichnen(main, r) {
|
|
const pfad = r.rest.join("/") || STANDARD;
|
|
const abschnitt = r.query.get("abschnitt");
|
|
const q = r.query.get("q");
|
|
const eintrag = S.dokumente.find((d) => d.pfad === pfad);
|
|
|
|
main.innerHTML = `
|
|
<div class="dok-rahmen">
|
|
<div class="block dok-liste">
|
|
<input type="search" id="dok-suche" placeholder="In allen Dokumenten suchen" value="${esc(suche.begriff)}" autocomplete="off">
|
|
<div id="dok-liste">${liste(pfad)}</div>
|
|
</div>
|
|
<article class="block dok-inhalt">
|
|
<div class="springe"><span class="pfad">${esc(pfad)}${eintrag ? `, geändert am ${zeitstempel(eintrag.zeit)}` : ""}</span><span id="springe"></span></div>
|
|
<div class="md" id="dok-text"><p class="muted">Lade</p></div>
|
|
</article>
|
|
</div>`;
|
|
|
|
const eingabe = main.querySelector("#dok-suche");
|
|
eingabe.oninput = () => {
|
|
clearTimeout(suche.laeuft);
|
|
suche.laeuft = setTimeout(async () => {
|
|
suche.begriff = eingabe.value.trim();
|
|
suche.treffer = suche.begriff.length >= 2
|
|
? await fetch(`/api/suche?q=${encodeURIComponent(suche.begriff)}`).then((x) => x.json()).catch(() => [])
|
|
: [];
|
|
main.querySelector("#dok-liste").innerHTML = liste(pfad);
|
|
}, 220);
|
|
};
|
|
eingabe.onkeydown = (e) => {
|
|
if (e.key === "Escape") { eingabe.value = ""; eingabe.oninput(); e.stopPropagation(); }
|
|
};
|
|
|
|
const ziel = main.querySelector("#dok-text");
|
|
let text;
|
|
try {
|
|
text = await dokText(pfad);
|
|
} catch (e) {
|
|
ziel.innerHTML = `<p>${esc(e.message)}</p>`;
|
|
return;
|
|
}
|
|
ziel.innerHTML = md(text);
|
|
ziel.querySelectorAll("table").forEach((t) => {
|
|
const rahmen = document.createElement("div");
|
|
rahmen.className = "tabelle-rahmen";
|
|
t.replaceWith(rahmen);
|
|
rahmen.appendChild(t);
|
|
});
|
|
linksUmbiegen(ziel, pfad);
|
|
|
|
const vergeben = new Set();
|
|
const ueberschriften = [...ziel.querySelectorAll("h2, h3")];
|
|
for (const h of ziel.querySelectorAll("h1, h2, h3, h4")) {
|
|
let id = slug(h.textContent);
|
|
while (vergeben.has(id)) id += "-1";
|
|
vergeben.add(id);
|
|
h.id = id;
|
|
}
|
|
const kapitel = ueberschriften.filter((h) => h.tagName === "H2");
|
|
if (kapitel.length > 2) {
|
|
const springe = main.querySelector("#springe");
|
|
springe.innerHTML = `<select aria-label="Springe zu"><option value="">Springe zu Abschnitt</option>${kapitel.map((h) =>
|
|
`<option value="${h.id}">${esc(h.textContent)}</option>`).join("")}</select>`;
|
|
const sel = springe.querySelector("select");
|
|
sel.onchange = () => {
|
|
document.getElementById(sel.value)?.scrollIntoView({ behavior: "smooth", block: "start" });
|
|
sel.value = "";
|
|
};
|
|
}
|
|
|
|
let sprung = null;
|
|
if (abschnitt) {
|
|
const a = abschnitt.toLowerCase();
|
|
sprung = [...ziel.querySelectorAll("h1, h2, h3, h4")].find((h) => h.id === slug(abschnitt) || h.textContent.trim().toLowerCase().startsWith(a));
|
|
}
|
|
if (q) sprung = markieren(ziel, q) || sprung;
|
|
if (sprung) requestAnimationFrame(() => sprung.scrollIntoView({ block: q ? "center" : "start" }));
|
|
}
|