Skip to content

Commit 0fea354

Browse files
committed
WIP
- Working on searching virtual page
1 parent 87984d6 commit 0fea354

File tree

1 file changed

+29
-34
lines changed

1 file changed

+29
-34
lines changed

site/config/routes.php

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,45 +35,40 @@
3535
]);
3636
}
3737
],
38+
[
39+
'pattern' => '/second',
40+
'method' => 'get',
41+
'action' => function () {
42+
return Page::factory([
43+
'slug' => 'second',
44+
'template' => 'search',
45+
'content' => [
46+
'title' => 'Andrea\'s search information',
47+
'subtitle' => 'Andrea\'s search information',
48+
'published_at' => '2025-03-11',
49+
]
50+
]);
51+
}
52+
],
3853
[
3954
'pattern' => '/andrea/url/(:any)',
4055
'method' => 'get',
41-
'action' => function ($slug) {
42-
// Define el ID de la página de Notion que deseas recuperar
43-
$notionPageId = 'Ciclo-de-vida-de-software-1754e2b34628803b9557cd1d9d07370a';
44-
45-
// Configura los encabezados necesarios para la API de Notion
46-
$headers = [
47-
'Authorization' => 'Bearer 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',
48-
'Notion-Version' => '2021-08-16',
49-
];
50-
51-
// Realiza la solicitud GET a la API de Notion
52-
$response = Remote::get("https://api.notion.com/v1/pages/{$notionPageId}", [
53-
'headers' => $headers
56+
'action' => function () {
57+
$mock = Remote::get('https://jsonplaceholder.typicode.com/posts/1');
58+
59+
$content = (object) json_decode($mock->content(), true);
60+
return Page::factory([
61+
'slug' => 'first',
62+
'template' => 'article',
63+
'content' => [
64+
'title' => $content->title,
65+
'subtitle' => $content->title,
66+
'published_at' => '2025-03-11',
67+
'blocks' => $content->body,
68+
]
5469
]);
55-
56-
// Verifica si la respuesta es exitosa
57-
if ($response->code() === 200) {
58-
$content = json_decode($response->content(), true);
59-
60-
// Procesa el contenido según la estructura de tu página en Notion
61-
return Page::factory([
62-
'slug' => $slug,
63-
'template' => 'article',
64-
'content' => [
65-
'title' => $content['properties']['title']['title'][0]['text']['content'],
66-
'subtitle' => $content['properties']['subtitle']['rich_text'][0]['text']['content'],
67-
'published_at' => $content['properties']['published_at']['date']['start'],
68-
'blocks' => $content['properties']['content']['rich_text'][0]['text']['content'],
69-
]
70-
]);
71-
} else {
72-
// Maneja el error en caso de que la solicitud falle
73-
return 'Error al obtener datos de Notion';
74-
}
7570
}
76-
],
71+
],
7772
[
7873
'pattern' => '/search',
7974
'method' => 'get',

0 commit comments

Comments
 (0)