première tentative d'export du body en md, pas très concluant
This commit is contained in:
parent
8c8295b677
commit
c4892e919c
16 changed files with 477 additions and 0 deletions
50
site/plugins/epub-export/index.php
Normal file
50
site/plugins/epub-export/index.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
Kirby::plugin('tonnom/epub-export', [
|
||||
'api' => [
|
||||
'routes' => [
|
||||
[
|
||||
'pattern' => 'epub-export/(:any)',
|
||||
'method' => 'POST',
|
||||
'action' => function () {
|
||||
$pageId = get('id');
|
||||
$page = page($pageId);
|
||||
throw new Exception($page);
|
||||
if (!$page) {
|
||||
throw new Exception("Page introuvable");
|
||||
}
|
||||
|
||||
// Markdown du champ Body
|
||||
$markdown = $page->body()->toMarkdown();
|
||||
|
||||
// Emplacement du fichier
|
||||
$root = kirby()->root('media') . '/exports';
|
||||
Dir::make($root);
|
||||
|
||||
$filename = $page->id() . '.md';
|
||||
$filepath = $root . '/' . $filename;
|
||||
|
||||
file_put_contents($filepath, $markdown);
|
||||
|
||||
return [
|
||||
'message' => 'OK',
|
||||
'file' => $filename,
|
||||
'path' => $filepath,
|
||||
'url' => kirby()->url('media') . '/exports/' . $filename,
|
||||
];
|
||||
}
|
||||
]
|
||||
]
|
||||
],
|
||||
|
||||
'sections' => [
|
||||
'epubexport' => [
|
||||
'props' => [
|
||||
'pageId' => function () {
|
||||
return $this->model()->id();
|
||||
},
|
||||
],
|
||||
'component' => 'export-button'
|
||||
]
|
||||
]
|
||||
]);
|
||||
Loading…
Add table
Add a link
Reference in a new issue