her.esy.fun/src/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/index.html
Yann Esposito (Yogsototh) 059fabd7d0
many minor details to update
2022-10-26 11:38:50 +02:00

108 lines
7.2 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 lang="fr">
<head>
<meta charset="utf-8">
<title>YBlog - Utilisation de git pour calculer les mtimes</title>
<meta name="keywords" content="nanoc, web, git" />
<link rel="shortcut icon" type="image/x-icon" href="../../../../Scratch/img/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../../../../css/y.css" />
<link rel="stylesheet" type="text/css" href="/css/legacy.css" />
<link rel="alternate" type="application/rss+xml" title="RSS" href="/rss.xml" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="apple-touch-icon" href="../../../../Scratch/img/about/FlatAvatar@2x.png" />
<!--[if lt IE 9]>
<script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE9.js"></script>
<![endif]-->
<!-- IndieAuth -->
<link href="https://twitter.com/yogsototh" rel="me">
<link href="https://github.com/yogsototh" rel="me">
<link href="mailto:yann.esposito@gmail.com" rel="me">
<link rel="pgpkey" href="../../../../pubkey.txt">
</head>
<body lang="fr" class="article">
<div id="content">
<div id="header">
<div id="choix">
<span id="choixlang">
<a href="../../../../Scratch/en/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/">Anglais</a>
</span>
<span class="tomenu"><a href="#navigation">↓ Menu ↓</a></span>
<span class="flush"></span>
</div>
</div>
<div id="titre">
<h1>Utilisation de git pour calculer les mtimes</h1>
</div>
<div class="flush"></div>
<div id="afterheader" class="article">
<div class="corps">
<p>Vous pouvez remarquer quà la fin de chaque page je donne une date de dernière modification. Précédemment cette date était calculée en utilisant la date du fichier. Mais il arrive fréquemment que je fasse un <code>touch</code> dun fichier pour engendrer tout le site de nouveau. Donc la date nest pas nécessairement la <em>vraie</em> de modification du contenue.</p>
<p>Jutilise <a href="http://git-scm.org">git</a> pour <em>versionner</em> mon site web. Et cet outil me permet de récupérer la dernière date de <em>vraie</em> modification dun fichier. Voici comment je my prend avec <a href="http://nanoc.stoneship.org">nanoc</a>&nbsp;:</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode ruby"><code class="sourceCode ruby"><a class="sourceLine" id="cb1-1" title="1"><span class="kw">def</span> gitmtime</a>
<a class="sourceLine" id="cb1-2" title="2"> filepath=<span class="ot">@item</span>.path.sub(<span class="st">'/Scratch/'</span>,<span class="st">'content/html/'</span>).sub(<span class="ot">/\/$/</span>,<span class="st">''</span>)</a>
<a class="sourceLine" id="cb1-3" title="3"> ext=<span class="ot">%{</span><span class="st">.</span><span class="ot">#{@item</span>[<span class="st">:extension</span>]<span class="ot">}}</span></a>
<a class="sourceLine" id="cb1-4" title="4"> filepath&lt;&lt;=ext</a>
<a class="sourceLine" id="cb1-5" title="5"> <span class="kw">if</span> <span class="kw">not</span> <span class="dt">FileTest</span>.exists?(filepath)</a>
<a class="sourceLine" id="cb1-6" title="6"> filepath.sub!(ext,<span class="ot">%{#{@item</span>.raw_filename<span class="ot">}#{</span>ext<span class="ot">}}</span>)</a>
<a class="sourceLine" id="cb1-7" title="7"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb1-8" title="8"> str=<span class="st">`git log -1 --format='%ci' -- </span><span class="ot">#{</span>filepath<span class="ot">}</span><span class="st">`</span></a>
<a class="sourceLine" id="cb1-9" title="9"> <span class="kw">if</span> str.nil? <span class="kw">or</span> str.empty?</a>
<a class="sourceLine" id="cb1-10" title="10"> <span class="kw">return</span> <span class="dt">Time</span>.now</a>
<a class="sourceLine" id="cb1-11" title="11"> <span class="kw">else</span></a>
<a class="sourceLine" id="cb1-12" title="12"> <span class="kw">return</span> <span class="dt">DateTime</span>.parse( str )</a>
<a class="sourceLine" id="cb1-13" title="13"> <span class="kw">end</span></a>
<a class="sourceLine" id="cb1-14" title="14"><span class="kw">end</span></a></code></pre></div>
<p>Bien entendu je sais que cest très lent et absolument pas optimisé. Mais ça fonctionne comme prévu. Maintenant la date que vous voyez en bas de la page correspond exactement à la dernière date de modification de son contenu.</p>
<p><em>Mise à jour</em>: Je tiens à remercier Eric Sunshine et Kris pour leurs conseils sur ce problème.</p>
</div>
<div id="afterarticle">
<div id="social">
<a href="/rss.xml" target="_blank" rel="noopener noreferrer nofollow" class="social">RSS</a>
·
<a href="https://twitter.com/home?status=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/%20via%20@yogsototh" target="_blank" rel="noopener noreferrer nofollow" class="social">Tweet</a>
·
<a href="http://www.facebook.com/sharer/sharer.php?u=http%3A%2F%2Fyannesposito.com/Scratch/fr/blog/2010-09-02-Use-git-to-calculate-trusted-mtimes/" target="_blank" rel="noopener noreferrer nofollow" class="social">FB</a>
<br />
<a class="message" href="../../../../Scratch/fr/blog/Social-link-the-right-way/">Ces liens sociaux préservent votre vie privée</a>
</div>
<div id="navigation">
<a href="../../../../">Accueil</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/blog">Blog</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/softwares">Logiciels</a>
<span class="sep">¦</span>
<a href="../../../../Scratch/fr/about">Auteur</a>
</div>
<div id="totop"><a href="#header">↑ Top ↑</a></div>
<div id="bottom">
<div>
Published on 2010-09-02
</div>
<div>
<a href="https://twitter.com/yogsototh">Follow @yogsototh</a>
</div>
<div>
<a rel="license" href="http://creativecommons.org/licenses/by/3.0/deed.en_US">Yann Esposito©</a>
</div>
<div>
Done with
<a href="http://www.vim.org" target="_blank" rel="noopener noreferrer nofollow"><strike>Vim</strike></a>
<a href="http://spacemacs.org" target="_blank" rel="noopener noreferrer nofollow">spacemacs</a>
<span class="pala">&amp;</span>
<a href="http://nanoc.ws" target="_blank" rel="noopener noreferrer nofollow"><strike>nanoc</strike></a>
<a href="http://jaspervdj.be/hakyll" target="_blank" rel="noopener noreferrer nofollow">Hakyll</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>