<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nikola on C'est la Z</title><link>https://cestlaz.github.io/cestlaz-old-hugo.github.io/tags/nikola/</link><description>C'est la Z (nikola)</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><lastBuildDate>Sun, 15 May 2016 00:00:00 +0000</lastBuildDate><atom:link href="https://cestlaz.github.io/cestlaz-old-hugo.github.io/tags/nikola/rss.xml" rel="self" type="application/rss"/><item><title>Shell short - tagging old posts in Nikola</title><link>https://cestlaz.github.io/cestlaz-old-hugo.github.io/posts/shell-short-tagging/</link><pubDate>Sun, 15 May 2016 00:00:00 +0000</pubDate><guid>https://cestlaz.github.io/cestlaz-old-hugo.github.io/posts/shell-short-tagging/</guid><description>
&lt;p>
Quick post to add to the recent command line fu I&amp;#39;ve been writing
about.&lt;/p>
&lt;p>
&lt;a href="https://twitter.com/dougpete">Douglas Peterson&lt;/a> had another &lt;strong>&lt;strong>Whatever happened to&lt;/strong>&lt;/strong> post. This time
on &lt;a href="https://dougpete.wordpress.com/2016/05/15/whatever-happened-to-6/">Logo&lt;/a>. I wanted to reply, talk about NetLogo and link to some of my
old NetLogo posts to help show how cool it is.&lt;/p>
&lt;p>
Nikola supports tags, makes a nice &lt;a href="http://cestlaz.github.io/categories">tags&lt;/a> page and for each tag, a nice
page of all the &lt;a href="http://cestlaz.github.io/categories/netlogo">links&lt;/a>.&lt;/p>
&lt;p>
Nikola has a plugin &lt;strong>&lt;strong>tags&lt;/strong>&lt;/strong> which lets you manage tags from the
command line. For instance:&lt;/p>
&lt;div class="src src-bash">
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>nikola tags -a netlogo posts/somepost.org&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>
Would add the tag &lt;strong>&lt;strong>netlogo&lt;/strong>&lt;/strong> to the specified post.&lt;/p>
&lt;p>
The problem: The tags plugin only works if the post has a &lt;strong>&lt;strong>tag:&lt;/strong>&lt;/strong>
line already present in it&amp;#39;s header comment and I hadn&amp;#39;t put them in
my older posts.&lt;/p>
&lt;p>
I had a bunch of posts, all of them in one directory. All the new ones
were &lt;strong>&lt;strong>.org&lt;/strong>&lt;/strong> files and had the tag slug. The others were &lt;strong>&lt;strong>.md&lt;/strong>&lt;/strong> markdown
files and &lt;strong>&lt;strong>.html&lt;/strong>&lt;/strong> html files.&lt;/p>
&lt;p>
Here&amp;#39;s what a typical top block looks like:&lt;/p>
&lt;div class="src src-html">
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-html" data-lang="html">&lt;span style="display:flex;">&lt;span>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-html" data-lang="html">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">&amp;lt;!--
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">title: &amp;#34;Looking for interesting questions&amp;#34;
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">date: 2010-01-03
&lt;/span>&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#75715e">--&amp;gt;&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>
Sed to the rescue. Here&amp;#39;s the what I ended up typing (from within the
posts directory) to add the
&lt;strong>&lt;strong>tags&lt;/strong>&lt;/strong> slug to the top comments right above the &lt;strong>&lt;strong>.. type: text:&lt;/strong>&lt;/strong> line:&lt;/p>
&lt;div class="src src-bash">
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>ls *md *html | &lt;span style="color:#66d9ef">while&lt;/span> read filename
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">do&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>sed &lt;span style="color:#e6db74">&amp;#34;/type: text/ i .. tags: &amp;#34;&lt;/span> $filename
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#66d9ef">done&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>
A line at a time:&lt;/p>
&lt;div id="outline-container-headline-1" class="outline-3">
&lt;h3 id="headline-1">
ls *md *html
&lt;/h3>
&lt;div id="outline-text-headline-1" class="outline-text-3">
&lt;p>This lists all the files with that end in &lt;strong>&lt;strong>md&lt;/strong>&lt;/strong> or &lt;strong>&lt;strong>html&lt;/strong>&lt;/strong>&lt;/p>
&lt;/div>
&lt;/div>
&lt;div id="outline-container-headline-2" class="outline-3">
&lt;h3 id="headline-2">
| while read filename
&lt;/h3>
&lt;div id="outline-text-headline-2" class="outline-text-3">
&lt;p>The vertical bar (pipe) sends the output of &lt;strong>&lt;strong>ls&lt;/strong>&lt;/strong> into the &lt;strong>&lt;strong>while read&lt;/strong>&lt;/strong>
command. The &lt;strong>&lt;strong>while&lt;/strong>&lt;/strong> command sets up a loop which, each time
through, reads the next input and places into the variable
&lt;strong>&lt;strong>filename&lt;/strong>&lt;/strong>. The body of the loop is between the &lt;strong>&lt;strong>do&lt;/strong>&lt;/strong> and the
&lt;strong>&lt;strong>done&lt;/strong>&lt;/strong>.&lt;/p>
&lt;/div>
&lt;/div>
&lt;div id="outline-container-headline-3" class="outline-3">
&lt;h3 id="headline-3">
sed &amp;#34;/ type: text/ i .. tags: &amp;#34; $filename
&lt;/h3>
&lt;div id="outline-text-headline-3" class="outline-text-3">
&lt;p>Sed is the stream editor. The stuff between the slashes finds the line
with the text &lt;strong>&lt;strong>type: text&lt;/strong>&lt;/strong> in it. The &lt;strong>&lt;strong>i&lt;/strong>&lt;/strong> inserts a line above and
the rest of the stuff in the quotes is what to insert. The
&lt;strong>&lt;strong>$filename&lt;/strong>&lt;/strong> expands to each filename, one each time through the
loop.&lt;/p>
&lt;p>
Now all of my files have blank &lt;strong>&lt;strong>tag&lt;/strong>&lt;/strong> slugs so I can find my netlogo
posts and tag them:&lt;/p>
&lt;div class="src src-bash">
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-bash" data-lang="bash">&lt;span style="display:flex;">&lt;span>nikola tags -a netlogo &lt;span style="color:#e6db74">`&lt;/span>grep -i -l netlogo posts/*&lt;span style="color:#e6db74">`&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>
&lt;/div>
&lt;p>
Any command in backticks expands to the result of the commmand. The
grep command has two argiments: &lt;strong>&lt;strong>-i&lt;/strong>&lt;/strong> means ignore case so it will
find netlogo, NetLogo, NETLOGO, etc.. The &lt;strong>&lt;strong>-l&lt;/strong>&lt;/strong> tells grep to just
output the filenames. So, the grep command will expand to a list of
files that mention netlogo. The full command adds the netlogo tag to
all of them.&lt;/p>
&lt;p>
So, just a bit of quick shell scripting and I&amp;#39;ve:&lt;/p>
&lt;ul>
&lt;li>modified all old posts to accept tags.&lt;/li>
&lt;li>added the netlogo tag to all my netlogo posts.&lt;/li>
&lt;/ul>
&lt;p>You can find all those posts &lt;a href="http://cestlaz.github.io/categories/netlogo">here&lt;/a>.&lt;/p>
&lt;/div>
&lt;/div></description></item></channel></rss>