mirror of
https://github.com/zadam/trilium.git
synced 2025-12-07 16:04:23 +01:00
feat(docs): try to get images to load at least?
This commit is contained in:
parent
68a10a9813
commit
22c5651eeb
55
.github/scripts/sync-docs-to-wiki.ts
vendored
55
.github/scripts/sync-docs-to-wiki.ts
vendored
@ -235,39 +235,37 @@ async function getAllDirectories(dir: string): Promise<string[]> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fix image references in markdown files for wiki compatibility
|
* Fix references in markdown files for wiki compatibility
|
||||||
*
|
*
|
||||||
* The issue: Trilium exports markdown with URL-encoded references (spaces as %20)
|
* Issues fixed:
|
||||||
* but the actual image files have spaces in their names. GitHub wikis need
|
* 1. URL-encoded image references (spaces as %20) need to match actual filenames
|
||||||
* the references to match the actual filenames exactly.
|
* 2. Internal markdown links need to be converted to wiki syntax
|
||||||
|
* 3. Images can optionally use wiki syntax [[image.png]] for better compatibility
|
||||||
*/
|
*/
|
||||||
async function fixImageReferences(wikiDir: string): Promise<void> {
|
async function fixImageReferences(wikiDir: string): Promise<void> {
|
||||||
console.log('Fixing URL-encoded references in markdown files...');
|
console.log('Fixing references for GitHub Wiki compatibility...');
|
||||||
const mdFiles = await findFiles(wikiDir, ['.md']);
|
const mdFiles = await findFiles(wikiDir, ['.md']);
|
||||||
let fixedCount = 0;
|
let fixedCount = 0;
|
||||||
|
|
||||||
for (const file of mdFiles) {
|
for (const file of mdFiles) {
|
||||||
let content = await fs.readFile(file, 'utf-8');
|
let content = await fs.readFile(file, 'utf-8');
|
||||||
let modified = false;
|
let modified = false;
|
||||||
|
const originalContent = content;
|
||||||
|
|
||||||
// Fix URL-encoded image references
|
// Step 1: Fix URL-encoded image references
|
||||||
// Convert  to 
|
// Convert  to 
|
||||||
// This is needed because file names have actual spaces, not %20
|
content = content.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (match, alt, src) => {
|
||||||
const imagePattern = /!\[([^\]]*)\]\(([^)]+)\)/g;
|
|
||||||
const newContent = content.replace(imagePattern, (match, alt, src) => {
|
|
||||||
// Skip external URLs
|
// Skip external URLs
|
||||||
if (src.startsWith('http://') || src.startsWith('https://')) {
|
if (src.startsWith('http://') || src.startsWith('https://')) {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the path contains URL encoding, decode it
|
// Decode URL encoding if present
|
||||||
if (src.includes('%20') || src.includes('%')) {
|
if (src.includes('%')) {
|
||||||
try {
|
try {
|
||||||
const decodedSrc = decodeURIComponent(src);
|
const decodedSrc = decodeURIComponent(src);
|
||||||
modified = true;
|
|
||||||
return ``;
|
return ``;
|
||||||
} catch {
|
} catch {
|
||||||
// If decoding fails, leave it as is
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,22 +273,23 @@ async function fixImageReferences(wikiDir: string): Promise<void> {
|
|||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Also fix internal link references with URL encoding
|
// Step 2: Fix internal links - decode URL encoding but keep standard markdown format
|
||||||
const linkPattern = /\[([^\]]+)\]\(([^)]+)\)/g;
|
// GitHub Wiki actually supports standard markdown links with relative paths
|
||||||
const finalContent = newContent.replace(linkPattern, (match, text, href) => {
|
content = content.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (match, text, href) => {
|
||||||
// Skip external URLs and image references
|
// Skip external URLs, anchors, and images
|
||||||
if (href.startsWith('http://') || href.startsWith('https://') || href.match(/\.(png|jpg|jpeg|gif|svg)$/i)) {
|
if (href.startsWith('http://') ||
|
||||||
|
href.startsWith('https://') ||
|
||||||
|
href.startsWith('#') ||
|
||||||
|
href.match(/\.(png|jpg|jpeg|gif|svg)$/i)) {
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the path contains URL encoding, decode it
|
// Decode URL encoding for all internal links
|
||||||
if (href.includes('%20') || href.includes('%')) {
|
if (href.includes('%')) {
|
||||||
try {
|
try {
|
||||||
const decodedHref = decodeURIComponent(href);
|
const decodedHref = decodeURIComponent(href);
|
||||||
modified = true;
|
|
||||||
return `[${text}](${decodedHref})`;
|
return `[${text}](${decodedHref})`;
|
||||||
} catch {
|
} catch {
|
||||||
// If decoding fails, leave it as is
|
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -298,18 +297,20 @@ async function fixImageReferences(wikiDir: string): Promise<void> {
|
|||||||
return match;
|
return match;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (modified) {
|
// Check if content was modified
|
||||||
await fs.writeFile(file, finalContent, 'utf-8');
|
if (content !== originalContent) {
|
||||||
|
modified = true;
|
||||||
|
await fs.writeFile(file, content, 'utf-8');
|
||||||
const relativePath = path.relative(wikiDir, file);
|
const relativePath = path.relative(wikiDir, file);
|
||||||
console.log(` Fixed URL-encoded references in: ${relativePath}`);
|
console.log(` Fixed references in: ${relativePath}`);
|
||||||
fixedCount++;
|
fixedCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fixedCount > 0) {
|
if (fixedCount > 0) {
|
||||||
console.log(`Fixed URL-encoded references in ${fixedCount} files`);
|
console.log(`Fixed references in ${fixedCount} files`);
|
||||||
} else {
|
} else {
|
||||||
console.log('No URL-encoded references needed fixing');
|
console.log('No references needed fixing');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user