56 lines
1.9 KiB
JavaScript
56 lines
1.9 KiB
JavaScript
|
|
const fs = require('fs');
|
||
|
|
const path = 'e:\\I code\\pages\\index\\index.js';
|
||
|
|
|
||
|
|
try {
|
||
|
|
let content = fs.readFileSync(path, 'utf8');
|
||
|
|
|
||
|
|
// Regex to match aiSchema: [...] and append layout
|
||
|
|
// We match "aiSchema": [ ... ] (multiline)
|
||
|
|
// And escape the replacement curlies
|
||
|
|
const regex = /("aiSchema":\s*\[[^\]]*\])/g;
|
||
|
|
|
||
|
|
let newContent = content.replace(regex, (match) => {
|
||
|
|
return match + ',\n layout: { type: \'grid\' }';
|
||
|
|
});
|
||
|
|
|
||
|
|
// Special handling for Celtic Cross
|
||
|
|
// Find the generated text for celtic_cross and replace grid with specific layout
|
||
|
|
// We need to look for "id": "celtic_cross" ... layout: { type: 'grid' }
|
||
|
|
|
||
|
|
const celticLayout = `layout: {
|
||
|
|
type: 'celtic',
|
||
|
|
areas: [
|
||
|
|
{ area: 'center', rotate: 0 },
|
||
|
|
{ area: 'center', rotate: 90 },
|
||
|
|
{ area: 'bottom' },
|
||
|
|
{ area: 'left' },
|
||
|
|
{ area: 'top' },
|
||
|
|
{ area: 'right' },
|
||
|
|
{ area: 'side' },
|
||
|
|
{ area: 'side' },
|
||
|
|
{ area: 'side' },
|
||
|
|
{ area: 'side' }
|
||
|
|
]
|
||
|
|
}`;
|
||
|
|
|
||
|
|
// Use a regex that finds the celtic_cross object and its layout
|
||
|
|
// Look for id: celtic_cross, then scan until layout: { type: 'grid' }
|
||
|
|
// This is tricky with regex.
|
||
|
|
// Let's just replacing the specific string unique to celtic cross context if possible.
|
||
|
|
|
||
|
|
// Easier: Split by "id": "celtic_cross"
|
||
|
|
const parts = newContent.split('"id": "celtic_cross"');
|
||
|
|
if (parts.length > 1) {
|
||
|
|
// part[1] starts after celtic_cross.
|
||
|
|
// Find the first layout: { type: 'grid' } in part[1] and replace it.
|
||
|
|
parts[1] = parts[1].replace("layout: { type: 'grid' }", celticLayout);
|
||
|
|
newContent = parts.join('"id": "celtic_cross"');
|
||
|
|
}
|
||
|
|
|
||
|
|
fs.writeFileSync(path, newContent, 'utf8');
|
||
|
|
console.log('Successfully updated index.js');
|
||
|
|
|
||
|
|
} catch (e) {
|
||
|
|
console.error('Error:', e);
|
||
|
|
}
|