|
38 | 38 | [ |
39 | 39 | 'pattern' => '/andrea/url/(:any)', |
40 | 40 | 'method' => 'get', |
41 | | - 'action' => function () { |
42 | | - $mock = Remote::get('https://jsonplaceholder.typicode.com/posts/1'); |
43 | | - |
44 | | - $content = (object) json_decode($mock->content(), true); |
45 | | - return Page::factory([ |
46 | | - 'slug' => 'first', |
47 | | - 'template' => 'article', |
48 | | - 'content' => [ |
49 | | - 'title' => $content->title, |
50 | | - 'subtitle' => $content->title, |
51 | | - 'published_at' => '2025-03-11', |
52 | | - 'blocks' => $content->body, |
53 | | - ] |
| 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 |
54 | 54 | ]); |
| 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 | + } |
55 | 75 | } |
56 | | - ], |
| 76 | + ], |
57 | 77 | [ |
58 | 78 | 'pattern' => '/search', |
59 | 79 | 'method' => 'get', |
|
0 commit comments