parent
a2b77b5a93
commit
2ffa1b2267
@ -0,0 +1,40 @@ |
|||||||
|
1. Twitter Cards (twitter:*) |
||||||
|
• Platforms: Twitter, X (formerly Twitter), TweetDeck, some news aggregators. |
||||||
|
• Purpose: Provides rich media snippets when links are shared, including title, description, image, and card type (e.g., summary, player, app). |
||||||
|
• Example: |
||||||
|
|
||||||
|
<meta name="twitter:card" content="summary_large_image"> |
||||||
|
<meta name="twitter:site" content="@example"> |
||||||
|
<meta name="twitter:title" content="Example Title"> |
||||||
|
<meta name="twitter:description" content="Example Description"> |
||||||
|
<meta name="twitter:image" content="https://example.com/image.jpg"> |
||||||
|
|
||||||
|
2. Open Graph (og:*) |
||||||
|
• Platforms: Facebook, LinkedIn, WhatsApp, Slack, Discord, Reddit, Microsoft Teams, Telegram, and more. |
||||||
|
• Purpose: Defines how links are previewed, including titles, images, descriptions, and types. |
||||||
|
• Example: |
||||||
|
|
||||||
|
<meta property="og:title" content="Example Title"> |
||||||
|
<meta property="og:description" content="Example Description"> |
||||||
|
<meta property="og:image" content="https://example.com/image.jpg"> |
||||||
|
<meta property="og:url" content="https://example.com"> |
||||||
|
<meta property="og:type" content="website"> |
||||||
|
|
||||||
|
3. Schema.org (itemprop) |
||||||
|
• Platforms: Google, Bing, Yandex, and other search engines. |
||||||
|
• Purpose: Provides structured data for better search visibility, rich snippets, and enhanced knowledge panels. |
||||||
|
• Example: |
||||||
|
|
||||||
|
<meta itemprop="name" content="Example Title"> |
||||||
|
<meta itemprop="description" content="Example Description"> |
||||||
|
<meta itemprop="image" content="https://example.com/image.jpg"> |
||||||
|
|
||||||
|
4. Other Specialized Tags |
||||||
|
• Pinterest: Uses og:image and og:description for rich pins. |
||||||
|
• Reddit: Often pulls og:title and og:description. |
||||||
|
• Discord: Prioritizes og: tags for link previews. |
||||||
|
• Slack: Also prefers og: and twitter: tags. |
||||||
|
• Microsoft Teams: Uses Open Graph for link cards. |
||||||
|
• Telegram: Uses Open Graph for link previews. |
||||||
|
|
||||||
|
|
||||||
@ -0,0 +1,100 @@ |
|||||||
|
<?php |
||||||
|
# Request Content-Type |
||||||
|
stripos($_SERVER['CONTENT_TYPE'], 'application/json') === 0; // ✅ true |
||||||
|
$data = json_decode(file_get_contents('php://input'), true); |
||||||
|
|
||||||
|
|
||||||
|
function generateCard($title, $url, $image, $description = '') { |
||||||
|
return <<<HTML |
||||||
|
<div class="card mb-4" style="width: 18rem;"> |
||||||
|
<a href="{$url}" class="text-decoration-none text-reset"> |
||||||
|
<img src="{$image}" class="card-img-top" alt="{$title}"> |
||||||
|
<div class="card-body"> |
||||||
|
<h5 class="card-title">{$title}</h5> |
||||||
|
<p class="card-text">{$description}</p> |
||||||
|
</div> |
||||||
|
</a> |
||||||
|
</div> |
||||||
|
HTML; |
||||||
|
} |
||||||
|
|
||||||
|
$meta['title'] = $meta['title'] !== '' ? $meta['title'] : 'Home'; |
||||||
|
$meta['title'] ??= ucfirst(str_replace('/', '', $path)) ?: 'Home'; |
||||||
|
|
||||||
|
function extractMeta($directory) { |
||||||
|
$metaData = []; |
||||||
|
|
||||||
|
if (!is_dir($directory)) { |
||||||
|
throw new Exception("Directory not found: $directory"); |
||||||
|
} |
||||||
|
|
||||||
|
foreach (new DirectoryIterator($directory) as $file) { |
||||||
|
if ($file->isFile() && $file->getExtension() === 'md') { |
||||||
|
$contents = file_get_contents($file->getPathname()); |
||||||
|
|
||||||
|
// Extract title and image from the front matter |
||||||
|
if (preg_match('/^-{3,}\s*(.*?)\s*-{3,}/s', $contents, $matches)) { |
||||||
|
$frontMatter = $matches[1]; |
||||||
|
|
||||||
|
// Extract title |
||||||
|
preg_match('/title:\s*(.*?)\s*$/m', $frontMatter, $titleMatch); |
||||||
|
$title = trim($titleMatch[1] ?? ''); |
||||||
|
|
||||||
|
// Extract image |
||||||
|
preg_match('/image:\s*(.*?)\s*$/m', $frontMatter, $imageMatch); |
||||||
|
$image = trim($imageMatch[1] ?? ''); |
||||||
|
|
||||||
|
$metaData[$file->getFilename()] = [ |
||||||
|
'title' => $title, |
||||||
|
'image' => $image, |
||||||
|
]; |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $metaData; |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
$file = '/path/to/your/file.txt'; |
||||||
|
|
||||||
|
if (file_exists($file)) { |
||||||
|
$modTime = filemtime($file); |
||||||
|
echo "Last modified: " . date(DATE_RFC2822, $modTime); |
||||||
|
} else { |
||||||
|
echo "File not found."; |
||||||
|
} |
||||||
|
|
||||||
|
echo realpath($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME']); |
||||||
|
|
||||||
|
function render_meta($config, $core = [], $options = []) { |
||||||
|
// Default options |
||||||
|
$defaults = [ |
||||||
|
'ogm' => false, |
||||||
|
'twitter' => false, |
||||||
|
'schema' => true, |
||||||
|
]; |
||||||
|
|
||||||
|
// Merge provided options with defaults |
||||||
|
$options = array_merge($defaults, $options); |
||||||
|
|
||||||
|
// Example usage |
||||||
|
var_dump($options); |
||||||
|
} |
||||||
|
|
||||||
|
function compareDates($date1, $date2) { |
||||||
|
try { |
||||||
|
// Normalize both dates to the same format (ISO 8601) |
||||||
|
$normalized1 = (new DateTime($date1))->format('Y-m-d'); |
||||||
|
$normalized2 = (new DateTime($date2))->format('Y-m-d'); |
||||||
|
|
||||||
|
// Return comparison result |
||||||
|
return strcmp($normalized1, $normalized2); |
||||||
|
} catch (Exception $e) { |
||||||
|
// Handle invalid date formats |
||||||
|
trigger_error("Invalid date format: " . $e->getMessage(), E_USER_WARNING); |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
Loading…
Reference in new issue