Blogging structure with SEO markup
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
blog/lib/meta.php

100 lines
2.9 KiB

<?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;
}
}