- Import
This commit is contained in:
@@ -254,6 +254,50 @@ final class ContentRepository
|
||||
return $this->find($slug, true) ?? [];
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $metadata */
|
||||
public function saveImported(string $slug, array $metadata, string $markdown, bool $rebuildIndex = true): array
|
||||
{
|
||||
$slug = self::slugify($slug !== '' ? $slug : (string) ($metadata['title'] ?? 'untitled'));
|
||||
if ($slug === '') {
|
||||
throw new RuntimeException('A title or slug is required.');
|
||||
}
|
||||
|
||||
$directory = $this->pagesRoot . '/' . $slug;
|
||||
if (!is_dir($directory)) {
|
||||
mkdir($directory, 0775, true);
|
||||
}
|
||||
|
||||
$date = (string) ($metadata['date'] ?? date('c'));
|
||||
$metadata = array_replace([
|
||||
'title' => self::titleFromSlug($slug),
|
||||
'type' => 'post',
|
||||
'status' => 'published',
|
||||
'date' => $date,
|
||||
'modified' => $metadata['modified'] ?? $date,
|
||||
'category' => 'Notes',
|
||||
'tags' => [],
|
||||
'summary' => '',
|
||||
'author' => 'Editor',
|
||||
'cover' => '',
|
||||
'allow_comments' => true,
|
||||
'menu_order' => 0,
|
||||
], $metadata);
|
||||
|
||||
$metadata['slug'] = $slug;
|
||||
$metadata['tags'] = self::normalizeList($metadata['tags'] ?? []);
|
||||
$metadata['allow_comments'] = self::toBool($metadata['allow_comments'] ?? true);
|
||||
|
||||
file_put_contents($directory . '/index.txt', $this->serialize($metadata, $markdown));
|
||||
$timestamp = strtotime((string) ($metadata['modified'] ?? $metadata['date'])) ?: time();
|
||||
touch($directory . '/index.txt', $timestamp);
|
||||
|
||||
if ($rebuildIndex) {
|
||||
$this->rebuildIndex();
|
||||
}
|
||||
|
||||
return $this->find($slug, true) ?? [];
|
||||
}
|
||||
|
||||
public function delete(string $slug): bool
|
||||
{
|
||||
$slug = self::slugify($slug);
|
||||
|
||||
Reference in New Issue
Block a user