|
| 1 | +<?php |
| 2 | + |
| 3 | +require_once __DIR__.'/../vendor/autoload.php'; |
| 4 | + |
| 5 | +use Illuminate\Container\Container; |
| 6 | +use Illuminate\Events\Dispatcher; |
| 7 | +use Illuminate\Filesystem\Filesystem; |
| 8 | +use Illuminate\Support\Facades\Facade; |
| 9 | +use Illuminate\Support\Facades\View; |
| 10 | +use Illuminate\View\Compilers\BladeCompiler; |
| 11 | +use Illuminate\View\Engines\CompilerEngine; |
| 12 | +use Illuminate\View\Engines\EngineResolver; |
| 13 | +use Illuminate\View\Factory; |
| 14 | +use Illuminate\View\FileViewFinder; |
| 15 | +use Redberry\MdNotion\Adapters\BlockAdapterFactory; |
| 16 | +use Redberry\MdNotion\SDK\Notion; |
| 17 | +use Redberry\MdNotion\Services\BlockRegistry; |
| 18 | +use Redberry\MdNotion\Services\DatabaseReader; |
| 19 | +use Redberry\MdNotion\Services\DatabaseTable; |
| 20 | +use Redberry\MdNotion\Services\PageReader; |
| 21 | +use Redberry\MdNotion\Services\PropertiesTable; |
| 22 | + |
| 23 | +// Set up Laravel container |
| 24 | +$container = new Container; |
| 25 | +Container::setInstance($container); |
| 26 | + |
| 27 | +// Set up Facade root |
| 28 | +Facade::setFacadeApplication($container); |
| 29 | + |
| 30 | +// Register filesystem |
| 31 | +$container->singleton('files', fn () => new Filesystem); |
| 32 | + |
| 33 | +// Register blade compiler |
| 34 | +$container->singleton('blade.compiler', function ($app) { |
| 35 | + return new BladeCompiler( |
| 36 | + $app['files'], |
| 37 | + __DIR__.'/../storage/views' |
| 38 | + ); |
| 39 | +}); |
| 40 | + |
| 41 | +// Set up view finder |
| 42 | +$viewFinder = new FileViewFinder( |
| 43 | + $container['files'], |
| 44 | + [__DIR__.'/../resources/views'] |
| 45 | +); |
| 46 | + |
| 47 | +// Add namespace for our views |
| 48 | +$viewFinder->addNamespace('md-notion', __DIR__.'/../resources/views'); |
| 49 | + |
| 50 | +// Set up view factory |
| 51 | +$resolver = new EngineResolver; |
| 52 | +$resolver->register('blade', function () use ($container) { |
| 53 | + return new CompilerEngine($container['blade.compiler']); |
| 54 | +}); |
| 55 | + |
| 56 | +$factory = new Factory( |
| 57 | + $resolver, |
| 58 | + $viewFinder, |
| 59 | + new Dispatcher($container) |
| 60 | +); |
| 61 | + |
| 62 | +// Bind view factory to container |
| 63 | +$container->instance('view', $factory); |
| 64 | +View::setFacadeApplication($container); |
| 65 | + |
| 66 | +// Initialize the real Notion SDK with token |
| 67 | +$token = include __DIR__.'/../notion-token.php'; |
| 68 | +$notion = new Notion($token, '2025-09-03'); |
| 69 | + |
| 70 | +// Create services |
| 71 | +$mdNotionConfig = include __DIR__.'/../config/md-notion.php'; |
| 72 | +$blockRegistry = new BlockRegistry(new BlockAdapterFactory($notion, $mdNotionConfig['adapters'] ?? [])); |
| 73 | +$databaseTable = new DatabaseTable; |
| 74 | +$pageReader = new PageReader($notion, $blockRegistry); |
| 75 | +$databaseReader = new DatabaseReader($notion, $databaseTable); |
| 76 | +$propertiesTable = new PropertiesTable; |
| 77 | + |
| 78 | +// Bind services to container so Page objects can use them |
| 79 | +$container->instance(PropertiesTable::class, $propertiesTable); |
| 80 | + |
| 81 | +// Use a page ID that has properties (replace with your actual page ID) |
| 82 | +// This should be a page from your Notion workspace that has various properties |
| 83 | +$pageId = '263d9316605a80c0a8fbfd152e79b9d8'; // Replace with a page that has properties |
| 84 | + |
| 85 | +echo "Fetching page content with properties...\n"; |
| 86 | + |
| 87 | +try { |
| 88 | + // Read page |
| 89 | + $page = $pageReader->read($pageId); |
| 90 | + |
| 91 | + echo "Page fetched successfully!\n"; |
| 92 | + echo 'Page title: '.$page->getTitle()."\n"; |
| 93 | + echo 'Has properties: '.($page->hasProperties() ? 'Yes ('.count($page->getProperties()).')' : 'No')."\n"; |
| 94 | + echo 'Content length: '.strlen($page->getContent() ?? '')." characters\n\n"; |
| 95 | + |
| 96 | + // Build markdown content |
| 97 | + $markdown = ''; |
| 98 | + |
| 99 | + // Add page title |
| 100 | + $markdown .= $page->renderTitle(1)."\n\n"; |
| 101 | + |
| 102 | + // Add properties table if available |
| 103 | + if ($page->hasProperties()) { |
| 104 | + $markdown .= $page->renderPropertiesTable()."\n"; |
| 105 | + } |
| 106 | + |
| 107 | + // Add page content |
| 108 | + if ($page->hasContent()) { |
| 109 | + $markdown .= $page->getContent()."\n\n"; |
| 110 | + } |
| 111 | + |
| 112 | + // Save to file |
| 113 | + file_put_contents(__DIR__.'/properties-example.md', $markdown); |
| 114 | + |
| 115 | + echo "Page with properties table converted and saved to examples/properties-example.md\n"; |
| 116 | + echo "\nGenerated markdown:\n"; |
| 117 | + echo "---\n"; |
| 118 | + echo $markdown; |
| 119 | + echo "---\n"; |
| 120 | + |
| 121 | +} catch (\Exception $e) { |
| 122 | + echo 'Error: '.$e->getMessage()."\n"; |
| 123 | + echo "Stack trace:\n"; |
| 124 | + echo $e->getTraceAsString()."\n"; |
| 125 | +} |
0 commit comments