Knowledge to Web 是一个知识文章网页生成器,主要用途是将知识文章内容转换为精美的交互式网页,并根据内容自动生成配图。它适用于历史、科学、文化等各类知识主题。
主要能力方面,该工具可以根据提供的文章内容生成一个完整的 HTML 文件,包含响应式设计(适配移动端和桌面端)、精美的卡片式布局、AI 生成的配图、时间线可视化、图标和视觉元素,以及易错点提示,生成结果可直接在浏览器中打开查看。输出目录为 output/knowledge-web/。设计上使用 Tailwind CSS 框架,采用中文优化字体(Noto Sans SC / Noto Serif SC),支持自定义配色方案、卡片悬停效果、滚动时间线和响应式网格布局。
使用方式分为两种。方式一:提供 JSON 文件,运行命令行:python scripts/knowledge-to-web.py <content.json> [api_key] [--images N] [--style STYLE]。参数包括 content.json(文章内容的 JSON 文件,参考 assets/example-industrial-revolution.json)、api_key(Google API key,可选,如果已设置环境变量 GOOGLE_API_KEY)、--images N(生成图片数量,默认 5)、--style STYLE(图片风格,可选 historical/scientific/cultural/nature,默认 historical)、--no-images(跳过图片生成,仅生成 HTML)。方式二:通过 Skill 调用,例如 /knowledge-2-web 工业革命 包括背景、发展阶段、技术创新、社会影响等内容。
JSON 内容格式包括 title、subtitle、coreThesis、primaryColor、accentColor、causes(含 title、description)、timeline(含 time、title、description)、impacts(含 title、description)、perspectives(含 title、quote)、misconceptions(含 misconception、fact)。完整示例可参考 assets/example-industrial-revolution.json。
图片生成使用 Gemini Image API 自动生成配图,提供四种图片风格:historical(传统中国画风格,适合历史主题)、scientific(科学插图风格,适合科学概念)、cultural(文化艺术风格,适合文化主题)、nature(自然摄影风格,适合自然主题)。API 配置需要 Google API Key,可通过环境变量 export GOOGLE_API_KEY="your-api-key" 或命令行参数 python scripts/knowledge-to-web.py content.json your-api-key 设置。图片生成示例代码使用 google.genai 客户端、PIL 库,模型为 gemini-2.5-flash-image,通过 types.GenerateContentConfig 设置 response_modalities=['IMAGE'] 和 image_config 的 aspect_ratio 为 "16:9",然后从响应中提取 inline_data 保存图片。
脚本说明:knowledge-to-web.py 是主脚本,包含图片生成和 HTML 生成功能;generate-illustrations.py 是独立的插图生成器,可单独为知识文章生成配图;generate-template.js 是 JavaScript 模板生成器,用于前端动态生成 HTML。
示例用法包括:生成工业革命知识网页(含 5 张插图)python scripts/knowledge-to-web.py assets/example-industrial-revolution.json --images 5 --style historical;仅生成 HTML 不生成图片 python scripts/knowledge-to-web.py assets/example-industrial-revolution.json --no-images;使用科学风格生成 3 张插图 python scripts/knowledge-to-web.py content.json --images 3 --style scientific。
适用场景包括教学辅助材料制作、知识科普文章可视化、历史事件深度解析、科学概念图解说明、文化知识卡片展示等。
限制方面,资料未提供收费、价格、平台支持等具体信息,这些内容暂未提供。使用图片生成功能需要配置 Google API Key。