Skip to content

Commit 275530b

Browse files
committed
quick and simple gb cards conversion on migration
1 parent 537baad commit 275530b

File tree

1 file changed

+80
-6
lines changed

1 file changed

+80
-6
lines changed

site/scripts/convert-gitbook-to-docusaurus.js

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,75 @@ function fixLinks(content, filePath, version) {
12711271
return { content, modified };
12721272
}
12731273

1274+
/**
1275+
* Convert GitBook card tables to Docusaurus-compatible card layout
1276+
*/
1277+
function convertGitBookCards(content) {
1278+
let modified = false;
1279+
1280+
// Match GitBook card tables
1281+
const cardTablePattern = /<table[^>]*data-view="cards"[^>]*>[\s\S]*?<\/table>/g;
1282+
1283+
content = content.replace(cardTablePattern, (match) => {
1284+
modified = true;
1285+
1286+
// Extract card data from the table
1287+
const cards = [];
1288+
const rowPattern = /<tr>[\s\S]*?<\/tr>/g;
1289+
const rows = match.match(rowPattern) || [];
1290+
1291+
// Skip header row
1292+
for (let i = 1; i < rows.length; i++) {
1293+
const row = rows[i];
1294+
1295+
// Extract cells from row
1296+
const cellPattern = /<td>[\s\S]*?<\/td>/g;
1297+
const cells = row.match(cellPattern) || [];
1298+
1299+
if (cells.length >= 2) {
1300+
// First cell contains the link and title
1301+
const titleCell = cells[0];
1302+
const titleMatch = titleCell.match(/<a[^>]*href="([^"]*)"[^>]*><strong>(.*?)<\/strong><\/a>/);
1303+
1304+
// Second cell contains the description
1305+
const descCell = cells[1];
1306+
const descMatch = descCell.match(/<td>(.*?)<\/td>/);
1307+
1308+
if (titleMatch && descMatch) {
1309+
cards.push({
1310+
href: titleMatch[1],
1311+
title: titleMatch[2],
1312+
description: descMatch[1]
1313+
});
1314+
}
1315+
}
1316+
}
1317+
1318+
// Generate simplified card grid
1319+
// Using a simple grid layout that will work with Docusaurus
1320+
let cardHtml = '<div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; margin: 2rem 0;">\n';
1321+
1322+
for (const card of cards) {
1323+
cardHtml += ` <div style="border: 1px solid #e0e0e0; border-radius: 8px; padding: 1.5rem; transition: box-shadow 0.2s;">
1324+
<h3 style="margin-top: 0;">
1325+
<a href="${card.href}" style="text-decoration: none; color: inherit;">
1326+
${card.title}
1327+
</a>
1328+
</h3>
1329+
<p style="margin-bottom: 0; color: #666;">
1330+
${card.description}
1331+
</p>
1332+
</div>\n`;
1333+
}
1334+
1335+
cardHtml += '</div>';
1336+
1337+
return cardHtml;
1338+
});
1339+
1340+
return { content, modified };
1341+
}
1342+
12741343
/**
12751344
* Main conversion function
12761345
*/
@@ -1292,32 +1361,37 @@ function convertFile(filePath, targetPath, docsDir, outputDir, options = {}) {
12921361
// Apply conversions in order
12931362
let result;
12941363

1295-
// 1. GitBook syntax conversion
1364+
// 1. GitBook cards conversion (do this early before other HTML processing)
1365+
result = convertGitBookCards(content);
1366+
content = result.content;
1367+
totalModified = totalModified || result.modified;
1368+
1369+
// 2. GitBook syntax conversion
12961370
result = convertGitBookSyntax(content);
12971371
content = result.content;
12981372
totalModified = totalModified || result.modified;
12991373

1300-
// 2. MDX syntax fixes
1374+
// 3. MDX syntax fixes
13011375
result = fixMDXSyntax(content, filePath);
13021376
content = result.content;
13031377
totalModified = totalModified || result.modified;
13041378

1305-
// 3. Image path fixes
1379+
// 4. Image path fixes
13061380
result = fixImagePaths(content, version);
13071381
content = result.content;
13081382
totalModified = totalModified || result.modified;
13091383

1310-
// 4. Version-specific fixes FIRST (before general fixes)
1384+
// 5. Version-specific fixes FIRST (before general fixes)
13111385
result = applyVersionSpecificFixes(content, filePath, version);
13121386
content = result.content;
13131387
totalModified = totalModified || result.modified;
13141388

1315-
// 5. General link fixes (after version-specific)
1389+
// 6. General link fixes (after version-specific)
13161390
result = fixLinks(content, filePath, version);
13171391
content = result.content;
13181392
totalModified = totalModified || result.modified;
13191393

1320-
// 6. Release notes processing
1394+
// 7. Release notes processing
13211395
result = processReleaseNotes(content, filePath, version);
13221396
content = result.content;
13231397
totalModified = totalModified || result.modified;

0 commit comments

Comments
 (0)