return $Parsedown->text($markdown);
}
+class PostMetadata {
+ public $hero_image;
+ public $hero_image_alt;
+
+ public function __construct($dict) {
+ $this->hero_image = $dict['post_hero_image'];
+ $this->hero_image_alt = $dict['post_hero_image_alt'];
+ }
+}
+
class Post {
public $id;
public $title;
$this->html_excerpt = mk_markdown($segments[0]);
}
}
+
+ public function get_metadata() {
+ $data = [];
+
+ $doc = new DOMDocument();
+ $doc->loadHTML($this->html_content);
+
+ $image_tag = $doc->getElementsByTagName('img')[0];
+
+ if ($image_tag != null) {
+ $data['post_hero_image'] = $image_tag->getAttribute('src');
+ $data['post_hero_image_alt'] = htmlspecialchars($image_tag->getAttribute('alt'));
+ }
+
+ return new PostMetadata($data);
+ }
}
function cx_post_make_slug($title) {
<?php
-function cx_template_render($class, $name, $variables = []) {
+function cx_template_render($class, $name, $variables = null) {
global $cx_template_base, $cx_template_content;
$base_template = null;
$path = join(DIRECTORY_SEPARATOR, $segments);
$base_template = null;
+ $base_template_variables = null;
$cx_template_base_previous = $cx_template_base;
- $cx_template_base = function($name) use (&$base_template ) {
+ $cx_template_base = function($name, $base_variables) use (&$base_template, &$base_template_variables) {
$base_template = $name;
+ $base_template_variables = $base_variables;
};
$cx_template_content_previous = $cx_template_content;
cx_require('lib', 'url.php'); // For templates
- extract($variables);
+ if ($variables != null) {
+ extract($variables);
+ }
+
ob_start();
include($path);
$output = ob_get_contents();
$cx_template_content = $cx_template_content_previous;
$name = $base_template;
+ $variables = $base_template_variables;
}
return $output;
}
-function cx_template_base($name) {
+function cx_template_base($name, $variables = null) {
global $cx_template_base;
- $cx_template_base($name);
+ $cx_template_base($name, $variables);
}
function cx_template_content() {
<title><?= cx_site_name(); ?></title>
<link rel="stylesheet" href="<?= cx_url('/design/css/style.css') ?>">
<link rel="alternate" type="application/rss+xml" title="bts.cx" href="<?= cx_url('/feed/') ?>" />
+
+ <?php if (isset($cx_post_meta)): ?>
+
+ <meta property="og:title" content="<?= cx_site_name(); ?>">
+ <meta property="og:type" content="article" />
+ <meta property="og:image" content="<?= $cx_post_meta->hero_image; ?>">
+ <meta property="og:url" content="<?= cx_url_site($cx_post_permalink); ?>">
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:image:alt" content="<?= $cx_post_meta->hero_image_alt; ?>">
+
+ <?php /*<meta property="og:description" content="Offering tour packages for individuals or groups.">
+ <meta property="og:site_name" content="<?= cx_site_name(); ?>">
+ <meta name="twitter:image:alt" content="Alt text for image">*/ ?>
+
+ <?php endif; ?>
</head>
<body>
-<?php cx_template_base('base'); ?>
-<main>
<?php $post = cx_posts_find_post($post_id); ?>
-<?php if ($post): ?>
+<?php $post_metadata = $post->get_metadata(); ?>
<?php $post_permalink = '/' . date('Y', $post->date) . '/' . date('m', $post->date) . '/' . $post->slug; ?>
+<?php cx_template_base('base', ['cx_post_meta' => $post_metadata, 'cx_post_permalink' => $post_permalink]); ?>
+<main>
+<?php if ($post): ?>
<article>
<h1><a href="<?= cx_url($post_permalink) ?>"><?= $post->title ?></a></h1>
<p class="updated"><?= date('l, F jS, Y',$post->date) ?></p>