Permalink
Browse files

sections.rb: this has long been moved to lib/hobix/plugin/sections.rb

txp-to-hobix.rb: added (thanks to ernesto guisado)
  • Loading branch information...
William Morgan
William Morgan committed Jul 30, 2005
1 parent 9394811 commit e021ff0582b76fa7a2095ec8c234747e7e149697
Showing with 56 additions and 87 deletions.
  1. +0 −87 contrib/sections.rb
  2. +56 −0 contrib/txp-to-hobix.rb
View
@@ -1,87 +0,0 @@
-## sections.rb -- Hobix section map plugin
-## (c) 2004, 2005 William Morgan. This file is released under the GNU
-## Public License.
-##
-## Contributors: Frederick Ros, Eric Stewart, Jeremy Hinegardner
-##
-## USAGE: place this file in your $HOBIXROOT/lib directory. Then, in
-## your $HOBIXROOT/hobix.yaml file (or by running 'hobix edit'), add
-## 'sections' to the 'required' block, like this:
-##
-## [...]
-## required:
-## - sections
-##
-## Finally, add 'sidebar_section_list' to the 'sidebar_list' property
-## of hobix/out/quick, like this:
-##
-## hobix/out/quick:
-## sidebar_list:
-## - sidebar_section_map
-##
-## Voila, your sidebar will display a section map when you next do a
-## regen. Note that the default Hobix CSS doesn't indent lists, so the
-## hierarchy is lost upon display. I'm not a CSS expert, but I changed
-## the sidebarBox ul section in site.css to this and it was better:
-##
-## .sidebarBox ul {
-## margin:7px;
-## padding:0px;
-## }
-##
-## Good luck. -- William <wmorgan-section_map-hobix@masanjin.net>
-
-class Hobix::Out::Quick
- def section_list(entries, topname="top level")
- counts = {}
- entries.each do |entry|
- path = (entry.id.split("/")[0 ... -1] || []) # nil in ruby 1.8.1 if path is ""
- counts[path] = 1 + (counts[path] || 0)
- end
-
- list = []; seen = {}
- counts[[]] ||= 0 # force the root
- counts.sort.each do |path, count|
- if path == []
- list.push [topname, "", 0, counts[path]]
- else
- path.inject(".") do |s, x|
- prefix = s + "/" + x
- unless seen[prefix]
- length = prefix.count '/'
- list.push [x, prefix, length, (length == path.length ? count : 0)]
- seen[prefix] = true
- end
- prefix
- end
- end
- end
- list
- end
-
- def sidebar_section_map_erb
- %q{
- <div class="sidebarBox">
- <h2 class="sidebarTitle">Sections</h2>
- <% curlev = -1 %>
- <% section_list(weblog.storage.find).each do |name, path, lev, num| %>
- <% if (lev > curlev) %>
- <% (lev - curlev).times do %> <ul> <% end %>
- <% else # less than or equal %>
- </li>
- <% end %>
- <% if (curlev > lev) %>
- <% (curlev - lev).times do %> </ul></li> <% end %>
- <% end %>
-
- <% curlev = lev %>
- <li>
- <a href="<%= weblog.expand_path path %>"><%= name %></a><% if num != 0 then %>: <%= num %> <% end %>
- <% end %>
- <% (curlev + 1).times do %>
- </li></ul>
- <% end %>
- </div>
- }
- end
-end
View
@@ -0,0 +1,56 @@
+#
+# txp_to_hobix.rb
+#
+# Converts a textpattern xml dump file generated with sqldump into a set of Hobix YAML entry files.
+#
+# Hobix::Entry code lifted from http://www.anvilwerks.com/src/wordpress_to_hobix.rb
+#
+# (c) 2005 erngui.com
+#
+require "rexml/document"
+include REXML # so that we don't have to prefix everything with REXML::...
+
+require "hobix"
+require "hobix/entry"
+require "fileutils"
+require "parsedate"
+
+txpdump = ARGV.shift
+outdir = ARGV.shift
+
+usage = <<EOT
+Usage:
+
+ ruby txp_to_hobix.rb <txp dump file> <output directory>
+
+ Converts a textpattern xml dump file generated with sqldump into a set of Hobix YAML entry files.
+
+EOT
+
+unless txpdump and outdir
+ puts usage
+ exit(1)
+end
+
+txpexport = Document.new File.new(txpdump)
+FileUtils.mkdir_p outdir
+
+txpexport.elements.each("*/textpattern") do |e|
+ entry = Hobix::Entry.new()
+ entry.title = e.elements["Title"].text
+ entry.author = e.elements["AuthorID"].text
+ res = ParseDate.parsedate(e.elements["Posted"].text)
+ posted = Time.local(*res)
+ entry.created = posted
+ entry.summary = e.elements["Excerpt"].text if e.elements["Excerpt"].text
+ entry.content = e.elements["Body"].text
+
+ # use the post title as filename after removing dodgy characters
+ yamlfile = File.join(outdir, e.elements["Title"].text.downcase.tr(" :?!", "-").gsub(/[^a-zA-Z0-9-]+/, "") + ".yaml")
+
+ puts "writing: #{yamlfile}"
+ puts yamlfile.gsub(/(\w)\w*/, '\1').tr("-", "")
+ File.open(yamlfile, "w") do |f|
+ f.write(entry.to_yaml + "\n")
+ end
+end

0 comments on commit e021ff0

Please sign in to comment.