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 = "{category}/dynarex.xml"
  rows = dynarex.to_h

  tags.each do |tag|

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

    return if a.empty?

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

    filepath = "/home/james/" % \
                                                 [category, keyword.downcase] filepath



dx = ''

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

category = 'snippets'

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

tagify tags

see also