diff --git a/src/Actions/CreatesNewStaticPageSourceFile.php b/src/Actions/CreatesNewStaticPageSourceFile.php new file mode 100644 index 00000000..bd0be98b --- /dev/null +++ b/src/Actions/CreatesNewStaticPageSourceFile.php @@ -0,0 +1,89 @@ +title = $title; + $this->slug = Str::slug($title); + + $this->createPage($type); + } + + /** + * Create the page. + * + * @param string $type - The page type, either 'markdown' or 'blade' + * @throws \Exception if the page type is not 'markdown' or 'blade' + */ + public function createPage(string $type) + { + // Check that the page type is either 'markdown' or 'blade' + if ($type === MarkdownPage::class) { + return $this->createMarkdownFile(); + } + if ($type === BladePage::class) { + return $this->createBladeFile(); + } + + throw new \Exception('The page type must be either "markdown" or "blade"'); + } + + /** + * Create the Markdown file. + */ + public function createMarkdownFile() + { + return file_put_contents( + Hyde::path("_pages/{$this->slug}.md"), + "---\ntitle: {$this->title}\n---\n\n# {$this->title}\n" + ); + } + + /** + * Create the Blade file. + */ + public function createBladeFile() + { + return file_put_contents( + Hyde::path("resources/views/pages/{$this->slug}.blade.php"), + "@extends('hyde::layouts.app') +@section('content') +@php(\$title = \"{$this->title}\") + +
+

{$this->title}

+
+ +@endsection +"); + } +} \ No newline at end of file