Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
freekmurze committed Jun 7, 2024
1 parent a4b5ab5 commit 93df8fd
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 33 deletions.
57 changes: 57 additions & 0 deletions app/Http/Controllers/InsightsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Http\Controllers;

use Spatie\ContentApi\ContentApi;
use Spatie\ContentApi\Data\Post;
use Spatie\Feed\FeedItem;

class InsightsController
{
public function index()
{
$posts = ContentApi::getPosts('ray', request('page', 1), theme: 'nord');

if (request('page', 1)) {
$firstPost = $posts->first();
unset($posts[0]);
}

return view('front.pages.insights.index', [
'posts' => $posts,
'firstPost' => $firstPost ?? null,
]);
}

public function detail(string $slug)
{
$post = ContentApi::getPost('spatie', $slug, theme: 'nord');

if (! $post && is_numeric(explode('-', $slug)[0])) {
$parts = explode('-', $slug);

$parts = array_slice($parts, 1);

return redirect(action([self::class, 'detail'], implode('-', $parts)), 301);
}

abort_if(is_null($post), 404);

return view('front.pages.insights.show', [
'post' => $post,
]);
}

public static function getFeedItems()
{
return ContentApi::getPosts('spatie', 1, 10_000, theme: 'nord')->map(function (Post $post) {
return FeedItem::create()
->id($post->slug)
->title($post->title)
->summary($post->summary)
->updated($post->updated_at)
->link(action([self::class, 'detail'], $post->slug))
->authorName($post->authors->first()?->name);
});
}
}
34 changes: 34 additions & 0 deletions app/Livewire/NewsletterComponent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Livewire;

use App\Actions\SubscribeUserToNewsletterAction;
use App\Services\Mailcoach\MailcoachApi;
use Livewire\Component;

