pages/fr/posts/ci-gitlab-latex.html
2026-04-01 11:40:19 +00:00

911 lines
No EOL
48 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr"><head>
<meta charset="utf-8">
<meta name="generator" content="quarto-1.6.39">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<meta name="author" content="Louis Lacoste">
<title>Faire une CI LaTeX avec GitLab Louis Lacoste</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
div.columns{display: flex; gap: min(4vw, 1.5em);}
div.column{flex: auto; overflow-x: auto;}
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
ul.task-list{list-style: none;}
ul.task-list li input[type="checkbox"] {
width: 0.8em;
margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */
vertical-align: middle;
}
/* CSS for syntax highlighting */
pre > code.sourceCode { white-space: pre; position: relative; }
pre > code.sourceCode > span { line-height: 1.25; }
pre > code.sourceCode > span:empty { height: 1.2em; }
.sourceCode { overflow: visible; }
code.sourceCode > span { color: inherit; text-decoration: inherit; }
div.sourceCode { margin: 1em 0; }
pre.sourceCode { margin: 0; }
@media screen {
div.sourceCode { overflow: auto; }
}
@media print {
pre > code.sourceCode { white-space: pre-wrap; }
pre > code.sourceCode > span { display: inline-block; text-indent: -5em; padding-left: 5em; }
}
pre.numberSource code
{ counter-reset: source-line 0; }
pre.numberSource code > span
{ position: relative; left: -4em; counter-increment: source-line; }
pre.numberSource code > span > a:first-child::before
{ content: counter(source-line);
position: relative; left: -1em; text-align: right; vertical-align: baseline;
border: none; display: inline-block;
-webkit-touch-callout: none; -webkit-user-select: none;
-khtml-user-select: none; -moz-user-select: none;
-ms-user-select: none; user-select: none;
padding: 0 4px; width: 4em;
}
pre.numberSource { margin-left: 3em; padding-left: 4px; }
div.sourceCode
{ }
@media screen {
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
}
</style>
<script src="../site_libs/quarto-nav/quarto-nav.js"></script>
<script src="../site_libs/quarto-nav/headroom.min.js"></script>
<script src="../site_libs/clipboard/clipboard.min.js"></script>
<script src="../site_libs/quarto-search/autocomplete.umd.js"></script>
<script src="../site_libs/quarto-search/fuse.min.js"></script>
<script src="../site_libs/quarto-search/quarto-search.js"></script>
<meta name="quarto:offset" content="../">
<script src="../site_libs/quarto-html/quarto.js"></script>
<script src="../site_libs/quarto-html/popper.min.js"></script>
<script src="../site_libs/quarto-html/tippy.umd.min.js"></script>
<script src="../site_libs/quarto-html/anchor.min.js"></script>
<link href="../site_libs/quarto-html/tippy.css" rel="stylesheet">
<link href="../site_libs/quarto-html/quarto-syntax-highlighting-e26003cea8cd680ca0c55a263523d882.css" rel="stylesheet" id="quarto-text-highlighting-styles">
<script src="../site_libs/bootstrap/bootstrap.min.js"></script>
<link href="../site_libs/bootstrap/bootstrap-icons.css" rel="stylesheet">
<link href="../site_libs/bootstrap/bootstrap-86ddb94b6c65cfb424b1f9464cc27ff8.min.css" rel="stylesheet" append-hash="true" id="quarto-bootstrap" data-mode="light">
<script id="quarto-search-options" type="application/json">{
"location": "navbar",
"copy-button": false,
"collapse-after": 3,
"panel-placement": "end",
"type": "overlay",
"limit": 50,
"keyboard-shortcut": [
"f",
"/",
"s"
],
"show-item-context": false,
"language": {
"search-no-results-text": "Pas de résultats",
"search-matching-documents-text": "documents trouvés",
"search-copy-link-title": "Copier le lien vers la recherche",
"search-hide-matches-text": "Cacher les correspondances additionnelles",
"search-more-match-text": "correspondance de plus dans ce document",
"search-more-matches-text": "correspondances de plus dans ce document",
"search-clear-button-title": "Effacer",
"search-text-placeholder": "",
"search-detached-cancel-button-title": "Annuler",
"search-submit-button-title": "Envoyer",
"search-label": "Recherche"
}
}</script>
<link rel="stylesheet" href="../styles.css">
</head>
<body class="nav-fixed">
<div id="quarto-search-results"></div>
<header id="quarto-header" class="headroom fixed-top quarto-banner">
<nav class="navbar navbar-expand-lg " data-bs-theme="dark">
<div class="navbar-container container-fluid">
<div class="navbar-brand-container mx-auto">
<a class="navbar-brand" href="../index.html">
<span class="navbar-title">Louis Lacoste</span>
</a>
</div>
<div id="quarto-search" class="" title="Recherche"></div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" role="menu" aria-expanded="false" aria-label="Basculer la navigation" onclick="if (window.quartoToggleHeadroom) { window.quartoToggleHeadroom(); }">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarCollapse">
<ul class="navbar-nav navbar-nav-scroll me-auto">
<li class="nav-item">
<a class="nav-link" href="../index.html">
<span class="menu-text">Accueil</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../posts.html">
<span class="menu-text">Billets de blog</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../teaching.html">
<span class="menu-text">Enseignement</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="../publications.html">
<span class="menu-text">Publications</span></a>
</li>
</ul>
<ul class="navbar-nav navbar-nav-scroll ms-auto">
<li class="nav-item">
<a class="nav-link" href="../interests.html">
<span class="menu-text">Ce qui mintéresse</span></a>
</li>
</ul>
</div> <!-- /navcollapse -->
<div class="quarto-navbar-tools">
</div>
</div> <!-- /container-fluid -->
</nav>
</header>
<!-- content -->
<header id="title-block-header" class="quarto-title-block default page-columns page-full">
<div class="quarto-title-banner page-columns page-full">
<div class="quarto-title column-body">
<h1 class="title">Faire une CI LaTeX avec GitLab</h1>
<div class="quarto-categories">
<div class="quarto-category">ci</div>
<div class="quarto-category">intégration continue</div>
<div class="quarto-category">git</div>
<div class="quarto-category">GitLab</div>
<div class="quarto-category">LaTeX</div>
<div class="quarto-category">french</div>
<div class="quarto-category">français</div>
</div>
</div>
</div>
<div class="quarto-title-meta-author">
<div class="quarto-title-meta-heading">Auteur·rice</div>
<div class="quarto-title-meta-heading">Affiliation</div>
<div class="quarto-title-meta-contents">
<p class="author">Louis Lacoste <a href="mailto:louis.lacoste@agroparistech.fr" class="quarto-title-author-email"><i class="bi bi-envelope"></i></a> <a href="https://orcid.org/0009-0004-0178-9821" class="quarto-title-author-orcid"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA2ZpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo1N0NEMjA4MDI1MjA2ODExOTk0QzkzNTEzRjZEQTg1NyIgeG1wTU06RG9jdW1lbnRJRD0ieG1wLmRpZDozM0NDOEJGNEZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wTU06SW5zdGFuY2VJRD0ieG1wLmlpZDozM0NDOEJGM0ZGNTcxMUUxODdBOEVCODg2RjdCQ0QwOSIgeG1wOkNyZWF0b3JUb29sPSJBZG9iZSBQaG90b3Nob3AgQ1M1IE1hY2ludG9zaCI+IDx4bXBNTTpEZXJpdmVkRnJvbSBzdFJlZjppbnN0YW5jZUlEPSJ4bXAuaWlkOkZDN0YxMTc0MDcyMDY4MTE5NUZFRDc5MUM2MUUwNEREIiBzdFJlZjpkb2N1bWVudElEPSJ4bXAuZGlkOjU3Q0QyMDgwMjUyMDY4MTE5OTRDOTM1MTNGNkRBODU3Ii8+IDwvcmRmOkRlc2NyaXB0aW9uPiA8L3JkZjpSREY+IDwveDp4bXBtZXRhPiA8P3hwYWNrZXQgZW5kPSJyIj8+84NovQAAAR1JREFUeNpiZEADy85ZJgCpeCB2QJM6AMQLo4yOL0AWZETSqACk1gOxAQN+cAGIA4EGPQBxmJA0nwdpjjQ8xqArmczw5tMHXAaALDgP1QMxAGqzAAPxQACqh4ER6uf5MBlkm0X4EGayMfMw/Pr7Bd2gRBZogMFBrv01hisv5jLsv9nLAPIOMnjy8RDDyYctyAbFM2EJbRQw+aAWw/LzVgx7b+cwCHKqMhjJFCBLOzAR6+lXX84xnHjYyqAo5IUizkRCwIENQQckGSDGY4TVgAPEaraQr2a4/24bSuoExcJCfAEJihXkWDj3ZAKy9EJGaEo8T0QSxkjSwORsCAuDQCD+QILmD1A9kECEZgxDaEZhICIzGcIyEyOl2RkgwAAhkmC+eAm0TAAAAABJRU5ErkJggg=="></a></p>
</div>
<div class="quarto-title-meta-contents">
<p class="affiliation">
MIA Paris-Saclay, INRAE, AgroParisTech, Université Paris-Saclay
</p>
</div>
</div>
<div class="quarto-title-meta">
<div>
<div class="quarto-title-meta-heading">Date de publication</div>
<div class="quarto-title-meta-contents">
<p class="date">23 septembre 2025</p>
</div>
</div>
<div>
<div class="quarto-title-meta-heading">Modifié</div>
<div class="quarto-title-meta-contents">
<p class="date-modified">1 avril 2026</p>
</div>
</div>
</div>
</header><div id="quarto-content" class="quarto-container page-columns page-rows-contents page-layout-article page-navbar">
<!-- sidebar -->
<!-- margin-sidebar -->
<div id="quarto-margin-sidebar" class="sidebar margin-sidebar">
<nav id="TOC" role="doc-toc" class="toc-active">
<h2 id="toc-title">Sur cette page</h2>
<ul>
<li><a href="#la-ci-finale" id="toc-la-ci-finale" class="nav-link active" data-scroll-target="#la-ci-finale">La CI finale</a></li>
<li><a href="#les-variables" id="toc-les-variables" class="nav-link" data-scroll-target="#les-variables">Les variables</a></li>
<li><a href="#les-étapes" id="toc-les-étapes" class="nav-link" data-scroll-target="#les-étapes">Les étapes</a>
<ul class="collapse">
<li><a href="#la-phase-de-compilation-build_tex" id="toc-la-phase-de-compilation-build_tex" class="nav-link" data-scroll-target="#la-phase-de-compilation-build_tex">La phase de compilation <code>build_tex</code></a></li>
<li><a href="#la-phase-de-déploiement-deploy" id="toc-la-phase-de-déploiement-deploy" class="nav-link" data-scroll-target="#la-phase-de-déploiement-deploy">La phase de déploiement <code>deploy</code></a></li>
</ul></li>
</ul>
</nav>
</div>
<!-- main -->
<main class="content quarto-banner-title-block" id="quarto-document-content">
<p><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"><button onclick="window.location = window.location.href.replace('/fr', '');" class="btn"><i class="fa fa-language"></i> English </button></p>
<section id="la-ci-finale" class="level1">
<h1>La CI finale</h1>
<p>Voici le contenu dun de mes fichier <code>.gitlab-ci.yaml</code></p>
<div class="callout callout-style-default callout-important callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Important
</div>
</div>
<div class="callout-body-container callout-body">
<p>Si vous voyez des incohérences, contactez-moi par mail : <a href="mailto:louis.lacoste@agroparistech.fr">louis.lacoste@agroparistech.fr</a></p>
</div>
</div>
<div class="cell">
<div class="sourceCode cell-code" id="cb1"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb1-1"><a href="#cb1-1"></a><span class="fu">variables</span><span class="kw">:</span></span>
<span id="cb1-2"><a href="#cb1-2"></a><span class="co"> # Version de git utilisée</span></span>
<span id="cb1-3"><a href="#cb1-3"></a><span class="at"> </span><span class="fu">GIT_VERSION</span><span class="kw">:</span><span class="at"> v2.30.1</span></span>
<span id="cb1-4"><a href="#cb1-4"></a></span>
<span id="cb1-5"><a href="#cb1-5"></a><span class="co"> # Branche cible pour les PDF (modifiable via CI/CD variables)</span></span>
<span id="cb1-6"><a href="#cb1-6"></a><span class="at"> </span><span class="fu">PDF_BRANCH</span><span class="kw">:</span><span class="at"> </span><span class="st">"pdf"</span></span>
<span id="cb1-7"><a href="#cb1-7"></a></span>
<span id="cb1-8"><a href="#cb1-8"></a><span class="at"> </span><span class="fu">FILE_NAMES</span><span class="kw">:</span><span class="at"> 2024-2025-rapport-csi 2024-2025-presentation-csi</span></span>
<span id="cb1-9"><a href="#cb1-9"></a></span>
<span id="cb1-10"><a href="#cb1-10"></a><span class="fu">build_tex</span><span class="kw">:</span></span>
<span id="cb1-11"><a href="#cb1-11"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> build</span></span>
<span id="cb1-12"><a href="#cb1-12"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span><span class="at"> danteev/texlive:latest</span><span class="co"> # texlive plus inkscape and others</span></span>
<span id="cb1-13"><a href="#cb1-13"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb1-14"><a href="#cb1-14"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-15"><a href="#cb1-15"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb1-16"><a href="#cb1-16"></a> do</span>
<span id="cb1-17"><a href="#cb1-17"></a> echo "Compiling ${FILE_NAME}"</span>
<span id="cb1-18"><a href="#cb1-18"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb1-19"><a href="#cb1-19"></a> if test -f ${FILE_NAME}.bcf; then</span>
<span id="cb1-20"><a href="#cb1-20"></a> echo "Found ${FILE_NAME}.bcf, running biber"</span>
<span id="cb1-21"><a href="#cb1-21"></a> biber ${FILE_NAME}</span>
<span id="cb1-22"><a href="#cb1-22"></a> fi</span>
<span id="cb1-23"><a href="#cb1-23"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb1-24"><a href="#cb1-24"></a> done</span>
<span id="cb1-25"><a href="#cb1-25"></a><span class="at"> </span><span class="fu">after_script</span><span class="kw">:</span></span>
<span id="cb1-26"><a href="#cb1-26"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-27"><a href="#cb1-27"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb1-28"><a href="#cb1-28"></a> do</span>
<span id="cb1-29"><a href="#cb1-29"></a> echo "============================================"</span>
<span id="cb1-30"><a href="#cb1-30"></a> cat ${FILE_NAME}.log</span>
<span id="cb1-31"><a href="#cb1-31"></a> echo "============================================"</span>
<span id="cb1-32"><a href="#cb1-32"></a> done</span>
<span id="cb1-33"><a href="#cb1-33"></a></span>
<span id="cb1-34"><a href="#cb1-34"></a><span class="at"> </span><span class="fu">artifacts</span><span class="kw">:</span></span>
<span id="cb1-35"><a href="#cb1-35"></a><span class="at"> </span><span class="fu">paths</span><span class="kw">:</span></span>
<span id="cb1-36"><a href="#cb1-36"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="st">"*.pdf"</span></span>
<span id="cb1-37"><a href="#cb1-37"></a><span class="fu">deploy</span><span class="kw">:</span></span>
<span id="cb1-38"><a href="#cb1-38"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> deploy</span></span>
<span id="cb1-39"><a href="#cb1-39"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span></span>
<span id="cb1-40"><a href="#cb1-40"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> alpine/git:${GIT_VERSION}</span></span>
<span id="cb1-41"><a href="#cb1-41"></a><span class="at"> </span><span class="fu">entrypoint</span><span class="kw">:</span><span class="at"> </span><span class="kw">[</span><span class="st">""</span><span class="kw">]</span></span>
<span id="cb1-42"><a href="#cb1-42"></a></span>
<span id="cb1-43"><a href="#cb1-43"></a><span class="at"> </span><span class="fu">before_script</span><span class="kw">:</span></span>
<span id="cb1-44"><a href="#cb1-44"></a><span class="co"> # Clone le repo dans un dossier temporaire</span></span>
<span id="cb1-45"><a href="#cb1-45"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git clone "https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}"</span></span>
<span id="cb1-46"><a href="#cb1-46"></a></span>
<span id="cb1-47"><a href="#cb1-47"></a><span class="co"> # Configure lidentité git</span></span>
<span id="cb1-48"><a href="#cb1-48"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"</span></span>
<span id="cb1-49"><a href="#cb1-49"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"</span></span>
<span id="cb1-50"><a href="#cb1-50"></a></span>
<span id="cb1-51"><a href="#cb1-51"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb1-52"><a href="#cb1-52"></a><span class="co"> # Déplace les PDFs compilés dans le repo cloné</span></span>
<span id="cb1-53"><a href="#cb1-53"></a><span class="at"> </span><span class="kw">-</span><span class="at"> mv *.pdf "${CI_COMMIT_SHA}/"</span></span>
<span id="cb1-54"><a href="#cb1-54"></a><span class="at"> </span><span class="kw">-</span><span class="at"> cd "${CI_COMMIT_SHA}"</span></span>
<span id="cb1-55"><a href="#cb1-55"></a></span>
<span id="cb1-56"><a href="#cb1-56"></a><span class="co"> # Crée une branche orpheline (vierge, sans historique ni fichiers)</span></span>
<span id="cb1-57"><a href="#cb1-57"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git checkout --orphan "${PDF_BRANCH}"</span></span>
<span id="cb1-58"><a href="#cb1-58"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git reset --hard</span></span>
<span id="cb1-59"><a href="#cb1-59"></a></span>
<span id="cb1-60"><a href="#cb1-60"></a><span class="co"> # Ajoute uniquement les PDF</span></span>
<span id="cb1-61"><a href="#cb1-61"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git add -f *.pdf</span></span>
<span id="cb1-62"><a href="#cb1-62"></a></span>
<span id="cb1-63"><a href="#cb1-63"></a><span class="co"> # Vérifie sil y a des changements et push</span></span>
<span id="cb1-64"><a href="#cb1-64"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb1-65"><a href="#cb1-65"></a> CHANGES=$(git status --porcelain | wc -l)</span>
<span id="cb1-66"><a href="#cb1-66"></a> if [ "$CHANGES" -gt "0" ]; then</span>
<span id="cb1-67"><a href="#cb1-67"></a> git commit -m "${COMMIT_MESSAGE:-Updating PDF files}"</span>
<span id="cb1-68"><a href="#cb1-68"></a> git push --force origin "${PDF_BRANCH}" -o ci.skip</span>
<span id="cb1-69"><a href="#cb1-69"></a> else</span>
<span id="cb1-70"><a href="#cb1-70"></a> echo "No PDF changes to commit"</span>
<span id="cb1-71"><a href="#cb1-71"></a> fi</span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Détaillons ce quil sy passe !</p>
</section>
<section id="les-variables" class="level1">
<h1>Les variables</h1>
<p>La section variables ci-dessous sert à définir des variables auxquelles nous ferons référence plus tard.</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb2"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb2-1"><a href="#cb2-1"></a><span class="fu">variables</span><span class="kw">:</span></span>
<span id="cb2-2"><a href="#cb2-2"></a><span class="co"> # Version de git utilisée</span></span>
<span id="cb2-3"><a href="#cb2-3"></a><span class="at"> </span><span class="fu">GIT_VERSION</span><span class="kw">:</span><span class="at"> v2.30.1</span></span>
<span id="cb2-4"><a href="#cb2-4"></a></span>
<span id="cb2-5"><a href="#cb2-5"></a><span class="co"> # Branche cible pour les PDF (modifiable via CI/CD variables)</span></span>
<span id="cb2-6"><a href="#cb2-6"></a><span class="at"> </span><span class="fu">PDF_BRANCH</span><span class="kw">:</span><span class="at"> </span><span class="st">"pdf"</span></span>
<span id="cb2-7"><a href="#cb2-7"></a></span>
<span id="cb2-8"><a href="#cb2-8"></a><span class="at"> </span><span class="fu">FILE_NAMES</span><span class="kw">:</span><span class="at"> 2024-2025-rapport-csi 2024-2025-presentation-csi</span></span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<ul>
<li><code>GIT_VERSION</code> : spécifie la version de git à utiliser pour limage Docker que lon va récupérer.</li>
<li><code>PDF_BRANCH</code> : indique le nom de la branche sur laquelle nos PDF seront publiés.</li>
<li><code>FILE_NAMES</code> : déclare la liste des noms de fichiers (sans les extensions). Au format yaml donc des chaînes de caractères sans guillemets séparés par des espaces</li>
</ul>
</section>
<section id="les-étapes" class="level1">
<h1>Les étapes</h1>
<section id="la-phase-de-compilation-build_tex" class="level2">
<h2 class="anchored" data-anchor-id="la-phase-de-compilation-build_tex">La phase de compilation <code>build_tex</code></h2>
<p>Nous allons détailler létape <code>build_tex</code> :</p>
<div class="cell">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb3-1"><a href="#cb3-1"></a><span class="fu">build_tex</span><span class="kw">:</span></span>
<span id="cb3-2"><a href="#cb3-2"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> build</span></span>
<span id="cb3-3"><a href="#cb3-3"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span><span class="at"> danteev/texlive:latest</span><span class="co"> # texlive plus inkscape and others</span></span>
<span id="cb3-4"><a href="#cb3-4"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb3-5"><a href="#cb3-5"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb3-6"><a href="#cb3-6"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb3-7"><a href="#cb3-7"></a> do</span>
<span id="cb3-8"><a href="#cb3-8"></a> echo "Compiling ${FILE_NAME}"</span>
<span id="cb3-9"><a href="#cb3-9"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb3-10"><a href="#cb3-10"></a> if test -f ${FILE_NAME}.bcf; then</span>
<span id="cb3-11"><a href="#cb3-11"></a> echo "Found ${FILE_NAME}.bcf, running biber"</span>
<span id="cb3-12"><a href="#cb3-12"></a> biber ${FILE_NAME}</span>
<span id="cb3-13"><a href="#cb3-13"></a> fi</span>
<span id="cb3-14"><a href="#cb3-14"></a> pdflatex --shell-escape ${FILE_NAME}.tex</span>
<span id="cb3-15"><a href="#cb3-15"></a> done</span>
<span id="cb3-16"><a href="#cb3-16"></a><span class="at"> </span><span class="fu">after_script</span><span class="kw">:</span></span>
<span id="cb3-17"><a href="#cb3-17"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb3-18"><a href="#cb3-18"></a> for FILE_NAME in $FILE_NAMES</span>
<span id="cb3-19"><a href="#cb3-19"></a> do</span>
<span id="cb3-20"><a href="#cb3-20"></a> echo "============================================"</span>
<span id="cb3-21"><a href="#cb3-21"></a> cat ${FILE_NAME}.log</span>
<span id="cb3-22"><a href="#cb3-22"></a> echo "============================================"</span>
<span id="cb3-23"><a href="#cb3-23"></a> done</span>
<span id="cb3-24"><a href="#cb3-24"></a></span>
<span id="cb3-25"><a href="#cb3-25"></a><span class="at"> </span><span class="fu">artifacts</span><span class="kw">:</span></span>
<span id="cb3-26"><a href="#cb3-26"></a><span class="at"> </span><span class="fu">paths</span><span class="kw">:</span></span>
<span id="cb3-27"><a href="#cb3-27"></a><span class="at"> </span><span class="kw">-</span><span class="at"> </span><span class="st">"*.pdf"</span></span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>On déclare tout dabord le <code>stage: build</code> pour qualifier létape que lon réalise ici. Il y en a 3 possibles : <code>build, test, deploy</code> (<a href="https://docs.gitlab.com/ci/yaml/#stage">documentation GitLab</a>). Ici nous choisissons <code>build</code> puisquil sagit de la compilation de notre projet.</p>
<p>À la suite nous chargeons une image docker qui contient les outils <code>texlive</code>.</p>
<p>Et enfin la directive <code>script</code> définit en <code>bash</code> lenchaînement détapes que nous réalisons pour compiler le projet.</p>
<div class="callout callout-style-default callout-note callout-titled" title="Exécution conditionnelle de `biber`">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Exécution conditionnelle de <code>biber</code>
</div>
</div>
<div class="callout-body-container callout-body">
<p>Noter que nous navons pas mis dextensions dans <code>FILE_NAMES</code> afin de pouvoir détecter ici les fichiers bcf caractéristiques de la bibliographie.</p>
</div>
</div>
<p>Finalement, nous utilisons la directive <code>after_script</code> pour afficher dans les journaux de la CI les fichiers de logs des compilations.</p>
<p>Enfin <code>artifacts</code> spécifie que les artéfacts que lon veut conserver de la CI sont tous les PDF à la racine du dépôt</p>
</section>
<section id="la-phase-de-déploiement-deploy" class="level2">
<h2 class="anchored" data-anchor-id="la-phase-de-déploiement-deploy">La phase de déploiement <code>deploy</code></h2>
<div class="cell">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode numberSource yaml number-lines code-with-copy"><code class="sourceCode yaml"><span id="cb4-1"><a href="#cb4-1"></a><span class="fu">deploy</span><span class="kw">:</span></span>
<span id="cb4-2"><a href="#cb4-2"></a><span class="at"> </span><span class="fu">stage</span><span class="kw">:</span><span class="at"> deploy</span></span>
<span id="cb4-3"><a href="#cb4-3"></a><span class="at"> </span><span class="fu">image</span><span class="kw">:</span></span>
<span id="cb4-4"><a href="#cb4-4"></a><span class="at"> </span><span class="fu">name</span><span class="kw">:</span><span class="at"> alpine/git:${GIT_VERSION}</span></span>
<span id="cb4-5"><a href="#cb4-5"></a><span class="at"> </span><span class="fu">entrypoint</span><span class="kw">:</span><span class="at"> </span><span class="kw">[</span><span class="st">""</span><span class="kw">]</span></span>
<span id="cb4-6"><a href="#cb4-6"></a></span>
<span id="cb4-7"><a href="#cb4-7"></a><span class="at"> </span><span class="fu">before_script</span><span class="kw">:</span></span>
<span id="cb4-8"><a href="#cb4-8"></a><span class="co"> # Clone le repo dans un dossier temporaire</span></span>
<span id="cb4-9"><a href="#cb4-9"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git clone "https://${GITLAB_USERNAME}:${GITLAB_TOKEN}@${CI_SERVER_HOST}/${CI_PROJECT_PATH}.git" "${CI_COMMIT_SHA}"</span></span>
<span id="cb4-10"><a href="#cb4-10"></a></span>
<span id="cb4-11"><a href="#cb4-11"></a><span class="co"> # Configure lidentité git</span></span>
<span id="cb4-12"><a href="#cb4-12"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.email "${GIT_USER_EMAIL:-$GITLAB_USER_EMAIL}"</span></span>
<span id="cb4-13"><a href="#cb4-13"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git config --global user.name "${GIT_USER_NAME:-$GITLAB_USER_NAME}"</span></span>
<span id="cb4-14"><a href="#cb4-14"></a></span>
<span id="cb4-15"><a href="#cb4-15"></a><span class="at"> </span><span class="fu">script</span><span class="kw">:</span></span>
<span id="cb4-16"><a href="#cb4-16"></a><span class="co"> # Déplace les PDFs compilés dans le repo cloné</span></span>
<span id="cb4-17"><a href="#cb4-17"></a><span class="at"> </span><span class="kw">-</span><span class="at"> mv *.pdf "${CI_COMMIT_SHA}/"</span></span>
<span id="cb4-18"><a href="#cb4-18"></a><span class="at"> </span><span class="kw">-</span><span class="at"> cd "${CI_COMMIT_SHA}"</span></span>
<span id="cb4-19"><a href="#cb4-19"></a></span>
<span id="cb4-20"><a href="#cb4-20"></a><span class="co"> # Crée une branche orpheline (vierge, sans historique ni fichiers)</span></span>
<span id="cb4-21"><a href="#cb4-21"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git checkout --orphan "${PDF_BRANCH}"</span></span>
<span id="cb4-22"><a href="#cb4-22"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git reset --hard</span></span>
<span id="cb4-23"><a href="#cb4-23"></a></span>
<span id="cb4-24"><a href="#cb4-24"></a><span class="co"> # Ajoute uniquement les PDF</span></span>
<span id="cb4-25"><a href="#cb4-25"></a><span class="at"> </span><span class="kw">-</span><span class="at"> git add -f *.pdf</span></span>
<span id="cb4-26"><a href="#cb4-26"></a></span>
<span id="cb4-27"><a href="#cb4-27"></a><span class="co"> # Vérifie sil y a des changements et push</span></span>
<span id="cb4-28"><a href="#cb4-28"></a><span class="kw"> - </span><span class="ch">|</span></span>
<span id="cb4-29"><a href="#cb4-29"></a> CHANGES=$(git status --porcelain | wc -l)</span>
<span id="cb4-30"><a href="#cb4-30"></a> if [ "$CHANGES" -gt "0" ]; then</span>
<span id="cb4-31"><a href="#cb4-31"></a> git commit -m "${COMMIT_MESSAGE:-Updating PDF files}"</span>
<span id="cb4-32"><a href="#cb4-32"></a> git push --force origin "${PDF_BRANCH}" -o ci.skip</span>
<span id="cb4-33"><a href="#cb4-33"></a> else</span>
<span id="cb4-34"><a href="#cb4-34"></a> echo "No PDF changes to commit"</span>
<span id="cb4-35"><a href="#cb4-35"></a> fi</span></code><button title="Copier vers le presse-papier" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Finalement nous déployons nos PDF. Pour cela on charge une image légère <code>Alpine Linux</code> avec la version Git sélectionnée dans les variables.</p>
<p>Avec la directive <code>before_script</code> on clone le dépôt.</p>
<div class="callout callout-style-default callout-important callout-titled" title="Pour créer le token GitLab">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
<i class="callout-icon"></i>
</div>
<div class="callout-title-container flex-fill">
Pour créer le token GitLab
</div>
</div>
<div class="callout-body-container callout-body">
<p>Notez dans le <code>git clone</code> que nous employons une variable <code>GITLAB_TOKEN</code>, celle-ci est a créer au préalable et à déclarer dans le dépôt.</p>
<p>Pour cela :</p>
<ol type="1">
<li>Rendez-vous dans les paramètre de votre dépôt.</li>
</ol>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="resources/ci-gitlab-latex/access-token-settings.png" class="img-fluid figure-img"></p>
<figcaption>Dans les menus de gauche, déplier “Settings” et rendez-vous dans “Access tokens”</figcaption>
</figure>
</div>
<ol start="2" type="1">
<li>Ici ajoutez un nouveau token.</li>
</ol>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="resources/ci-gitlab-latex/add-new-token.png" class="img-fluid figure-img"></p>
<figcaption>Cliquer sur “Add new token”</figcaption>
</figure>
</div>
<ol start="3" type="1">
<li>En configurant les permissions <code>read_repository</code> et <code>write_repository</code> afin de pouvoir cloner et pousser nos fichiers. Puis cliquer sur “Create project access token”.</li>
</ol>
<p><img src="resources/ci-gitlab-latex/scope.png" class="img-fluid"></p>
<ol start="4" type="1">
<li><p>Votre token est maintenant affiché, copiez le car il ne sera pas raffiché après.</p></li>
<li><p>Rendez-vous maintenant dans CI/CD settings.</p></li>
</ol>
<p><img src="resources/ci-gitlab-latex/ci-settings.png" class="img-fluid"></p>
<ol start="6" type="1">
<li>Créer maintenant la variable en cliquant sur “Add variable”, nommez la <code>GITLAB_TOKEN</code>, dans “value” ajoutez le token copié.</li>
</ol>
</div>
</div>
<p>La suite du script déplace les PDF dans le dépôt cloné, crée la branche de publication et ajoute les pdf.</p>
<p>Vous avez normalement maintenant une CI de compilation et publication de PDF ! Maintenant vous pouvez faire référence dans votre <code>README.md</code> à vos PDF en saisissant un lien du type :</p>
<p><code>https://mongitlab.com/monnomutilisateur/mondepot/-/raw/monpdf.pdf</code></p>
<p>qui permet dafficher directement dans le navigateur le produit de la compilation. 😄</p>
</section>
</section>
</main> <!-- /main -->
<script id="quarto-html-after-body" type="application/javascript">
window.document.addEventListener("DOMContentLoaded", function (event) {
const toggleBodyColorMode = (bsSheetEl) => {
const mode = bsSheetEl.getAttribute("data-mode");
const bodyEl = window.document.querySelector("body");
if (mode === "dark") {
bodyEl.classList.add("quarto-dark");
bodyEl.classList.remove("quarto-light");
} else {
bodyEl.classList.add("quarto-light");
bodyEl.classList.remove("quarto-dark");
}
}
const toggleBodyColorPrimary = () => {
const bsSheetEl = window.document.querySelector("link#quarto-bootstrap");
if (bsSheetEl) {
toggleBodyColorMode(bsSheetEl);
}
}
toggleBodyColorPrimary();
const icon = "";
const anchorJS = new window.AnchorJS();
anchorJS.options = {
placement: 'right',
icon: icon
};
anchorJS.add('.anchored');
const isCodeAnnotation = (el) => {
for (const clz of el.classList) {
if (clz.startsWith('code-annotation-')) {
return true;
}
}
return false;
}
const onCopySuccess = function(e) {
// button target
const button = e.trigger;
// don't keep focus
button.blur();
// flash "checked"
button.classList.add('code-copy-button-checked');
var currentTitle = button.getAttribute("title");
button.setAttribute("title", "Copié");
let tooltip;
if (window.bootstrap) {
button.setAttribute("data-bs-toggle", "tooltip");
button.setAttribute("data-bs-placement", "left");
button.setAttribute("data-bs-title", "Copié");
tooltip = new bootstrap.Tooltip(button,
{ trigger: "manual",
customClass: "code-copy-button-tooltip",
offset: [0, -8]});
tooltip.show();
}
setTimeout(function() {
if (tooltip) {
tooltip.hide();
button.removeAttribute("data-bs-title");
button.removeAttribute("data-bs-toggle");
button.removeAttribute("data-bs-placement");
}
button.setAttribute("title", currentTitle);
button.classList.remove('code-copy-button-checked');
}, 1000);
// clear code selection
e.clearSelection();
}
const getTextToCopy = function(trigger) {
const codeEl = trigger.previousElementSibling.cloneNode(true);
for (const childEl of codeEl.children) {
if (isCodeAnnotation(childEl)) {
childEl.remove();
}
}
return codeEl.innerText;
}
const clipboard = new window.ClipboardJS('.code-copy-button:not([data-in-quarto-modal])', {
text: getTextToCopy
});
clipboard.on('success', onCopySuccess);
if (window.document.getElementById('quarto-embedded-source-code-modal')) {
const clipboardModal = new window.ClipboardJS('.code-copy-button[data-in-quarto-modal]', {
text: getTextToCopy,
container: window.document.getElementById('quarto-embedded-source-code-modal')
});
clipboardModal.on('success', onCopySuccess);
}
var localhostRegex = new RegExp(/^(?:http|https):\/\/localhost\:?[0-9]*\//);
var mailtoRegex = new RegExp(/^mailto:/);
var filterRegex = new RegExp('/' + window.location.host + '/');
var isInternal = (href) => {
return filterRegex.test(href) || localhostRegex.test(href) || mailtoRegex.test(href);
}
// Inspect non-navigation links and adorn them if external
var links = window.document.querySelectorAll('a[href]:not(.nav-link):not(.navbar-brand):not(.toc-action):not(.sidebar-link):not(.sidebar-item-toggle):not(.pagination-link):not(.no-external):not([aria-hidden]):not(.dropdown-item):not(.quarto-navigation-tool):not(.about-link)');
for (var i=0; i<links.length; i++) {
const link = links[i];
if (!isInternal(link.href)) {
// undo the damage that might have been done by quarto-nav.js in the case of
// links that we want to consider external
if (link.dataset.originalHref !== undefined) {
link.href = link.dataset.originalHref;
}
}
}
function tippyHover(el, contentFn, onTriggerFn, onUntriggerFn) {
const config = {
allowHTML: true,
maxWidth: 500,
delay: 100,
arrow: false,
appendTo: function(el) {
return el.parentElement;
},
interactive: true,
interactiveBorder: 10,
theme: 'quarto',
placement: 'bottom-start',
};
if (contentFn) {
config.content = contentFn;
}
if (onTriggerFn) {
config.onTrigger = onTriggerFn;
}
if (onUntriggerFn) {
config.onUntrigger = onUntriggerFn;
}
window.tippy(el, config);
}
const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]');
for (var i=0; i<noterefs.length; i++) {
const ref = noterefs[i];
tippyHover(ref, function() {
// use id or data attribute instead here
let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href');
try { href = new URL(href).hash; } catch {}
const id = href.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note) {
return note.innerHTML;
} else {
return "";
}
});
}
const xrefs = window.document.querySelectorAll('a.quarto-xref');
const processXRef = (id, note) => {
// Strip column container classes
const stripColumnClz = (el) => {
el.classList.remove("page-full", "page-columns");
if (el.children) {
for (const child of el.children) {
stripColumnClz(child);
}
}
}
stripColumnClz(note)
if (id === null || id.startsWith('sec-')) {
// Special case sections, only their first couple elements
const container = document.createElement("div");
if (note.children && note.children.length > 2) {
container.appendChild(note.children[0].cloneNode(true));
for (let i = 1; i < note.children.length; i++) {
const child = note.children[i];
if (child.tagName === "P" && child.innerText === "") {
continue;
} else {
container.appendChild(child.cloneNode(true));
break;
}
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(container);
}
return container.innerHTML
} else {
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
return note.innerHTML;
}
} else {
// Remove any anchor links if they are present
const anchorLink = note.querySelector('a.anchorjs-link');
if (anchorLink) {
anchorLink.remove();
}
if (window.Quarto?.typesetMath) {
window.Quarto.typesetMath(note);
}
if (note.classList.contains("callout")) {
return note.outerHTML;
} else {
return note.innerHTML;
}
}
}
for (var i=0; i<xrefs.length; i++) {
const xref = xrefs[i];
tippyHover(xref, undefined, function(instance) {
instance.disable();
let url = xref.getAttribute('href');
let hash = undefined;
if (url.startsWith('#')) {
hash = url;
} else {
try { hash = new URL(url).hash; } catch {}
}
if (hash) {
const id = hash.replace(/^#\/?/, "");
const note = window.document.getElementById(id);
if (note !== null) {
try {
const html = processXRef(id, note.cloneNode(true));
instance.setContent(html);
} finally {
instance.enable();
instance.show();
}
} else {
// See if we can fetch this
fetch(url.split('#')[0])
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.getElementById(id);
if (note !== null) {
const html = processXRef(id, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
} else {
// See if we can fetch a full url (with no hash to target)
// This is a special case and we should probably do some content thinning / targeting
fetch(url)
.then(res => res.text())
.then(html => {
const parser = new DOMParser();
const htmlDoc = parser.parseFromString(html, "text/html");
const note = htmlDoc.querySelector('main.content');
if (note !== null) {
// This should only happen for chapter cross references
// (since there is no id in the URL)
// remove the first header
if (note.children.length > 0 && note.children[0].tagName === "HEADER") {
note.children[0].remove();
}
const html = processXRef(null, note);
instance.setContent(html);
}
}).finally(() => {
instance.enable();
instance.show();
});
}
}, function(instance) {
});
}
let selectedAnnoteEl;
const selectorForAnnotation = ( cell, annotation) => {
let cellAttr = 'data-code-cell="' + cell + '"';
let lineAttr = 'data-code-annotation="' + annotation + '"';
const selector = 'span[' + cellAttr + '][' + lineAttr + ']';
return selector;
}
const selectCodeLines = (annoteEl) => {
const doc = window.document;
const targetCell = annoteEl.getAttribute("data-target-cell");
const targetAnnotation = annoteEl.getAttribute("data-target-annotation");
const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation));
const lines = annoteSpan.getAttribute("data-code-lines").split(",");
const lineIds = lines.map((line) => {
return targetCell + "-" + line;
})
let top = null;
let height = null;
let parent = null;
if (lineIds.length > 0) {
//compute the position of the single el (top and bottom and make a div)
const el = window.document.getElementById(lineIds[0]);
top = el.offsetTop;
height = el.offsetHeight;
parent = el.parentElement.parentElement;
if (lineIds.length > 1) {
const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]);
const bottom = lastEl.offsetTop + lastEl.offsetHeight;
height = bottom - top;
}
if (top !== null && height !== null && parent !== null) {
// cook up a div (if necessary) and position it
let div = window.document.getElementById("code-annotation-line-highlight");
if (div === null) {
div = window.document.createElement("div");
div.setAttribute("id", "code-annotation-line-highlight");
div.style.position = 'absolute';
parent.appendChild(div);
}
div.style.top = top - 2 + "px";
div.style.height = height + 4 + "px";
div.style.left = 0;
let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter");
if (gutterDiv === null) {
gutterDiv = window.document.createElement("div");
gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter");
gutterDiv.style.position = 'absolute';
const codeCell = window.document.getElementById(targetCell);
const gutter = codeCell.querySelector('.code-annotation-gutter');
gutter.appendChild(gutterDiv);
}
gutterDiv.style.top = top - 2 + "px";
gutterDiv.style.height = height + 4 + "px";
}
selectedAnnoteEl = annoteEl;
}
};
const unselectCodeLines = () => {
const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"];
elementsIds.forEach((elId) => {
const div = window.document.getElementById(elId);
if (div) {
div.remove();
}
});
selectedAnnoteEl = undefined;
};
// Handle positioning of the toggle
window.addEventListener(
"resize",
throttle(() => {
elRect = undefined;
if (selectedAnnoteEl) {
selectCodeLines(selectedAnnoteEl);
}
}, 10)
);
function throttle(fn, ms) {
let throttle = false;
let timer;
return (...args) => {
if(!throttle) { // first call gets through
fn.apply(this, args);
throttle = true;
} else { // all the others get throttled
if(timer) clearTimeout(timer); // cancel #2
timer = setTimeout(() => {
fn.apply(this, args);
timer = throttle = false;
}, ms);
}
};
}
// Attach click handler to the DT
const annoteDls = window.document.querySelectorAll('dt[data-target-cell]');
for (const annoteDlNode of annoteDls) {
annoteDlNode.addEventListener('click', (event) => {
const clickedEl = event.target;
if (clickedEl !== selectedAnnoteEl) {
unselectCodeLines();
const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active');
if (activeEl) {
activeEl.classList.remove('code-annotation-active');
}
selectCodeLines(clickedEl);
clickedEl.classList.add('code-annotation-active');
} else {
// Unselect the line
unselectCodeLines();
clickedEl.classList.remove('code-annotation-active');
}
});
}
const findCites = (el) => {
const parentEl = el.parentElement;
if (parentEl) {
const cites = parentEl.dataset.cites;
if (cites) {
return {
el,
cites: cites.split(' ')
};
} else {
return findCites(el.parentElement)
}
} else {
return undefined;
}
};
var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]');
for (var i=0; i<bibliorefs.length; i++) {
const ref = bibliorefs[i];
const citeInfo = findCites(ref);
if (citeInfo) {
tippyHover(citeInfo.el, function() {
var popup = window.document.createElement('div');
citeInfo.cites.forEach(function(cite) {
var citeDiv = window.document.createElement('div');
citeDiv.classList.add('hanging-indent');
citeDiv.classList.add('csl-entry');
var biblioDiv = window.document.getElementById('ref-' + cite);
if (biblioDiv) {
citeDiv.innerHTML = biblioDiv.innerHTML;
}
popup.appendChild(citeDiv);
});
return popup.innerHTML;
});
}
}
});
</script>
</div> <!-- /content -->
</body></html>