396 lines
14 KiB
HTML
396 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="fr" data-theme="dark">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>ObsiGate - Popout</title>
|
|
<script>
|
|
document.documentElement.setAttribute('data-theme', localStorage.getItem('obsigate-theme') || 'dark');
|
|
</script>
|
|
<link rel="stylesheet" href="/static/style.css">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github-dark.min.css" id="hljs-theme-dark">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" id="hljs-theme-light" disabled>
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
|
|
<script src="https://unpkg.com/lucide@0.344.0/dist/umd/lucide.min.js"></script>
|
|
<style>
|
|
body, html {
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100%;
|
|
overflow: hidden;
|
|
background: var(--bg-primary);
|
|
}
|
|
|
|
.popout-loading {
|
|
position: absolute;
|
|
inset: 0;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
background: var(--bg-primary);
|
|
color: var(--text-primary);
|
|
z-index: 100;
|
|
transition: opacity 0.3s;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body class="popup-mode">
|
|
<div class="popout-loading" id="loading">Chargement...</div>
|
|
|
|
<div class="main-layout" style="height: 100vh;">
|
|
<main class="content-area" id="content-area" style="margin-top: 15px;">
|
|
<!-- JavaScript will inject breadcrumb, title, and markdown content here -->
|
|
</main>
|
|
</div>
|
|
|
|
<script>
|
|
function applyTheme(theme) {
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
|
|
const darkSheet = document.getElementById('hljs-theme-dark');
|
|
const lightSheet = document.getElementById('hljs-theme-light');
|
|
if (darkSheet && lightSheet) {
|
|
darkSheet.disabled = theme !== 'dark';
|
|
lightSheet.disabled = theme !== 'light';
|
|
}
|
|
}
|
|
|
|
function initTheme() {
|
|
const saved = localStorage.getItem('obsigate-theme') || 'dark';
|
|
applyTheme(saved);
|
|
}
|
|
|
|
async function initPopout() {
|
|
const pathParts = window.location.pathname.split('/');
|
|
const vault = decodeURIComponent(pathParts[2]);
|
|
const path = decodeURIComponent(pathParts.slice(3).join('/'));
|
|
|
|
if (!vault || !path) {
|
|
document.getElementById('loading').textContent = "Paramètres invalides";
|
|
return;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(`/api/file/${encodeURIComponent(vault)}?path=${encodeURIComponent(path)}`, {
|
|
credentials: 'include'
|
|
});
|
|
if (!response.ok) throw new Error("Erreur lors du chargement (Essayez de vous reconnecter sur le site principal)");
|
|
|
|
const data = await response.json();
|
|
document.title = data.title + " - ObsiGate";
|
|
|
|
const area = document.getElementById('content-area');
|
|
area.innerHTML = "";
|
|
|
|
// Build breadcrumb (identical structure to app.js)
|
|
const parts = path.split("/");
|
|
const breadcrumb = document.createElement("div");
|
|
breadcrumb.className = "breadcrumb";
|
|
|
|
breadcrumb.appendChild(createBreadcrumbSep());
|
|
breadcrumb.appendChild(createBreadcrumbItem(vault));
|
|
|
|
parts.forEach((part, i) => {
|
|
breadcrumb.appendChild(createBreadcrumbSep());
|
|
const name = i === parts.length - 1 ? part.replace(/\.md$/i, "") : part;
|
|
breadcrumb.appendChild(createBreadcrumbItem(name));
|
|
});
|
|
area.appendChild(breadcrumb);
|
|
|
|
// Build file header
|
|
const header = document.createElement("div");
|
|
header.className = "file-header";
|
|
const titleDiv = document.createElement("div");
|
|
titleDiv.className = "file-title";
|
|
titleDiv.textContent = data.title;
|
|
header.appendChild(titleDiv);
|
|
|
|
// Tags
|
|
if (data.tags && data.tags.length > 0) {
|
|
const tagsDiv = document.createElement("div");
|
|
tagsDiv.className = "file-tags";
|
|
data.tags.forEach(t => {
|
|
const span = document.createElement("span");
|
|
span.className = "file-tag";
|
|
span.textContent = "#" + t;
|
|
tagsDiv.appendChild(span);
|
|
});
|
|
header.appendChild(tagsDiv);
|
|
}
|
|
|
|
// Action buttons
|
|
const actionsDiv = document.createElement("div");
|
|
actionsDiv.className = "file-actions";
|
|
|
|
const copyBtn = document.createElement("button");
|
|
copyBtn.className = "btn-action";
|
|
copyBtn.title = "Copier la source";
|
|
copyBtn.innerHTML = '<i data-lucide="copy" style="width:14px;height:14px"></i> Copier';
|
|
copyBtn.addEventListener("click", async () => {
|
|
try {
|
|
const rawUrl = `/api/file/${encodeURIComponent(vault)}/raw?path=${encodeURIComponent(path)}`;
|
|
const rawData = await (await fetch(rawUrl, {credentials: 'include'})).json();
|
|
await navigator.clipboard.writeText(rawData.raw);
|
|
copyBtn.textContent = "Copié !";
|
|
setTimeout(() => (copyBtn.innerHTML = '<i data-lucide="copy" style="width:14px;height:14px"></i> Copier'), 1500);
|
|
if (window.lucide) window.lucide.createIcons();
|
|
} catch (e) {}
|
|
});
|
|
actionsDiv.appendChild(copyBtn);
|
|
|
|
const dlBtn = document.createElement("button");
|
|
dlBtn.className = "btn-action";
|
|
dlBtn.title = "Télécharger";
|
|
dlBtn.innerHTML = '<i data-lucide="download" style="width:14px;height:14px"></i> Télécharger';
|
|
dlBtn.addEventListener("click", () => {
|
|
const a = document.createElement("a");
|
|
a.href = `/api/file/${encodeURIComponent(vault)}/download?path=${encodeURIComponent(path)}`;
|
|
a.download = path.split('/').pop();
|
|
document.body.appendChild(a);
|
|
a.click();
|
|
document.body.removeChild(a);
|
|
});
|
|
actionsDiv.appendChild(dlBtn);
|
|
|
|
header.appendChild(actionsDiv);
|
|
area.appendChild(header);
|
|
|
|
// Frontmatter — Accent Card
|
|
if (data.frontmatter && Object.keys(data.frontmatter).length > 0) {
|
|
const fmSection = buildFrontmatterCard(data.frontmatter);
|
|
area.appendChild(fmSection);
|
|
}
|
|
|
|
// Markdown content wrapper
|
|
const mdDiv = document.createElement("div");
|
|
mdDiv.className = "md-content";
|
|
mdDiv.id = "file-rendered-content";
|
|
mdDiv.innerHTML = data.html;
|
|
area.appendChild(mdDiv);
|
|
|
|
// Render lucide icons
|
|
if (window.lucide) {
|
|
window.lucide.createIcons();
|
|
}
|
|
|
|
// Highlight code blocks
|
|
document.querySelectorAll('pre code').forEach((el) => {
|
|
hljs.highlightElement(el);
|
|
});
|
|
|
|
// Hide loading
|
|
document.getElementById('loading').style.opacity = '0';
|
|
setTimeout(() => {
|
|
document.getElementById('loading').style.display = 'none';
|
|
}, 300);
|
|
|
|
} catch (err) {
|
|
document.getElementById('loading').textContent = err.message;
|
|
}
|
|
}
|
|
|
|
function createBreadcrumbSep() {
|
|
const sep = document.createElement("span");
|
|
sep.className = "sep";
|
|
sep.textContent = " / ";
|
|
return sep;
|
|
}
|
|
|
|
function createBreadcrumbItem(text) {
|
|
const item = document.createElement("span");
|
|
item.className = "breadcrumb-item";
|
|
item.textContent = text;
|
|
return item;
|
|
}
|
|
|
|
function buildFrontmatterCard(frontmatter) {
|
|
// Helper: format date
|
|
function formatDate(iso) {
|
|
if (!iso) return '—';
|
|
const d = new Date(iso);
|
|
const date = d.toISOString().slice(0, 10);
|
|
const time = d.toTimeString().slice(0, 5);
|
|
return `${date} · ${time}`;
|
|
}
|
|
|
|
// Helper: create element
|
|
function el(tag, className, children) {
|
|
const e = document.createElement(tag);
|
|
if (className) e.className = className;
|
|
if (children) {
|
|
children.forEach(c => { if (c) e.appendChild(c); });
|
|
}
|
|
return e;
|
|
}
|
|
|
|
// Extract boolean flags
|
|
const booleanFlags = ['publish', 'favoris', 'template', 'task', 'archive', 'draft', 'private']
|
|
.map(key => ({ key, value: !!frontmatter[key] }));
|
|
|
|
// Toggle state
|
|
let isOpen = true;
|
|
|
|
// Build header with chevron
|
|
const chevron = el("span", "fm-chevron open");
|
|
chevron.innerHTML = '<i data-lucide="chevron-down" style="width:14px;height:14px"></i>';
|
|
|
|
const fmHeader = el("div", "fm-header");
|
|
fmHeader.appendChild(chevron);
|
|
fmHeader.appendChild(document.createTextNode("Frontmatter"));
|
|
|
|
// ZONE 1: Top strip
|
|
const acTop = el("div", "ac-top");
|
|
|
|
// Title badge
|
|
const title = frontmatter.titre || frontmatter.title || '';
|
|
if (title) {
|
|
const titleSpan = el("span", "ac-title");
|
|
titleSpan.textContent = `"${title}"`;
|
|
acTop.appendChild(titleSpan);
|
|
}
|
|
|
|
// Status badge
|
|
if (frontmatter.statut) {
|
|
const statusBadge = el("span", "ac-badge green");
|
|
const dot = el("span", "ac-dot");
|
|
statusBadge.appendChild(dot);
|
|
statusBadge.appendChild(document.createTextNode(frontmatter.statut));
|
|
acTop.appendChild(statusBadge);
|
|
}
|
|
|
|
// Category badge
|
|
if (frontmatter.catégorie || frontmatter.categorie) {
|
|
const cat = frontmatter.catégorie || frontmatter.categorie;
|
|
const catBadge = el("span", "ac-badge blue");
|
|
catBadge.textContent = cat;
|
|
acTop.appendChild(catBadge);
|
|
}
|
|
|
|
// Publish badge
|
|
if (frontmatter.publish) {
|
|
const pubBadge = el("span", "ac-badge purple");
|
|
pubBadge.textContent = "publié";
|
|
acTop.appendChild(pubBadge);
|
|
}
|
|
|
|
// Favoris badge
|
|
if (frontmatter.favoris) {
|
|
const favBadge = el("span", "ac-badge purple");
|
|
favBadge.textContent = "favori";
|
|
acTop.appendChild(favBadge);
|
|
}
|
|
|
|
// ZONE 2: Body 2 columns
|
|
const leftCol = el("div", "ac-col");
|
|
|
|
const row1 = el("div", "ac-row");
|
|
row1.innerHTML = '<span class="ac-k">auteur</span><span class="ac-v">' + (frontmatter.auteur || '—') + '</span>';
|
|
leftCol.appendChild(row1);
|
|
|
|
const row2 = el("div", "ac-row");
|
|
row2.innerHTML = '<span class="ac-k">catégorie</span><span class="ac-v">' + (frontmatter.catégorie || frontmatter.categorie || '—') + '</span>';
|
|
leftCol.appendChild(row2);
|
|
|
|
const row3 = el("div", "ac-row");
|
|
row3.innerHTML = '<span class="ac-k">statut</span><span class="ac-v">' + (frontmatter.statut || '—') + '</span>';
|
|
leftCol.appendChild(row3);
|
|
|
|
const row4 = el("div", "ac-row");
|
|
const aliases = frontmatter.aliases && frontmatter.aliases.length > 0 ? frontmatter.aliases.join(', ') : '[]';
|
|
row4.innerHTML = '<span class="ac-k">aliases</span><span class="ac-v muted">' + aliases + '</span>';
|
|
leftCol.appendChild(row4);
|
|
|
|
const rightCol = el("div", "ac-col");
|
|
|
|
const row5 = el("div", "ac-row");
|
|
row5.innerHTML = '<span class="ac-k">creation_date</span><span class="ac-v mono">' + formatDate(frontmatter.creation_date) + '</span>';
|
|
rightCol.appendChild(row5);
|
|
|
|
const row6 = el("div", "ac-row");
|
|
row6.innerHTML = '<span class="ac-k">modification_date</span><span class="ac-v mono">' + formatDate(frontmatter.modification_date) + '</span>';
|
|
rightCol.appendChild(row6);
|
|
|
|
const row7 = el("div", "ac-row");
|
|
row7.innerHTML = '<span class="ac-k">publish</span><span class="ac-v">' + String(frontmatter.publish || false) + '</span>';
|
|
rightCol.appendChild(row7);
|
|
|
|
const row8 = el("div", "ac-row");
|
|
row8.innerHTML = '<span class="ac-k">favoris</span><span class="ac-v">' + String(frontmatter.favoris || false) + '</span>';
|
|
rightCol.appendChild(row8);
|
|
|
|
const acBody = el("div", "ac-body");
|
|
acBody.appendChild(leftCol);
|
|
acBody.appendChild(rightCol);
|
|
|
|
// ZONE 3: Tags row
|
|
const acTagsRow = el("div", "ac-tags-row");
|
|
const tagsLabel = el("span", "ac-tags-k");
|
|
tagsLabel.textContent = "tags";
|
|
acTagsRow.appendChild(tagsLabel);
|
|
|
|
const tagsWrap = el("div", "ac-tags-wrap");
|
|
if (frontmatter.tags && frontmatter.tags.length > 0) {
|
|
frontmatter.tags.forEach(tag => {
|
|
const tagSpan = el("span", "ac-tag");
|
|
tagSpan.textContent = tag;
|
|
tagsWrap.appendChild(tagSpan);
|
|
});
|
|
}
|
|
acTagsRow.appendChild(tagsWrap);
|
|
|
|
// ZONE 4: Flags row
|
|
const acFlagsRow = el("div", "ac-flags-row");
|
|
const flagsLabel = el("span", "ac-flags-k");
|
|
flagsLabel.textContent = "flags";
|
|
acFlagsRow.appendChild(flagsLabel);
|
|
|
|
booleanFlags.forEach(flag => {
|
|
const chipClass = flag.value ? "flag-chip on" : "flag-chip off";
|
|
const chip = el("span", chipClass);
|
|
const dot = el("span", "flag-dot");
|
|
chip.appendChild(dot);
|
|
chip.appendChild(document.createTextNode(flag.key));
|
|
acFlagsRow.appendChild(chip);
|
|
});
|
|
|
|
// Assemble the card
|
|
const acCard = el("div", "ac-card");
|
|
acCard.appendChild(acTop);
|
|
acCard.appendChild(acBody);
|
|
acCard.appendChild(acTagsRow);
|
|
acCard.appendChild(acFlagsRow);
|
|
|
|
// Toggle functionality
|
|
fmHeader.addEventListener("click", () => {
|
|
isOpen = !isOpen;
|
|
if (isOpen) {
|
|
acCard.style.display = "block";
|
|
chevron.classList.remove("closed");
|
|
chevron.classList.add("open");
|
|
} else {
|
|
acCard.style.display = "none";
|
|
chevron.classList.remove("open");
|
|
chevron.classList.add("closed");
|
|
}
|
|
if (window.lucide) window.lucide.createIcons();
|
|
});
|
|
|
|
// Wrap in section
|
|
const fmSection = el("div", "fm-section");
|
|
fmSection.appendChild(fmHeader);
|
|
fmSection.appendChild(acCard);
|
|
|
|
return fmSection;
|
|
}
|
|
|
|
initTheme();
|
|
window.addEventListener('storage', (event) => {
|
|
if (event.key === 'obsigate-theme' && event.newValue) {
|
|
applyTheme(event.newValue);
|
|
}
|
|
});
|
|
initPopout();
|
|
</script>
|
|
</body>
|
|
</html>
|