gl-website-deployer/publi_bib.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2024-11-23 20:45:29 +01:00
<?php
use RenanBr\BibTexParser\Listener;
use RenanBr\BibTexParser\Parser;
use RenanBr\BibTexParser\Processor;
require dirname(__FILE__).'/common.php';
2024-11-23 21:06:10 +01:00
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;
}
2024-11-23 20:45:29 +01:00
$m = setup_mustache();
2024-11-23 21:06:10 +01:00
2024-11-23 20:45:29 +01:00
// Create and configure a Listener
$listener = new Listener();
$listener->addProcessor(new Processor\TagNameCaseProcessor(CASE_LOWER));
2024-11-23 21:06:10 +01:00
$listener->addProcessor(new NamesProcessor());
$listener->addProcessor(static function (array $entry) {
$entry['title'] = removeBoundingBraces($entry['title']);
return $entry;
});
2024-11-23 20:45:29 +01:00
// Create a Parser and attach the listener
$parser = new Parser();
$parser->addListener($listener);
// Parse the content, then read processed data from the Listener
2024-11-23 20:55:19 +01:00
try {
$parser->parseFile('assets/bib/export-bibtex.bib');
$entries = $listener->export();
2024-11-23 21:01:37 +01:00
$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'));
2024-11-23 20:55:19 +01:00
} catch (Exception $e) {
2024-11-23 21:02:01 +01:00
echo $e->getMessage() . "<br/>";
2024-11-23 20:55:19 +01:00
}
2024-11-23 20:45:29 +01:00