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/render_php.php

30 lines
889 B

<?php
use Symfony\Component\Yaml\Yaml;
function render_php($file) {
ob_start();
#include __DIR__ . '/' . $file;
include $file;
$html = ob_get_clean();
$meta = [];
# Split off head matter
#
# this pattern uses the 'ms' modifier to treat multiline strings as a
# single string, and let '\s', '.' etc treat newlines as whitespace
# I match an _optional_ HTML ( '<!-- nnnn -->') comment if we want to wrap
# the headmatter in a comment.
#
# The headmatter is delimited by either '----' or '++++' as per
# Markdown/yaml standards.
# Technical note that '+' is a regex character so \+{3,} instead of ++++
if (preg_match('/^(<!--\s*)?(-{3,}|\+{3,})\s*(.*?)(-{3,}|\+{3,})\s*(-->)?\s*(.*)/ms',$html, $parts) === 1) {
$html = $parts[6];
$meta = array_merge($meta,Yaml::parse($parts[3]));
}
return [
'html' => $html,
'meta' => $meta,
];
}