This commit is contained in:
Fabien POLLY
2026-01-24 17:28:14 +01:00
parent 7c8dfdb072
commit f98f2f024a
2 changed files with 37 additions and 37 deletions

View File

@@ -1111,8 +1111,8 @@
contentCache: {}, contentCache: {},
searchIndex: [], searchIndex: [],
expandedSections: new Set(), expandedSections: new Set(),
repo: "infinition/AcidWiki", // Fallback repo: "infinition/Bjorn", // Fallback
branch: "main", branch: "wiki",
currentTitle: "", currentTitle: "",
currentFolder: "", currentFolder: "",
currentFilename: "" currentFilename: ""
@@ -1407,28 +1407,28 @@
// --- 4. WIKI CORE --- // --- 4. WIKI CORE ---
async function initWiki() { async function initWiki() {
try { try {
debugLog('[AcidWiki] 🚀 Initializing wiki...'); debugLog('[Bjorn] 🚀 Initializing wiki...');
// Try GitHub API first for production // Try GitHub API first for production
let structure = await fetchWikiStructureFromAPI(); let structure = await fetchWikiStructureFromAPI();
// If API fails, try local filesystem scanning (for local HTTP servers) // If API fails, try local filesystem scanning (for local HTTP servers)
if (!structure) { if (!structure) {
debugLog('[AcidWiki] 🔄 Trying local filesystem scan...'); debugLog('[Bjorn] 🔄 Trying local filesystem scan...');
structure = await scanLocalFilesystem(); structure = await scanLocalFilesystem();
} }
if (!structure || Object.keys(structure).length === 0) { if (!structure || Object.keys(structure).length === 0) {
if (CONFIG.features.showRootReadme) { if (CONFIG.features.showRootReadme) {
debugLog('[AcidWiki] No docs found, but root README is enabled. Proceeding...'); debugLog('[Bjorn] No docs found, but root README is enabled. Proceeding...');
structure = {}; // Empty but valid structure = {}; // Empty but valid
} else { } else {
console.error('[AcidWiki] ❌ No wiki content found!'); console.error('[Bjorn] ❌ No wiki content found!');
throw new Error("No wiki content found. Please add .md files to wiki/docs/"); throw new Error("No wiki content found. Please add .md files to wiki/docs/");
} }
} }
debugLog('[AcidWiki] ✅ Wiki structure loaded successfully'); debugLog('[Bjorn] ✅ Wiki structure loaded successfully');
STATE.wikiData = structure; STATE.wikiData = structure;
const firstFolder = Object.keys(STATE.wikiData)[0]; const firstFolder = Object.keys(STATE.wikiData)[0];
@@ -1457,22 +1457,22 @@
async function fetchWikiStructureFromAPI() { async function fetchWikiStructureFromAPI() {
// CORRECTION : On autorise l'API même en mode local, tant qu'il y a un repo configuré // CORRECTION : On autorise l'API même en mode local, tant qu'il y a un repo configuré
if (!STATE.repo) { if (!STATE.repo) {
debugLog('[AcidWiki] ⏭️ Skipping GitHub API (no repo configured)'); debugLog('[Bjorn] ⏭️ Skipping GitHub API (no repo configured)');
return null; return null;
} }
const branchesToTry = [CONFIG.branch, 'main', 'master']; const branchesToTry = [CONFIG.branch, 'wiki', 'master'];
for (const branch of branchesToTry) { for (const branch of branchesToTry) {
if (!branch) continue; if (!branch) continue;
debugLog(`[AcidWiki] 🌐 Fetching structure from GitHub API: ${STATE.repo}/${branch}`); debugLog(`[Bjorn] 🌐 Fetching structure from GitHub API: ${STATE.repo}/${branch}`);
try { try {
const res = await fetch(`https://api.github.com/repos/${STATE.repo}/git/trees/${branch}?recursive=1`); const res = await fetch(`https://api.github.com/repos/${STATE.repo}/git/trees/${branch}?recursive=1`);
if (!res.ok) { if (!res.ok) {
debugLog(`[AcidWiki] ⚠️ Branch "${branch}" failed (${res.status})`); debugLog(`[Bjorn] ⚠️ Branch "${branch}" failed (${res.status})`);
continue; continue;
} }
debugLog(`[AcidWiki] ✅ GitHub API response received for branch: ${branch}`); debugLog(`[Bjorn] ✅ GitHub API response received for branch: ${branch}`);
const data = await res.json(); const data = await res.json();
const structure = {}; const structure = {};
let fileCount = 0; let fileCount = 0;
@@ -1510,31 +1510,31 @@
} }
const sortedStructure = sortStructure(structure); const sortedStructure = sortStructure(structure);
debugLog(`[AcidWiki] ✅ GitHub discovery complete: Found ${fileCount} files`); debugLog(`[Bjorn] ✅ GitHub discovery complete: Found ${fileCount} files`);
return Object.keys(sortedStructure).length > 0 ? sortedStructure : null; return Object.keys(sortedStructure).length > 0 ? sortedStructure : null;
} catch (e) { } catch (e) {
debugLog(`[AcidWiki] ❌ Error fetching branch "${branch}":`, e); debugLog(`[Bjorn] ❌ Error fetching branch "${branch}":`, e);
} }
} }
return null; return null;
} }
async function scanLocalFilesystem() { async function scanLocalFilesystem() {
debugLog('[AcidWiki] 🔍 Starting local filesystem scan...'); debugLog('[Bjorn] 🔍 Starting local filesystem scan...');
try { try {
// Try to fetch the wiki/docs/ directory listing // Try to fetch the wiki/docs/ directory listing
const res = await fetch('./wiki/docs/'); const res = await fetch('./wiki/docs/');
if (!res.ok) { if (!res.ok) {
debugLog('[AcidWiki] ❌ Cannot access wiki/docs/ directory'); debugLog('[Bjorn] ❌ Cannot access wiki/docs/ directory');
return null; return null;
} }
debugLog('[AcidWiki] ✅ Successfully accessed wiki/docs/'); debugLog('[Bjorn] ✅ Successfully accessed wiki/docs/');
const structure = {}; const structure = {};
// Recursive function to scan a folder // Recursive function to scan a folder
async function scanFolder(path = '', parentStructure = structure) { async function scanFolder(path = '', parentStructure = structure) {
debugLog(`[AcidWiki] 📂 Scanning folder: wiki/docs/${path || '(root)'}`); debugLog(`[Bjorn] 📂 Scanning folder: wiki/docs/${path || '(root)'}`);
const folderUrl = path ? `./wiki/docs/${path}/` : './wiki/docs/'; const folderUrl = path ? `./wiki/docs/${path}/` : './wiki/docs/';
const folderRes = await fetch(folderUrl); const folderRes = await fetch(folderUrl);
@@ -1548,7 +1548,7 @@
let filesFound = 0; let filesFound = 0;
let foldersFound = 0; let foldersFound = 0;
debugLog(`[AcidWiki] 🔎 Found ${links.length} links in HTML`); debugLog(`[Bjorn] 🔎 Found ${links.length} links in HTML`);
for (const link of links) { for (const link of links) {
const href = link.getAttribute('href'); const href = link.getAttribute('href');
@@ -1558,7 +1558,7 @@
// Skip navigation links // Skip navigation links
if (linkText === '..' || linkText === '~') { if (linkText === '..' || linkText === '~') {
debugLog(`[AcidWiki] ⏭️ Skipped navigation link: "${linkText}"`); debugLog(`[Bjorn] ⏭️ Skipped navigation link: "${linkText}"`);
continue; continue;
} }
@@ -1569,14 +1569,14 @@
// Only process links that contain wiki/docs in their path // Only process links that contain wiki/docs in their path
if (!href.includes(baseDocsPath)) { if (!href.includes(baseDocsPath)) {
debugLog(`[AcidWiki] ⏭️ Skipped (not in wiki/docs): "${href}"`); debugLog(`[Bjorn] ⏭️ Skipped (not in wiki/docs): "${href}"`);
continue; continue;
} }
// Extract the part after /wiki/docs/ // Extract the part after /wiki/docs/
const afterDocs = href.split(baseDocsPath)[1]; const afterDocs = href.split(baseDocsPath)[1];
if (!afterDocs) { if (!afterDocs) {
debugLog(`[AcidWiki] ⏭️ Skipped (invalid path after wiki/docs): "${href}"`); debugLog(`[Bjorn] ⏭️ Skipped (invalid path after wiki/docs): "${href}"`);
continue; continue;
} }
@@ -1585,7 +1585,7 @@
// If we're scanning '01_General', afterDocs should start with '01_General/' and next segment is the child // If we're scanning '01_General', afterDocs should start with '01_General/' and next segment is the child
const expectedPrefix = path ? `${path}/` : ''; const expectedPrefix = path ? `${path}/` : '';
if (path && !afterDocs.startsWith(expectedPrefix)) { if (path && !afterDocs.startsWith(expectedPrefix)) {
debugLog(`[AcidWiki] ⏭️ Skipped (not in current path "${path}"): afterDocs="${afterDocs}"`); debugLog(`[Bjorn] ⏭️ Skipped (not in current path "${path}"): afterDocs="${afterDocs}"`);
continue; continue;
} }
@@ -1595,7 +1595,7 @@
// Only accept direct children: should not contain additional slashes (except trailing for folders) // Only accept direct children: should not contain additional slashes (except trailing for folders)
const withoutTrailingSlash = relativePart.endsWith('/') ? relativePart.slice(0, -1) : relativePart; const withoutTrailingSlash = relativePart.endsWith('/') ? relativePart.slice(0, -1) : relativePart;
if (withoutTrailingSlash.includes('/')) { if (withoutTrailingSlash.includes('/')) {
debugLog(`[AcidWiki] ⏭️ Skipped (not a direct child): relativePart="${relativePart}"`); debugLog(`[Bjorn] ⏭️ Skipped (not a direct child): relativePart="${relativePart}"`);
continue; continue;
} }
@@ -1622,13 +1622,13 @@
} }
if (!folderName || folderName.trim() === '' || folderName === '..') { if (!folderName || folderName.trim() === '' || folderName === '..') {
debugLog(`[AcidWiki] ⏭️ Skipping invalid folder name: "${folderName}"`); debugLog(`[Bjorn] ⏭️ Skipping invalid folder name: "${folderName}"`);
continue; continue;
} }
const fullPath = path ? `${path}/${folderName}` : folderName; const fullPath = path ? `${path}/${folderName}` : folderName;
debugLog(`[AcidWiki] 📁 Found folder: ${folderName} (${fullPath})`); debugLog(`[Bjorn] 📁 Found folder: ${folderName} (${fullPath})`);
foldersFound++; foldersFound++;
if (!parentStructure[folderName]) { if (!parentStructure[folderName]) {
@@ -1638,15 +1638,15 @@
try { try {
await scanFolder(fullPath, parentStructure[folderName]); await scanFolder(fullPath, parentStructure[folderName]);
} catch (e) { } catch (e) {
console.warn(`[AcidWiki] ⚠️ Failed to scan subfolder ${fullPath}:`, e); console.warn(`[Bjorn] ⚠️ Failed to scan subfolder ${fullPath}:`, e);
} }
} else { } else {
debugLog(`[AcidWiki] ⏭️ Skipped non-markdown file: "${href}"`); debugLog(`[Bjorn] ⏭️ Skipped non-markdown file: "${href}"`);
} }
} }
debugLog(`[AcidWiki] ✓ Folder scan complete: ${filesFound} files, ${foldersFound} subfolders`); debugLog(`[Bjorn] ✓ Folder scan complete: ${filesFound} files, ${foldersFound} subfolders`);
debugLog(`[AcidWiki] 📊 Structure for "${path || 'root'}":`, Object.keys(parentStructure)); debugLog(`[Bjorn] 📊 Structure for "${path || 'root'}":`, Object.keys(parentStructure));
} }
// Start recursive scanning from root // Start recursive scanning from root
@@ -1668,12 +1668,12 @@
const sortedStructure = sortStructure(structure); const sortedStructure = sortStructure(structure);
const totalItems = JSON.stringify(sortedStructure).split('.md').length - 1; const totalItems = JSON.stringify(sortedStructure).split('.md').length - 1;
debugLog(`[AcidWiki] ✅ Scan complete! Found ${totalItems} markdown files`); debugLog(`[Bjorn] ✅ Scan complete! Found ${totalItems} markdown files`);
debugLog('[AcidWiki] 📊 Structure:', sortedStructure); debugLog('[Bjorn] 📊 Structure:', sortedStructure);
return Object.keys(sortedStructure).length > 0 ? sortedStructure : null; return Object.keys(sortedStructure).length > 0 ? sortedStructure : null;
} catch (e) { } catch (e) {
console.error('[AcidWiki] ❌ Local filesystem scan failed:', e); console.error('[Bjorn] ❌ Local filesystem scan failed:', e);
return null; return null;
} }
} }
@@ -1755,9 +1755,9 @@
content: text.toLowerCase(), content: text.toLowerCase(),
titleLower: (CONFIG.ui.rootReadmeTitle || "Project Home").toLowerCase() titleLower: (CONFIG.ui.rootReadmeTitle || "Project Home").toLowerCase()
}); });
debugLog("[AcidWiki] 🔍 Root README indexed."); debugLog("[Bjorn] 🔍 Root README indexed.");
}) })
.catch(e => console.warn("[AcidWiki] Failed to index README.md", e)) .catch(e => console.warn("[Bjorn] Failed to index README.md", e))
); );
} }
@@ -1779,7 +1779,7 @@
titleLower: CONFIG.ui.changelogTitle.toLowerCase(), titleLower: CONFIG.ui.changelogTitle.toLowerCase(),
isVirtual: true isVirtual: true
}); });
debugLog("[AcidWiki] 🔍 Changelog indexed."); debugLog("[Bjorn] 🔍 Changelog indexed.");
}) })
.catch(() => { }) .catch(() => { })
); );

View File

@@ -1,5 +1,5 @@
/** /**
* AcidWiki Configuration (Master Template) * Bjorn Wiki Configuration (Master Template)
* Ce fichier est écrasé dynamiquement par le workflow GitHub Actions. * Ce fichier est écrasé dynamiquement par le workflow GitHub Actions.
* Ne modifiez pas les valeurs ici pour un projet spécifique, utilisez acidwiki.json. * Ne modifiez pas les valeurs ici pour un projet spécifique, utilisez acidwiki.json.
*/ */