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.
31 lines
889 B
31 lines
889 B
|
8 months ago
|
<?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,
|
||
|
|
];
|
||
|
|
}
|