gl-website-deployer/publi_bib.php
2024-11-23 21:06:10 +01:00

81 lines
1.9 KiB
PHP

<?php
use RenanBr\BibTexParser\Listener;
use RenanBr\BibTexParser\Parser;
use RenanBr\BibTexParser\Processor;
require dirname(__FILE__).'/common.php';
function removeBoundingBraces($str) {
// Trim whitespace first
$str = trim($str);
// Check if string starts with { and ends with }
if (strlen($str) >= 2) {
// Remove opening brace if it exists
if ($str[0] === '{') {
$str = substr($str, 1);
}
// After removing first brace, get new length
$length = strlen($str);
// Remove closing brace if it exists
if ($length > 0 && $str[$length - 1] === '}') {
$str = substr($str, 0, -1);
}
}
return $str;
}
$m = setup_mustache();
// Create and configure a Listener
$listener = new Listener();
$listener->addProcessor(new Processor\TagNameCaseProcessor(CASE_LOWER));
$listener->addProcessor(new NamesProcessor());
$listener->addProcessor(static function (array $entry) {
$entry['title'] = removeBoundingBraces($entry['title']);
return $entry;
});
// Create a Parser and attach the listener
$parser = new Parser();
$parser->addListener($listener);
// Parse the content, then read processed data from the Listener
try {
$parser->parseFile('assets/bib/export-bibtex.bib');
$entries = $listener->export();
$tpl = $m->loadTemplate("publi_bib_html");
echo $tpl->render(
array(
'ROOT_URL' => $iap_root,
'title'=>'Guilhem Lavaux\'s publications',
'publi'=>$entries,
'configure_script'=>[
'MathJax = {
tex: {
inlineMath: [[\'$\', \'$\'], [\'\\\\(\', \'\\\\)\']]
}
};
'
],
'external_scripts'=>[
'src="https://polyfill.io/v3/polyfill.min.js?features=es6"',
'id="MathJax-script" async src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"'
],
'bar' => 'baz'));
} catch (Exception $e) {
echo $e->getMessage() . "<br/>";
}