()
| 486 | } |
| 487 | |
| 488 | async fetchAllInspirations() { |
| 489 | console.log('🚀 Starting to fetch CSS-Inspiration repository contents...'); |
| 490 | |
| 491 | try { |
| 492 | // 获取所有分类目录 |
| 493 | const categories = Object.keys(this.categoryMapping); |
| 494 | let totalProcessed = 0; |
| 495 | |
| 496 | for (const category of categories) { |
| 497 | console.log(`\n📁 Processing category: ${category} (${this.categoryMapping[category]})`); |
| 498 | |
| 499 | const files = await this.fetchDirectoryContents(category); |
| 500 | |
| 501 | for (const file of files) { |
| 502 | try { |
| 503 | console.log(` 📄 Processing: ${file.name}`); |
| 504 | |
| 505 | const filePath = `${category}/${file.name}`; |
| 506 | const content = await this.fetchFileContent(filePath); |
| 507 | |
| 508 | if (content) { |
| 509 | const parsedContent = this.parseMarkdownContent(content, category, file.name); |
| 510 | |
| 511 | if (parsedContent.title) { |
| 512 | const inspirationId = await this.saveToDatabase(category, file.name, parsedContent); |
| 513 | |
| 514 | // 保存代码片段 |
| 515 | await this.extractAndSaveCodeSnippets( |
| 516 | inspirationId, |
| 517 | parsedContent.htmlContent, |
| 518 | parsedContent.cssContent |
| 519 | ); |
| 520 | |
| 521 | // 生成完整的演示页面 |
| 522 | await this.generateCompleteDemo( |
| 523 | inspirationId, |
| 524 | parsedContent.title, |
| 525 | parsedContent.htmlContent, |
| 526 | parsedContent.cssContent |
| 527 | ); |
| 528 | |
| 529 | totalProcessed++; |
| 530 | console.log(` ✅ Saved: ${parsedContent.title}`); |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | // 添加延迟以避免速率限制 |
| 535 | await new Promise(resolve => setTimeout(resolve, 500)); |
| 536 | |
| 537 | } catch (error) { |
| 538 | console.error(` ❌ Error processing ${file.name}:`, error.message); |
| 539 | continue; |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | console.log(`\n🎉 CSS-Inspiration import completed! Processed ${totalProcessed} demos.`); |
| 545 | this.generateStats(); |
no test coverage detected