rehankanak / laravel-notion-renderer
Laravel 包,用于将 Notion 页面转换为网页
Requires
- php: ^8.1
Requires (Dev)
- laravel/pint: ^1.0
README
此包使用 Notion API 将 Notion 页面中的所有块转换为 HTML。有关 Notion API 的更多详细信息,请参阅此页面:[https://developers.notion.com/](https://developers.notion.com/)
目前,Notion API 以 JSON 格式返回内容。您可以在以下链接中查看 JSON 格式的示例:[https://codebeautify.org/jsonviewer/y222f395f](https://codebeautify.org/jsonviewer/y222f395f),页面:[https://tested-wheel-e55.notion.site/Example-Page-6927be844d994e51bdda5f0c903f6788](https://tested-wheel-e55.notion.site/Example-Page-6927be844d994e51bdda5f0c903f6788)
我们的渲染器将 JSON 转换为 HTML(Markdown 转换正在进行中),您可以使用它来在您的 web 应用程序中渲染。
安装
您可以通过 composer 安装此包
composer require rehankanak/laravel-notion-renderer
用法
$pageHTML = (new NotionRenderer('yourPageId'))->html();
就这样 🎉
您的 Notion 页面现在已转换为 HTML,并可以在您的 web 应用程序中显示。
建议:我们建议使用 [https://tailwind.org.cn/docs/typography-plugin](https://tailwind.org.cn/docs/typography-plugin) 来样式化 HTML(或者您也可以使用您自己的 CSS 进行样式化)。
注意:NotionRenderer 类广泛使用了 Notion 的 Block API([https://developers.notion.com/reference/get-block-children](https://developers.notion.com/reference/get-block-children))来获取 Notion 页面的内容。此外,您的 API 密钥必须存在于 .env 文件中,有关更多详细信息,请检查包的 config 文件。
支持的块列表
目前仅支持以下块,但更多块即将推出。
- 段落
- 一级标题
- 二级标题
- 三级标题
- 引用
- 编号列表
- 项目符号列表
- 图片
- 表格
- 分隔符
完整块列表可在此处找到:[https://developers.notion.com/reference/block](https://developers.notion.com/reference/block)
注意:其他块正在开发中
服务类(可选使用)
此包包含以下服务类
NotionBlocks
- 通过指定的 ID 获取 Block 对象。([https://developers.notion.com/reference/get-block-children](https://developers.notion.com/reference/get-block-children))
用法
$notionPageAsBlocks = (new NotionBlocks())->fetch('yourPageId')
NotionDatabase
- 获取 Notion 数据库中包含的页面列表。([https://developers.notion.com/reference/post-database-query](https://developers.notion.com/reference/post-database-query))
用法
$notionDatabase = (new NotionDatabase())->fetch('yourDatabaseId')
NotionPage
- 通过指定的 Notion ID 获取 Page 对象。([https://developers.notion.com/reference/retrieve-a-page](https://developers.notion.com/reference/retrieve-a-page))
用法
$notionPage = (new NotionDatabase())->fetch('yourPageId')
注意
为此功能正常工作,您需要创建集成并将页面与集成共享。有关获取和创建集成的更多详细信息,请参阅此页面:[https://www.notion.so/my-integrations](https://www.notion.so/my-integrations)
致谢
许可协议
MIT 许可协议(MIT)。请参阅 [许可文件](https://github.com/zusamarehan/laravel-notion-renderer/blob/HEAD/LICENSE.md) 以获取更多信息。