承接 b3co/notion-mirror 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

b3co/notion-mirror

Composer 安装命令:

composer require b3co/notion-mirror

包简介

a notion mirror

README 文档

README

A PHP way to read Notion pages and (optionally) upload images and videos to an S3 bucket (and link accordingly).

This is my first package distributed through composer, bare with me.

Operation

Prepare Services

Notion

  1. you have to create a Notion integration here.
  2. since we’re not writing to Notion, at this time only read access is necessary
  3. grab the notion_token, something like secret_xxxxxxxxxx
  4. on every page you want to be read by this script, you need to share it with the integration as shown in the image, quite easy part but tricky to find

inline

my Notion integration is called page mirror, use your own, the one created on the first step ☝️

S3

  1. create an AWS S3 bucket
  2. grab the AWS_KEY, AWS_SECRET, AWS_REGION and BUCKET_NAME Note that by default, images will be uploading using the following structure: s3.AWS_REGION.amazonaws.com/BUCKET_NAME/PAGE_ID/public/image/IMAGE_ID.jpg

CLI Invocation

You have to create a $config object with the previously created services’ access variables as follows:

$config = [
  'notion_token' => 'NOTION_TOKEN',
  'aws_key'      => 'AWS_KEY',
  'aws_secret'   => 'AWS_SECRET',
  'aws_region'   => 'AWS_REGION',
  'bucket_name'  => 'BUCKET_NAME',
];

You now can invoke the Notion object.

$notion = new \b3co\notion\Notion($config);
$page   = $notion->getPage(PAGE_ID);
echo $page->toHtml();

Yii Invocation

First, on the config file either web.php or console.php add

$config = [
	...
	'components' => [
		...
		'notion' => [
			'class' => 'b3co\notion\YiiNotion',
		  'config' => [
		    'notion_token' => getenv('notion_token'),
		    'aws_key'      => getenv('aws_key'),
		    'aws_secret'   => getenv('aws_secret'),
		    'bucket_name'  => getenv('aws_bucket'),
		    'aws_region'   => getenv('aws_region'),
		  ]
		],
		...
  ]
	...
];

Second, use the YiiNotion object to get a Notion object and execute accordingly.

class NotionController extends Controller {

  public function actionIndex($id) {
    define('VERBOSE', false);
    $notion = Yii::$app->get('notion')->getNotion();
    $page = $notion->getPage($id);
    echo $page->toHtml();

    return ExitCode::OK;
  }
}

Templates (work in progress)

By default, three different export templates are set to each object:

  1. HTML with $page→toHtml()
  2. MarkDown with $page→toMd()
  3. Plain text with $page→toString()

Template families

Optionally you can use the template factory and create a template family under $config->templates_dir/TEMPLATE_FAMILY/ so if you invoke $page->toTemplate(TEMPLATE_FAMILY)
system will check for each block type template there, named as BLOCK_TYPE.template. For instance, for a template family called basic, you’ll have:

inline

Where image and page are block types.

Each template can use any given format/language and use objects’ attributes to be printed like [:ATTRIBUTE], for example an image with url and caption.

<div><img src='[:url]'>
  <div>[:caption]</div>
</div>

A complete list of objects and attributes is available here.

Important 🚨: If a template file is not found, that block will not be processed.

A note on toHtml method

HTML templating can be overwritten by creating a template family called html, if a block item template is found, will be used, if not, fail back will use the hardcoded HTML template.

Notion Objects

Supported Objects List

  • Paragraph blocks
  • Heading one blocks
  • Heading two blocks
  • Heading three blocks
  • Image blocks
  • To do blocks
  • Column List and Column Blocks
  • Quote blocks
  • Bulleted list item blocks
  • Code blocks
  • Toggle blocks
  • Divider blocks
  • Video blocks
  • Numbered list item blocks (tricky, work in progress)
  • Embed blocks
  • Equation blocks
  • Table row blocks
  • Table blocks
  • Callout blocks
  • Child page blocks

Out of Scope

  • Child database blocks
  • File blocks
  • PDF blocks
  • Bookmark blocks
  • Table of contents blocks
  • Breadcrumb blocks
  • Link Preview blocks
  • Template blocks
  • Link to page blocks
  • Synced Block blocks

This very README file is created and stored in Notion and converted to MD using this script, last update 2022-08-24 → .

b3co/notion-mirror 适用场景与选型建议

b3co/notion-mirror 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 08 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 b3co/notion-mirror 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 b3co/notion-mirror 我们能提供哪些服务?
定制开发 / 二次开发

基于 b3co/notion-mirror 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 48
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 6
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-24