Add browser lazy loading
This commit is contained in:
parent
e47a6e4795
commit
d3974b59cb
2 changed files with 40 additions and 5 deletions
|
@ -62,3 +62,39 @@ function makeMenu($getDir = null)
|
||||||
}
|
}
|
||||||
return $menu;
|
return $menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -23,14 +23,13 @@ if (empty($file) || !file_exists('content/' . urldecode($dir) . '/' . urldecode(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$Parsedown = new ParsedownToc();
|
|
||||||
|
|
||||||
$content = file_get_contents('content/' . urldecode($dir) . '/' . urldecode($file) . '.md');
|
$content = file_get_contents('content/' . urldecode($dir) . '/' . urldecode($file) . '.md');
|
||||||
$options = array('selectors' => array('h2', 'h3'));
|
$options = array('selectors' => array('h2', 'h3'));
|
||||||
|
|
||||||
$Parsedown = new ParsedownToc($options);
|
$Parsedown = new ExtendParsedownToc($options);
|
||||||
$body = $Parsedown->text($content);
|
|
||||||
$toc = $Parsedown->contentsList();
|
$body = $Parsedown->text($content);
|
||||||
|
$toc = $Parsedown->contentsList();
|
||||||
|
|
||||||
$body = str_replace("[ ]", '<input type="checkbox" disabled>', $body);
|
$body = str_replace("[ ]", '<input type="checkbox" disabled>', $body);
|
||||||
$body = str_replace("[x]", '<input type="checkbox" checked disabled>', $body);
|
$body = str_replace("[x]", '<input type="checkbox" checked disabled>', $body);
|
||||||
|
|
Loading…
Reference in a new issue