generated from spatie/package-skeleton-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle-fetch-example.php
More file actions
79 lines (62 loc) · 2.08 KB
/
toggle-fetch-example.php
File metadata and controls
79 lines (62 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Illuminate\Container\Container;
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Facade;
use Illuminate\Support\Facades\View;
use Illuminate\View\Compilers\BladeCompiler;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
use Illuminate\View\Factory;
use Illuminate\View\FileViewFinder;
use Redberry\MdNotion\Adapters\ToggleAdapter;
// Set up Laravel container
$container = new Container;
Container::setInstance($container);
// Set up Facade root
Facade::setFacadeApplication($container);
// Register filesystem
$container->singleton('files', fn () => new Filesystem);
// Register blade compiler
$container->singleton('blade.compiler', function ($app) {
return new BladeCompiler(
$app['files'],
__DIR__.'/../storage/views'
);
});
// Set up view finder
$viewFinder = new FileViewFinder(
$container['files'],
[__DIR__.'/../resources/views']
);
// Add namespace for our views
$viewFinder->addNamespace('md-notion', __DIR__.'/../resources/views');
// Set up view factory
$resolver = new EngineResolver;
$resolver->register('blade', function () use ($container) {
return new CompilerEngine($container['blade.compiler']);
});
$factory = new Factory(
$resolver,
$viewFinder,
new Dispatcher($container)
);
// Bind view factory to container
$container->instance('view', $factory);
View::setFacadeApplication($container);
use Redberry\MdNotion\SDK\Notion;
// Load toggle JSON
$toggleJson = file_get_contents(__DIR__.'/../BlockJsonExamples/ToggleJson.json');
$toggleBlock = json_decode($toggleJson, true);
// Initialize the real Notion SDK with token
$token = include __DIR__.'/../notion-token.php';
$notion = new Notion($token, '2025-09-03');
// Create and configure the adapter
$adapter = new ToggleAdapter;
$adapter->setSdk($notion);
// Convert to markdown
$markdown = $adapter->toMarkdown($toggleBlock);
// Save to file
file_put_contents(__DIR__.'/toggle.md', $markdown);
echo "Toggle block converted and saved to toggle.md\n";