PHP JavaScript

Streamlining Content Publishing: Dev.to Integration for Filament

Introduction

We've been working on the landing page project which serves as the main marketing site. A key aspect of this project involves streamlining content publishing across multiple platforms. We've recently integrated Dev.to publishing capabilities directly into our Filament admin panel, mirroring our existing LinkedIn publishing workflow.

The Challenge

Previously, publishing content to Dev.to required manual steps, including copying and pasting content, formatting, and scheduling. This was time-consuming and prone to errors. We wanted a more efficient and integrated solution.

The Solution

We implemented a new Filament action that allows us to publish posts directly to Dev.to from the admin panel. This includes:

  • Row-level actions: Publish individual posts directly from the table.
  • Bulk actions: Publish multiple posts simultaneously.
  • Scheduling: Schedule posts for future publication.

This functionality is facilitated by a DevtoPublishingCoordinator class, which handles the API interactions with Dev.to.

class DevtoPublishingCoordinator
{
    public function publish(Post $post, ?Carbon $publishAt = null):
    {
        // Format the post content for Dev.to
        $formattedContent = $this->formatContent($post->content);

        // Call the Dev.to API to publish the post
        $response = $this->devtoApi->createArticle([
            'title' => $post->title,
            'body_markdown' => $formattedContent,
            'published' => $publishAt === null, // Publish immediately if no schedule
            'published_at' => $publishAt ?->toIso8601String(),
        ]);

        return $response;
    }

    private function formatContent(string $content): string
    {
        // Apply Dev.to specific formatting rules (e.g., syntax highlighting)
        return $content;
    }
}

This class encapsulates the logic for authenticating with Dev.to, formatting the content, and making the API request.

Key Decisions

  • Replicated LinkedIn pattern: Ensured a consistent user experience by mirroring the existing LinkedIn publishing workflow.
  • Centralized publishing logic: Encapsulated the Dev.to API interaction within a dedicated coordinator class.
  • Support for scheduling: Allowed users to schedule posts for future publication.

Results

  • Reduced the time required to publish content to Dev.to.
  • Improved consistency in formatting and presentation.
  • Streamlined the overall content publishing workflow.

Lessons Learned

Integrating with third-party APIs can be simplified by creating dedicated coordinator classes that encapsulate the API interaction logic. This improves code organization and maintainability. When designing new features, consider mirroring existing patterns to provide a consistent user experience.

Streamlining Content Publishing: Dev.to Integration for Filament
Gerardo Ruiz

Gerardo Ruiz

Author

Share: