()
| 124 | |
| 125 | // 7. Add AppSearch component |
| 126 | const addSearchComponent = () => { |
| 127 | const content = fs.readFileSync(INDEX_MD_PATH, 'utf8'); |
| 128 | const lines = content.split('\n'); |
| 129 | |
| 130 | // Find frontmatter boundaries |
| 131 | const frontmatterIndices = []; |
| 132 | for (let i = 0; i < lines.length; i++) { |
| 133 | if (lines[i].trim() === '---') { |
| 134 | frontmatterIndices.push(i); |
| 135 | if (frontmatterIndices.length === 2) break; |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | if (frontmatterIndices.length < 2) { |
| 140 | handleError(`Could not find frontmatter markers in ${INDEX_MD_PATH}`); |
| 141 | } |
| 142 | |
| 143 | // Find content marker |
| 144 | let contentMarkerIndex = -1; |
| 145 | for (let i = 0; i < lines.length; i++) { |
| 146 | if (lines[i].startsWith('## Glossary')) { |
| 147 | contentMarkerIndex = i; |
| 148 | break; |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | if (contentMarkerIndex === -1) { |
| 153 | for (let i = 0; i < lines.length; i++) { |
| 154 | if (lines[i].startsWith('## ')) { |
| 155 | contentMarkerIndex = i; |
| 156 | break; |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | if (contentMarkerIndex === -1) { |
| 162 | handleError(`Could not find content marker in ${INDEX_MD_PATH}`); |
| 163 | } |
| 164 | |
| 165 | const headContent = lines.slice(0, contentMarkerIndex).join('\n'); |
| 166 | const tailContent = lines.slice(contentMarkerIndex).join('\n'); |
| 167 | |
| 168 | const newContent = `${headContent} |
| 169 | |
| 170 | <ClientOnly> |
| 171 | <AppSearch /> |
| 172 | </ClientOnly> |
| 173 | |
| 174 | <div class="app-search-content"> |
| 175 | |
| 176 | ${tailContent} |
| 177 | |
| 178 | </div>`; |
| 179 | |
| 180 | fs.writeFileSync(INDEX_MD_PATH, newContent); |
| 181 | }; |
| 182 | |
| 183 | addSearchComponent(); |
no test coverage detected