Social Sharing & SEO
Relevant source files
The following files were used as context for generating this wiki page:
- app/Support/Sharing/PostShareMetadata.php
- app/Support/Sharing/ShareUrlBuilder.php
- resources/views/components/sharing/share-buttons.blade.php
- resources/views/livewire/posts/post-show.blade.php
- app/Support/Import/OpenGraphParser.php
- tests/Feature/Sharing/PostShareMetadataTest.php
- tests/Feature/Sharing/ShareUrlBuilderTest.php
The Social Sharing & SEO module in RateGuru is responsible for managing how platform content is represented on social media and optimized for search engines. This system ensures that posts shared to external platforms like Facebook, X (formerly Twitter), and Telegram contain accurate metadata, high-quality preview images, and canonical links to prevent duplicate content issues.
The system is built around three core pillars: dynamic metadata generation for individual posts, a centralized URL builder for social platform integration, and an OpenGraph parser for handling external content references.
Metadata Management
RateGuru uses a structured approach to generate metadata for social platforms. The PostShareMetadata service transforms internal Post models into standardized ShareMetadata objects containing titles, descriptions, and absolute URLs.
Data Flow for Metadata Generation
When a post is viewed, the application generates specific OpenGraph and Twitter Card tags. If a post lacks a description, the system utilizes a fallback mechanism to ensure metadata fields are never empty.
SEO Meta Tags
On the post detail page, the application pushes specific SEO and social tags to the document head:
- Canonical Links: Used to specify the authoritative version of the post URL.
- OpenGraph (og:): Targets Facebook, LinkedIn, and Telegram.
- Twitter Cards (twitter:): Specifically handles "summary" or "summary_large_image" layouts based on the presence of a post image.
Sources: resources/views/livewire/posts/post-show.blade.php:3-16
Social Sharing Integration
Social sharing is implemented through a combination of a backend URL builder and a frontend UI component. The ShareUrlBuilder class handles the logic for constructing platform-specific sharing links with properly encoded parameters.
Supported Sharing Providers
| Provider | Mechanism | Requirements |
|---|---|---|
| sharer.php | Encoded URL | |
| X (Twitter) | intent/tweet | URL and Title |
| Telegram | share/url | URL and Text |
| wa.me | Text (Title + URL) | |
| pin/create/button | Requires Image URL | |
| submit | URL and Title | |
| mailto: | Subject and Body |
Sources: app/Support/Sharing/ShareUrlBuilder.php, tests/Feature/Sharing/ShareUrlBuilderTest.php:21-70
Share URL Generation Flow
The system validates whether a provider can support the available metadata (e.g., Pinterest requires an image) before returning a URL.
OpenGraph Parsing
To support external links and imports, RateGuru includes an OpenGraphParser. This service extracts metadata from external HTML content, providing a fallback chain to ensure high-quality data extraction even when standard OpenGraph tags are missing.
Extraction Logic & Fallbacks
The parser prioritizes tags in the following order:
- Title:
og:title->twitter:title-><title>tag. - Description:
og:description->twitter:description-><meta name="description">. - Image:
og:image->og:image:secure_url->twitter:image.
The parser also includes a resolveUrl method to convert relative image paths (e.g., /img/photo.jpg) or protocol-relative paths (e.g., //cdn.com/img.jpg) into absolute URLs based on the source page's scheme and host.
Sources: app/Support/Import/OpenGraphParser.php:12-45, tests/Feature/Import/OpenGraphParserTest.php:10-85
Implementation Summary
The sharing system is integrated into the UI via the share-buttons component and the post-show Livewire view.
// Example of the metadata fallback in PostShareMetadata.php
$description = $post->description ?: __('ui.post.share_fallback_description');
$url = route('posts.show', $post); // Resolved to absolute via config('app.url')
Sources: app/Support/Sharing/PostShareMetadata.php, tests/Feature/Sharing/PostShareMetadataTest.php:40-45
Key Technical Details
- Absolute URLs: All sharing and SEO URLs are forced to be absolute using
config('app.url')to ensure they function correctly when scraped by external bots. - Encoding: The
ShareUrlBuilderutilizesurlencode()for all query parameters to prevent breakage from special characters in post titles. - Conditional Rendering: Pinterest buttons are hidden if no image is available for the post.
Sources: app/Support/Sharing/ShareUrlBuilder.php, resources/views/components/sharing/share-buttons.blade.php, tests/Feature/Sharing/ShareUrlBuilderProviderUrlsTest.php:12-16