Skip to content

Commit ecdd157

Browse files
authored
Merge pull request #9 from RedberryProducts/page-properties-table
Page properties table
2 parents e9b5a2c + d883376 commit ecdd157

11 files changed

Lines changed: 1441 additions & 0 deletions

File tree

‎examples/properties-example.md‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Test DB item 1
2+
3+
| Property | Value |
4+
| --- | --- |
5+
| CheckboxField | ✓ |
6+
| Type | type-1 |
7+
| Email | [test@gogmail.com](mailto:test@gogmail.com) |
8+
| Date | 2025-09-02 |
9+
| Status | In progress |
10+
| Priority Level | 3, 2 |
11+
| Files & media | [ChatGPT Image Sep 3, 2025, 09_59_04 PM.png](https://prod-files-secure.s3.us-west-2.amazonaws.com/0d31a281-d71e-4bb9-9031-a5256095b873/641f2fcb-cf13-4c62-8d9d-2871f34a1a6a/ChatGPT_Image_Sep_3_2025_09_59_04_PM.png?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Content-Sha256=UNSIGNED-PAYLOAD&X-Amz-Credential=ASIAZI2LB466TSVKJSYL%2F20251113%2Fus-west-2%2Fs3%2Faws4_request&X-Amz-Date=20251113T142329Z&X-Amz-Expires=3600&X-Amz-Security-Token=IQoJb3JpZ2luX2VjEIb%2F%2F%2F%2F%2F%2F%2F%2F%2F%2FwEaCXVzLXdlc3QtMiJHMEUCIFRgCBhDrbx1BLqDYCSDBN0nKqfqOJQCDDgcaAlS7FlFAiEA61lIOYodqWb175B59GZ0I5UZAEVGESLENFu7u63l7yQq%2FwMITxAAGgw2Mzc0MjMxODM4MDUiDOjdkbEDAHH2feRgTCrcA52bxAy4SCWSISHqMfTFKV2hIXhxNoozmqaLUe2h2J4ZyCkPy7PoUDxaQ50Lz22Ef4qtAfpfuhfjDxG7U31MZuOVyVL8FHY7HLgkfG9xa%2Fmde0rvJRbVB0jVDJ6IPUYXnIVFt2i99jm20Y69%2Frxqdpojjf8qYXZ%2BFhLKyvEQMVtkf8JoGs5d%2BdzA8%2FKW1tfyTArdYlr9hwPge8%2BtBiFVGbtCtUzmYsQ6DgE8AQSvdaymhlyWZLGMXLM8teiVvygXfj1UmBgphObTgP5bHpzMAUkcGKr2Tgy6oeGmRPru2iajdVZanlXbliixd%2B89y0cYy%2F2TW7EI7qQTbb71hyoG72k4pb9Fe%2B4wNXcX42cC%2FuURsVdmfhjxLP%2FwmGuuJuKZAaIvPQBBvBQZR8uX4kcXHA5EP8B4H5Q16%2BpImFcREddY4dV4ge4zdQ7bRkfvtKDqB5GZOao3fYB59gow222KG1AEuf4q0m68QmeSye9tleUxG21mLpYRwd97Hb%2BZUQd%2F8YETrqMcQgJPla%2FIuR71zpRaMTt%2FCdsbhH0qudsDOMJO1cEvDnfF1dhA3ktdyMfDWcNplz5Y0XG8FvkJ1TvNAODiTC%2F9ToHstPj76i%2BUdP9wQFlVoEEoNwLnWeoSMPHC18gGOqUB1DXrEJu41npTQQ2drVOjvBH0Ce2PT4mEx7SJpUJYL1o53dsHF3vvXPvlivx1pp6azmVDYwsAlFncBNTwBBm6rkytMfi4vC9GgB5ovSwCGNuWgQpYm8ZQuy5SYZ4Rgq1pI6Sqz75B1fnUgOa7bHAJrTfZ%2FdaHISPNwbsWULzDE44jpADZk9mxdmROHT1S6Urgn38UlZlo9iAqH2ffG4YjK%2B3HMKWR&X-Amz-Signature=6f39e1d0620132a3ed8b664b8b99adf82929e79cf1dd8f561a2a1153803f36be&X-Amz-SignedHeaders=host&x-amz-checksum-mode=ENABLED&x-id=GetObject) |
12+
| Person | Maestro Error |
13+
| Name | Test DB item 1 |
14+
15+
16+
17+
18+
> 💪 Test callout
19+
20+
21+
22+
23+
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
}

‎resources/views/full-md.blade.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11

22
{!! $current_page['title'] !!}
33

4+
@if($current_page['hasPropertiesTable'])
5+
6+
{!! $current_page['properties_table'] !!}
7+
@endif
48
@if($current_page['hasContent'])
59

610
{!! $current_page['content'] !!}

‎resources/views/page-md.blade.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
{!! $current_page['title'] !!}
22

3+
@if($current_page['hasPropertiesTable'])
4+
5+
{!! $current_page['properties_table'] !!}
6+
@endif
37
@if($current_page['hasContent'])
48

59
{!! $current_page['content'] !!}
@@ -25,6 +29,10 @@
2529
@foreach($child_pages as $childPage)
2630
{!! $childPage['title'] !!}
2731

32+
@if($childPage['hasPropertiesTable'])
33+
34+
{!! $childPage['properties_table'] !!}
35+
@endif
2836
@if($childPage['hasContent'])
2937
{!! $childPage['content'] !!}
3038

‎src/ContentBuilder.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ public function read(): string
8181
// Build structured data for template
8282
$currentPage = [
8383
'title' => $page->renderTitle(1),
84+
'properties_table' => $page->hasProperties() ? $page->renderPropertiesTable() : null,
85+
'hasPropertiesTable' => $page->hasProperties(),
8486
'content' => $page->hasContent() ? $page->getContent() : null,
8587
'hasContent' => $page->hasContent(),
8688
];
@@ -101,6 +103,8 @@ public function read(): string
101103
foreach ($page->getChildPages() as $childPage) {
102104
$childPages[] = [
103105
'title' => $childPage->renderTitle(3),
106+
'properties_table' => $childPage->hasProperties() ? $childPage->renderPropertiesTable() : null,
107+
'hasPropertiesTable' => $childPage->hasProperties(),
104108
'content' => $childPage->hasContent() ? $childPage->getContent() : null,
105109
'hasContent' => $childPage->hasContent(),
106110
];

‎src/MdNotion.php‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ private function buildFullMarkdownData($page, $level = 1): array
115115
{
116116
$currentPage = [
117117
'title' => $page->renderTitle($level),
118+
'properties_table' => $page->hasProperties() ? $page->renderPropertiesTable() : null,
119+
'hasPropertiesTable' => $page->hasProperties(),
118120
'content' => $page->hasContent() ? $page->getContent() : null,
119121
'hasContent' => $page->hasContent(),
120122
];

‎src/Objects/Page.php‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ public function fetch(): static
170170
return $this;
171171
}
172172

173+
/**
174+
* Render properties as markdown table
175+
*
176+
* @return string The properties table markdown
177+
*/
178+
public function renderPropertiesTable(): string
179+
{
180+
if (! $this->hasProperties()) {
181+
return '';
182+
}
183+
184+
$propertiesTable = app(\Redberry\MdNotion\Services\PropertiesTable::class);
185+
186+
return $propertiesTable->convertPropertiesToMarkdownTable($this->properties);
187+
}
188+
173189
/**
174190
* Convert the page to an array
175191
*/

0 commit comments

Comments
 (0)