Rebuild article system
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?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,
|
||||
];
|
||||
}
|
||||
Reference in New Issue
Block a user