* @global
* @param mixed $data
* @param string $name Default: ''
* @return void
*/
function n_print($data, $name = '')
{
$aBackTrace = debug_backtrace();
echo '
', $name, '
';
echo '
';
}
/**
* Return list dir of content
*
* @author Knah Tsaeb
* @global
* @return array
*/
function listDir()
{
$dirList = array();
foreach (glob("content/*", GLOB_ONLYDIR) as $dir) {
$dirList[basename($dir)] = listFile($dir);
}
if (empty($dirList)) {
$dirList = array();
}
return $dirList;
}
/**
* Return list file in dir
*
* @author Knah Tsaeb
* @global
* @param mixed $dir
* @return mixed
*/
function listFile($dir)
{
$fileList = array();
foreach (glob($dir . "/*.md") as $dir) {
$fileList[] = str_replace('.md', '', basename($dir));
}
if (empty($fileList)) {
$fileList = array();
}
return $fileList;
}
/**
* Gen navigation menu
*
* @author Knah Tsaeb
* @global
* @param string $getDir Default: null
* @return string
*/
function makeMenu($getDir = null)
{
$dirList = listDir();
$menu = '';
foreach ($dirList as $dir => $files) {
if ($getDir === $dir) {
$expand = 'open';
} else {
$expand = 'close';
}
$menu .= '
' . $dir . '
';
foreach ($files as $value) {
$menu .= '- ' . $value . '
';
}
$menu .= '
';
}
return $menu;
}
/**
* Add lazy loading attribute for img
*
* @author Knah Tsaeb
* @see ParsedownToc
* @global
*/
class ExtendParsedownToc extends ParsedownToc
{
public function inlineImage($Excerpt)
{
if (!isset($Excerpt['text'][1]) or $Excerpt['text'][1] !== '[') {
return;
}
$Excerpt['text'] = substr($Excerpt['text'], 1);
$Link = $this->inlineLink($Excerpt);
if ($Link === null) {
return;
}
$Inline = array(
'extent' => $Link['extent'] + 1,
'element' => array(
'name' => 'img',
'attributes' => array(
'src' => $Link['element']['attributes']['href'],
'alt' => $Link['element']['text'],
'loading' => 'lazy',
),
),
);
$Inline['element']['attributes'] += $Link['element']['attributes'];
unset($Inline['element']['attributes']['href']);
return $Inline;
}
}