-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerger.js
More file actions
112 lines (96 loc) · 3.73 KB
/
Copy pathmerger.js
File metadata and controls
112 lines (96 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const fs = require('fs');
const path = require('path');
function getBodyContent(htmlStr) {
const mainMatch = htmlStr.match(/<main[^>]*>([\s\S]*?)<\/main>/i);
return mainMatch ? mainMatch[1] : '';
}
const dirs = [
__dirname,
path.join(__dirname, 'SignalLM-Android', 'app', 'src', 'main', 'assets')
];
for (const dir of dirs) {
const indexHtmlPath = path.join(dir, 'index.html');
const editorHtmlPath = path.join(dir, 'editor.html');
const mcpHtmlPath = path.join(dir, 'mcp.html');
const settingsHtmlPath = path.join(dir, 'settings.html');
if (!fs.existsSync(indexHtmlPath)) continue;
let indexHtml = fs.readFileSync(indexHtmlPath, 'utf8');
// If already merged, skip
if (indexHtml.includes('id="view-chat"')) continue;
const editorHtml = fs.readFileSync(editorHtmlPath, 'utf8');
const mcpHtml = fs.readFileSync(mcpHtmlPath, 'utf8');
const settingsHtml = fs.readFileSync(settingsHtmlPath, 'utf8');
const editorContent = getBodyContent(editorHtml);
const mcpContent = getBodyContent(mcpHtml);
const settingsContent = getBodyContent(settingsHtml);
// Replace <main class="main-chat"> with <main class="main-app">
indexHtml = indexHtml.replace(/<main class="main-chat">([\s\S]*?)<\/main>/i, function(match, p1) {
return `<main class="main-app">
<div id="view-chat" class="app-view active">
${p1}
</div>
<div id="view-editor" class="app-view" style="display:none;">
${editorContent}
</div>
<div id="view-mcp" class="app-view" style="display:none;">
${mcpContent}
</div>
<div id="view-settings" class="app-view" style="display:none;">
${settingsContent}
</div>
</main>`;
});
// Update nav links
indexHtml = indexHtml.replace(/href="index\.html"/g, 'href="#chat"');
indexHtml = indexHtml.replace(/href="editor\.html"/g, 'href="#editor"');
indexHtml = indexHtml.replace(/href="mcp\.html"/g, 'href="#mcp"');
indexHtml = indexHtml.replace(/href="settings\.html"/g, 'href="#settings"');
// Update script tags: add the others
indexHtml = indexHtml.replace('</body>', `
<script src="editor.js"></script>
<script src="mcp.js"></script>
<script src="settings.js"></script>
<script src="signal-lm-mcp-file-path.js"></script>
<script>
// SPA Router
function handleRouting() {
const hash = window.location.hash || '#chat';
const views = document.querySelectorAll('.app-view');
views.forEach(v => {
v.style.display = 'none';
v.classList.remove('active');
});
const targetView = document.getElementById('view-' + hash.substring(1));
if (targetView) {
targetView.style.display = 'block';
targetView.classList.add('active');
} else {
document.getElementById('view-chat').style.display = 'block';
document.getElementById('view-chat').classList.add('active');
}
// Update active nav link
document.querySelectorAll('.nav-link').forEach(link => {
if (link.getAttribute('href') === hash) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
// Toggle sidebar on mobile when navigating
if (typeof window.toggleSidebar === 'function') {
window.toggleSidebar(false);
}
}
window.addEventListener('hashchange', handleRouting);
document.addEventListener('DOMContentLoaded', handleRouting);
</script>
</body>`);
// Add the additional CSS files to the head
indexHtml = indexHtml.replace('</head>', `
<link rel="stylesheet" href="editor.css">
<link rel="stylesheet" href="mcp.css">
<link rel="stylesheet" href="settings.css">
</head>`);
fs.writeFileSync(indexHtmlPath, indexHtml, 'utf8');
console.log('Merged HTML in ' + dir);
}