How I tagified all my snippets

To tagify all my snippets I first of all wrote a script to open each snippets file, find the tags, and then make hyperlinks from the tags at the footer of the page. Then I wrote the following script to generate all the tag files (for each tag) containing all related snippets:

require 'dynarex'
require 'open-uri'

def tagify(tags, category='snippets')

  dynarex = Dynarex.new "http://a0.jamesrobertson.eu/#{category}/dynarex.xml"
  rows = dynarex.to_h

  tags.each do |tag|

    keyword = tag
    a = rows.select {|x| x[:title][/##{keyword}\b/]}

    return if a.empty?

    results = Dynarex.new 'results/result(title, url)'
    results.xslt = '/xsl/dynarex-b.xsl'
    a.each {|record| results.create record }

    filepath = "/home/james/jamesrobertson.eu/%s/tags/%s.xml" % \
                                                 [category, keyword.downcase]
    results.save filepath

  end

end


dx = Dynarex.new 'http://www.jamesrobertson.eu/snippets/dynarex.xml'

tags = dx.all.inject([]) {|r,x| r + x.title.scan(/#(\w+)/).flatten(1)}.uniq

category = 'snippets'

tags.reject! do |tag|
  filepath = "/home/james/jamesrobertson.eu/%s/tags/%s.xml" % \
                                                 [category, tag.downcase]
  File.exists?  filepath
end

tagify tags

see also