How to enable a blog

How to enable a blog

Note: You can do this with most versions of Soks, but these instructions refer to v1-0-0+

One blog

You can create a blog of the pages a user creates using the automatic summary class. For instance, put one of these in your start.rb file:

or you can do combinations, e.g.

Many blogs

Bil Kleb asked if there was a way of automatically creating such things for the users of his wiki, to avoid restarts.

All authors

One way is to create a WatchPage class like this (note this will be included in the next release) that yields whenever a new author is detected.


class ListOfAuthors

    def initialize(wiki, only_new_people = false, author_include = /.*/i, author_exclude = /^(Automatic|import script)/i, &action  )
        @wiki, @author_include, @author_exclude = wiki, author_include, author_exclude
        @action = action
        @authors = []
        find_all_authors( wiki ) unless only_new_people
        @wiki.watch_for( :page_revised ) { |event, page, revision| add_author( revision ) }
    end

    def add_author( revision )
        return if @authors.include? revision.author
        return unless revision.author =~ @author_include
        return unless revision.author !~ @author_exclude
        @authors << revision.author
        @action.call(revision.author)
    end

    def find_all_authors( wiki )
        wiki.each do |name, page|
            page.revisions.each do |revision|
                add_author( revision )
            end
        end
    end
end

Then in the start.rb file put something like this:


    require 'helpers/author-helpers'
    ListOfAuthors.new( wiki ) do |author|
        AutomaticSummary.new( wiki, "#{author.capitalize}'s Blog", :reverse_sort => true) { |page| page.author == author }
    end

Which should ensure a Blog is created for each user.

Some people

Cool!, said Bil Kleb, but, I don’t think we want a blog created for every author, just those that somehow request one—along the lines of your idea to have a blog sign-up page.

One way is to create a class like this (note this will be included in the next release) that watches a particular page.


class WatchPage
    def initialize( wiki, page_to_watch, call_once_at_startup = true, &action)
        wiki.watch_for( :page_revised ) do |event, page, revision|
            action.call(revision) if page.name == page_to_watch
        end
        return unless call_once_at_startup
        wiki.watch_for( :start ) do
            action.call( wiki.page( page_to_watch ).revisions.last )
        end
    end
end

Then in the start.rb file put something likes this:


blogs = {}
@watcher = WatchPage.new(wiki,"People who want Blogs") do |page|
    next if page.empty?
    page.content.split("\n").each do |person|
        next if blogs[person]
        $LOG.info "Creating a blog for #{person}" 
        blogs[person] = AutomaticSummary.new( wiki, "#{person.capitalize}'s Blog", :reverse_sort => true) { |page| page.author == person }
    end
end

Which will create a blog for each person listed on the page “People who want Blogs”, with one name per page.

An obvious bug with this is that there is no way to delete AutomaticSummarys while the wiki is running.

One problem with having it automatically tied to the author is that because we don’t have our wiki access controlled with login accounts, people sign in with various “handles”. For example, on this wiki I believe I’ve editted as at least “Bil” and “Bil Kleb”. —Bil

Well, there has to be a way of uniquely identifying that you want the page to be in your blog. Which means either using a particular author, or a particular word in the title, or a particular word on the page. All of which would require people to be consistent in some fashion… Or perhaps it could be a feature, different sign-in, different blog, perfect for those with MPDtamc

Edit this page or watch for changes using RSS.