class NewsletterComponent extends Component
{
public string $email = '';

public bool $submitted = false;

public function render()
{
return view('livewire.newsletter-component');
}

public function subscribe()
{
//TODO: make this work
$this->validate([
'email' => 'required|email',
]);

$mailcoach = app(MailcoachApi::class);

$subscriber = $mailcoach->subscribe(strtolower($this->email), skipConfirmation: true);
$subscriber->addTags('spatie-newsletter');

Check failure on line 30 in app/Livewire/NewsletterComponent.php

View workflow job for this annotation

GitHub Actions / phpstan

Call to an undefined method App\Services\Mailcoach\Subscriber::addTags().

$this->submitted = true;
}
}
2 changes: 2 additions & 0 deletions app/Providers/LivewireServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Livewire\ActivationsComponent;
use App\Livewire\DomainComponent;
use App\Livewire\LessonCompletedButtonComponent;
use App\Livewire\NewsletterComponent;
use App\Livewire\RepositoriesComponent;
use App\Livewire\SearchDocsComponent;
use Illuminate\Support\ServiceProvider;
Expand All @@ -19,5 +20,6 @@ public function register(): void
Livewire::component('domain', DomainComponent::class);
Livewire::component('activations', ActivationsComponent::class);
Livewire::component('search-docs', SearchDocsComponent::class);
Livewire::component('newsletter', NewsletterComponent::class);
}
}
2 changes: 1 addition & 1 deletion app/Providers/NavigationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function register(): void
->addItemClass('first:-m-1 first:p-1 rounded-sm')
->route('vacancies.index', 'Vacancies')
->route('about', 'About')
->route('blog', 'Blog')
->route('insights', 'insights')
->route('docs', 'Docs')
->route('guidelines', 'Guidelines')
->addIf(auth()->check(), View::create('layout.partials.navigation.profileIcon', ['url' => route('profile')]))
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"spatie/ray": "^1.36",
"spatie/schema-org": "^3.11",
"spatie/sheets": "^1.10",
"spatie/spatie-content-api": "^3.1",
"spatie/ssh": "^1.8",
"spatie/test-time": "^1.3",
"spatie/valuestore": "^1.3.1",
Expand Down
68 changes: 66 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 15 additions & 30 deletions config/feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,27 @@
return [
'feeds' => [
'main' => [
'items' => \App\Models\Insight::class . '@getFeedItems',
'items' => [\App\Http\Controllers\InsightsController::class, 'getFeedItems'],
'url' => '/feed',
'title' => 'All blogposts of the Spatie team',
//'view' => 'feeds.insights',

'description' => 'All blogposts of the Spatie team.',

'title' => 'All insights of the Spatie team',
'description' => 'All insights of the Spatie team.',
'language' => 'en-US',
'image' => '',
'format' => 'atom',
'view' => 'feed::atom',
'type' => '',
'contentType' => '',
],
'insights' => [
'items' => [\App\Models\Insight::class, 'getFeedItems'],
'url' => '/feed-insights',
'title' => 'All personal blogposts of the Spatie team',
'description' => 'All personal blogposts of the Spatie team.',
'language' => 'en-US',

/*
* The image to display for the feed. For Atom feeds, this is displayed as
* a banner/logo; for RSS and JSON feeds, it's displayed as an icon.
* An empty value omits the image attribute from the feed.
*/
'image' => '',

/*
* The format of the feed. Acceptable values are 'rss', 'atom', or 'json'.
*/
'format' => 'atom',

/*
* The view that will render the feed.
*/
'view' => 'feed::atom',

/*
* The mime type to be used in the <link> tag. Set to an empty string to automatically
* determine the correct value.
*/
'type' => '',

/*
* The content type for the feed response. Set to an empty string to automatically
* determine the correct value.
*/
'contentType' => '',
],
],
Expand Down
30 changes: 30 additions & 0 deletions resources/views/front/pages/insights/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<x-page title="Blog" background="/backgrounds/blogs.jpg">
<!-- @todo replace background -->

<section id="banner" class="banner" role="banner">
Insights
</section>

@if($firstPost)
@include('front.pages.insights.partials.firstPostListItem', ['post' => $firstPost])
@endif

<h2>
More insights
</h2>

<section class="section section-group">
<div class="wrap">
<div class="max-w-md grid gap-6">
@foreach($posts as $post)
@include('front.pages.insights.partials.postListItem')
@endforeach
</div>
<div class="mt-12">
{{ $posts->onEachSide(1)->links() }}
</div>
</div>
</section>

<livewire:newsletter />
</x-page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<article>
Last article

<div>
<time datetime="{{ $post->date->format('Y-m-d') }}">{{ $post->date->format('d F Y') }}</time>
</div>

{{ $post->title }}

<p>{{ htmlspecialchars_decode(strip_tags($post->summary)) }}</p>

</article>
23 changes: 23 additions & 0 deletions resources/views/front/pages/insights/partials/newsletter.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<div>
<div>
Get the latest from Spatie
</div>

<div>
<div>Logo</div>
<div>Powered by <a href="https://mailcoach.app">Mailcoach</a>, powerful email marketing tools to effortlessly grow, connect and convert.</div>
</div>

<div>
<div>
<form>
<input type="email" placeholder="Your email address">
<button>Subscribe</button>
</form>
</div>
<div>
Sign up for occasional emails on Spatie products and promotions.
By submitting this from, you acknowledge our [Privacy Policy]({{ route('legal.privacy') }}).
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<article>
<div>
<h3>
<a href="{{ route('insights.show', $post->slug) }}">
<span></span>
{{ $post->title }}
</a>
</h3>
<p>{{ htmlspecialchars_decode(strip_tags($post->summary)) }}</p>
</div>
@isset($post->date)
<div>
<time datetime="{{ $post->date->format('Y-m-d') }}">{{ $post->date->format('d F Y') }}</time>
</div>
@endisset
</article>
Empty file.
38 changes: 38 additions & 0 deletions resources/views/livewire/newsletter-component.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<div>
<div>
Get the latest from Spatie
</div>

<div>
<div>Logo</div>
<div>Powered by <a href="https://mailcoach.app">Mailcoach</a>, powerful email marketing tools to effortlessly
grow, connect and convert.
</div>
</div>

@if($submitted)
<div>
<div>
<h2>Thank you for subscribing!</h2>
<p>You'll receive a confirmation email shortly.</p>
</div>
</div>
@else
<div>
<div>
<div>
<input name="email" wire:model="email" type="email" placeholder="Your email address">
@error('email')
<div>{{ $message }}</div>
@enderror

<button wire:click="subscribe">Subscribe</button>
</div>
</div>
<div>
Sign up for occasional emails on Spatie products and promotions.
By submitting this from, you acknowledge our [Privacy Policy]({{ route('legal.privacy') }}).
</div>
</div>
@endif
</div>
Loading

0 comments on commit 93df8fd

Please sign in to comment.