From 1b781a23f6ea83cf7ec2c4a996302da01b370f47 Mon Sep 17 00:00:00 2001 From: muflax Date: Wed, 18 Apr 2012 23:06:03 +0200 Subject: [PATCH] transition complete * word count * categories in nav-bar * next / prev item * robots.txt (including sitemap) * many minor tweaks --- Rules | 30 +++++--- commands/last.rb | 4 +- commands/references.rb | 21 +----- commands/sites.rb | 75 ++++++++++++++++++- commands/wc.rb | 22 ++++++ .../all.mkd => content/categories.mkd | 6 +- content/date.mkd | 11 +++ content/robots.erb | 14 ++++ content/sitemap.erb | 6 ++ content/styles/default.scss | 35 +++++---- content_daily/about.mkd | 1 + content_daily/index.mkd | 2 +- content_sutra/faq.mkd | 1 + layouts/all-posts.erb | 4 + layouts/blog.erb | 1 + layouts/cat-nav.erb | 22 +++++- layouts/category.erb | 22 ++---- layouts/content-embed.erb | 2 +- layouts/episteme.erb | 4 +- layouts/list-item.erb | 15 ++++ layouts/main.erb | 4 +- layouts/next-prev.erb | 39 ++++++---- lib/default.rb | 24 +++++- lib/episteme.rb | 6 +- lib/sites.rb | 52 ------------- lib/toc.rb | 2 +- 26 files changed, 279 insertions(+), 146 deletions(-) create mode 100644 commands/wc.rb rename content_blog/all.mkd => content/categories.mkd (70%) create mode 100644 content/date.mkd create mode 100644 content/robots.erb create mode 100644 content/sitemap.erb create mode 100644 layouts/all-posts.erb create mode 100644 layouts/list-item.erb delete mode 100644 lib/sites.rb diff --git a/Rules b/Rules index 3bb6fe9..cc8f1af 100644 --- a/Rules +++ b/Rules @@ -61,10 +61,6 @@ compile '/feed/' do filter :erb end -compile '/htaccess/' do - filter :erb -end - compile '*' do if item.binary? # don't filter binary items @@ -87,17 +83,21 @@ compile '*' do filter :colorize_syntax, :default_colorizer => :pygmentize when "org" # org-mode pages filter :org + when "erb" # general erb files + filter :erb end # layout - if @site.blog? - layout 'blog' - else - layout 'default' - end + unless @item[:is_hidden] + if @site.blog? + layout 'blog' + else + layout 'default' + end - # clean up - filter :tidy + # clean up + filter :tidy + end end end @@ -109,6 +109,14 @@ route '/htaccess/' do '/.htaccess' end +route '/robots/' do + '/robots.txt' +end + +route '/sitemap/' do + '/sitemap.xml' +end + route '/styles/*' do route_with_new_extension "css" end diff --git a/commands/last.rb b/commands/last.rb index b59a66d..fa9293e 100644 --- a/commands/last.rb +++ b/commands/last.rb @@ -5,9 +5,7 @@ description 'Opens last page in Emacs.' module Nanoc::CLI::Commands class Last < ::Nanoc::CLI::CommandRunner def run - page = Dir['content_daily/log/*.mkd'].map do |l| - [l.match(/\/(\d+).mkd$/)[1].to_i, l] - end.sort.last[1] + page = daily_logs.last puts "editing: #{page}..." system "emacs-gui #{page}" end diff --git a/commands/references.rb b/commands/references.rb index bc8f106..71f12e7 100644 --- a/commands/references.rb +++ b/commands/references.rb @@ -7,28 +7,15 @@ required :s, :sites, 'sites' module Nanoc::CLI::Commands class References < ::Nanoc::CLI::CommandRunner - # load data from site - def load_site(site=nil) - self.require_site - @current_site = self.site - - # load site-specific config - @current_site.extended_build_config('.', site) unless site.nil? - - # load site data (including plugins) - @current_site.load - - # find relevant items - @current_site.find_printed_items - end - # collect links in site def extract_links site=nil + current_site = load_site site + shared = site.nil? page_links = [""] - @current_site.printed_items.each do |i| + current_site.printed_items.each do |i| # don't include shared content with sites unless shared next if i.shared? @@ -57,8 +44,6 @@ module Nanoc::CLI::Commands puts "loading: #{site}" end - load_site site - page_links = extract_links site puts "#links: #{page_links.size}" diff --git a/commands/sites.rb b/commands/sites.rb index 70e6e59..58fecfa 100644 --- a/commands/sites.rb +++ b/commands/sites.rb @@ -12,7 +12,7 @@ site_cmds = [ 'watch', ] -# load site-specific config +# site-specific config module ::Nanoc class Site def extended_build_config(dir_or_config_hash, site) @@ -50,6 +50,56 @@ module ::Nanoc end @config[:watcher][:dirs_to_watch] << "content_#{site}" + + @config[:base_url] = self.url + end + + def main_site? + $site == "muflax" + end + + def blog? + !main_site? # everything is a blog except for the main site + end + + def disqus_site + # TODO merge them all? + # site -> disqus shortname + case $site + when "muflax" + "muflax" + when "sutra" + "muflaxsutra" + when "daily" + "dailymuflax" + when "blog" + "muflaxblog" + else # put 'em on the main site + "muflax" + end + end + + def url + "http://#{main_site? ? "" : "#{$site}."}muflax.com" + end + + def disqus_url item + url + item.identifier + end + + def title + case $site + when "muflax" + "lies and wonderland" + when "sutra" + "Blogchen" + when "daily" + "muflax becomes a saint" + when "blog" + "muflax' mindstream" + else # placeholder + "muflaxia" + end end end end @@ -92,6 +142,29 @@ module Nanoc::CLI def sites_arg sites sites.nil? ? all_sites : sites.split(",") end + + # load data from site + def load_site site=nil + self.require_site + current_site = self.site + + # load site-specific config + current_site.extended_build_config('.', site) unless site.nil? + + # load site data (including plugins) + current_site.load + + current_site + end + + def daily_logs + dir = "content_daily/log" + pattern = /\/(\d+).mkd$/ + + Dir["#{dir}/*.mkd"].select{|l| l.match(pattern)}.sort_by do |l| + l.match(pattern)[1].to_i + end + end end end diff --git a/commands/wc.rb b/commands/wc.rb new file mode 100644 index 0000000..46cf972 --- /dev/null +++ b/commands/wc.rb @@ -0,0 +1,22 @@ +usage 'wc' +summary 'word count of logs' +description 'Prints word count of log entries for Beeminder logging.' + +module Nanoc::CLI::Commands + class WordCount < ::Nanoc::CLI::CommandRunner + def run + daily_logs.each do |log| + data = File.read(log) + pieces = data.split(/^(-{5}|-{3})\s*$/) + next if pieces.size < 4 + + content = pieces[4..-1].join.strip + words = content.scan(/( \[.+?\]\[.*?\][[:punct:]]* | <%=?.+?%> | \S+ )/x) + + puts "#{log} -> #{words.size}" + end + end + end +end + +runner Nanoc::CLI::Commands::WordCount diff --git a/content_blog/all.mkd b/content/categories.mkd similarity index 70% rename from content_blog/all.mkd rename to content/categories.mkd index 83c0c83..b19c3d2 100644 --- a/content_blog/all.mkd +++ b/content/categories.mkd @@ -1,13 +1,11 @@ --- -title: All Posts +title: All Posts By Category non_cognitive: true no_comments: true --- -All posts from the [blog][]. +All posts by category. <% @site.categories(false).each do |cat| %> <%= category cat %> <% end %> - - diff --git a/content/date.mkd b/content/date.mkd new file mode 100644 index 0000000..c39a2a7 --- /dev/null +++ b/content/date.mkd @@ -0,0 +1,11 @@ +--- +title: All Posts By Date +non_cognitive: true +no_comments: true +--- + +All posts by date. + +<% @site.items_by_date.reverse.each do |item| %> +<%= render 'list-item', :item => item %> +<% end %> diff --git a/content/robots.erb b/content/robots.erb new file mode 100644 index 0000000..13b3581 --- /dev/null +++ b/content/robots.erb @@ -0,0 +1,14 @@ +--- +is_hidden: true +non_cognitive: true +--- + +# stay in the box, clippy +User-agent: ufai +Disallow: /release + +# crawlers +User-agent: * +Disallow: /pigs/ +Disallow: /stuff/ +Sitemap: <%= @site.url %>/sitemap.xml diff --git a/content/sitemap.erb b/content/sitemap.erb new file mode 100644 index 0000000..213f692 --- /dev/null +++ b/content/sitemap.erb @@ -0,0 +1,6 @@ +--- +is_hidden: true +non_cognitive: true +--- + +<%= xml_sitemap :items => @site.printed_items %> diff --git a/content/styles/default.scss b/content/styles/default.scss index f2d4850..5e3359d 100644 --- a/content/styles/default.scss +++ b/content/styles/default.scss @@ -42,16 +42,14 @@ div#main { margin-bottom: 3em; } -div#title { - h1 { - background: $crumb-bg; - color: $crumb-fg; - line-height: 1.3em; - font-size: 1.7em; - font-weight: normal; - margin-top: 0; - text-align: center; - } +h1.title { + background: $crumb-bg; + color: $crumb-fg; + line-height: 1.3em; + font-size: 1.7em; + font-weight: normal; + margin-top: 0; + text-align: center; } a:link.title, a:hover.title, a:visited.title, a:active.title { @@ -84,6 +82,13 @@ div#nav { float: left; width: $right-col - $margin; margin-left: $margin; + text-align: left; + + h2, h3, h4, h5, h6 { + font-weight: normal; + margin-left: 0; + margin-right: 0; + } } /* toc */ @@ -96,7 +101,10 @@ div#toc { font-weight: normal; margin-top: 0; } - text-align: left; +} + +div#cat-nav { + line-height: 1.5em; } div#crumb { @@ -117,9 +125,8 @@ div#crumb { margin: 0 auto; } -div.nextprev { +div#next_prev { border-top: 10px solid $h1; - text-align: center; } div.footnotes { @@ -234,7 +241,7 @@ div.figure { h1 { background: $h2; color: #000; - font-size: 1.7em; + font-size: 1.5em; line-height: 1.3; text-align: center; diff --git a/content_daily/about.mkd b/content_daily/about.mkd index cf1193d..68eaf23 100644 --- a/content_daily/about.mkd +++ b/content_daily/about.mkd @@ -4,6 +4,7 @@ alt_titles: [about dlog] date: 2012-04-12 techne: :done episteme: :believed +non_cognitive: true --- I like talking about ideas. I like logging stuff. Writing this blog has vastly increased my thinking output. (Which is good, and unexpected.) I see people use daily logs of what they did and these people kick my ass when it comes to achievements, even though for each individual day, they don't do more than I can. It's just the pure, raw consistency. They still do the same shit 6 months from now and by then, they utterly outperform me. diff --git a/content_daily/index.mkd b/content_daily/index.mkd index 907fb52..460a687 100644 --- a/content_daily/index.mkd +++ b/content_daily/index.mkd @@ -7,7 +7,7 @@ no_comments: true Because death doesn't conquer itself, you know. -([More details what this is about.][about] See the [main site][main] or [blog][] for real content. There's also an [RSS feed][RSS].) +[More details what this is about.][about] See the [main site][main] or [blog][] for real content. There's also an [RSS feed][RSS]. Latest entry: diff --git a/content_sutra/faq.mkd b/content_sutra/faq.mkd index 230650c..a4d488d 100644 --- a/content_sutra/faq.mkd +++ b/content_sutra/faq.mkd @@ -3,6 +3,7 @@ title: FAQ date: 2012-04-15 techne: :done episteme: :believed +non_cognitive: true --- - Q: What's the tl;dr? diff --git a/layouts/all-posts.erb b/layouts/all-posts.erb new file mode 100644 index 0000000..6dde1ad --- /dev/null +++ b/layouts/all-posts.erb @@ -0,0 +1,4 @@ +
+ all posts by category + all posts by date +
diff --git a/layouts/blog.erb b/layouts/blog.erb index 74ae139..84e884d 100644 --- a/layouts/blog.erb +++ b/layouts/blog.erb @@ -3,6 +3,7 @@ <% render 'main', :navbar => true, :search => true, + :categories => true, :breadcrumbs => true do %> <%= yield %> <% end %> diff --git a/layouts/cat-nav.erb b/layouts/cat-nav.erb index eef242f..721db80 100644 --- a/layouts/cat-nav.erb +++ b/layouts/cat-nav.erb @@ -1,3 +1,23 @@
- <%= @item.toc %> +

Categories

+ + +

All Posts

+
diff --git a/layouts/category.erb b/layouts/category.erb index 90ff82e..c416368 100644 --- a/layouts/category.erb +++ b/layouts/category.erb @@ -1,24 +1,14 @@ - <% cat = @site.category @category %> - -# [<%= cat.item[:title] %>][] +

<%= cat.link %>

- -<% cat.members.sort_by{|i| i[:date]}.reverse.each do |i| - techne = "#{i[:date]}" - status = "(#{episteme_cat i[:episteme]}) (#{techne})" -%> - -{:.table} -- [<%= i[:title]%>][] - <%= status %> - -
- -<% end %> + diff --git a/layouts/content-embed.erb b/layouts/content-embed.erb index d647bde..1ad7855 100644 --- a/layouts/content-embed.erb +++ b/layouts/content-embed.erb @@ -12,7 +12,7 @@ <%= render 'next-prev', :item => @item %> - <%= render 'comments' %> + <%= render 'comments', :item => @item %> diff --git a/layouts/episteme.erb b/layouts/episteme.erb index 3216d8d..8d62324 100644 --- a/layouts/episteme.erb +++ b/layouts/episteme.erb @@ -2,12 +2,12 @@ <% if @item.epistemic? %>

- Last modified: <%= @item[:date] %> (<%= techne @item[:techne] %>). + Last modified: <%= @item[:date] %> (<%= techne_title @item[:techne] %>). Epistemic state: - <%= episteme @item[:episteme] %>. + <%= episteme_title @item[:episteme] %>.

diff --git a/layouts/list-item.erb b/layouts/list-item.erb new file mode 100644 index 0000000..fe89c30 --- /dev/null +++ b/layouts/list-item.erb @@ -0,0 +1,15 @@ +
  • + + + <%= @item[:title]%> + + + + <% if @episteme %> + + <%= "(#{episteme_cat @item[:episteme]}) (#{@item[:date]})" %> + + <% end %> + +
    +
  • diff --git a/layouts/main.erb b/layouts/main.erb index b74b39a..7135a01 100644 --- a/layouts/main.erb +++ b/layouts/main.erb @@ -23,6 +23,8 @@ diff --git a/layouts/next-prev.erb b/layouts/next-prev.erb index d22d19b..f76ab5d 100644 --- a/layouts/next-prev.erb +++ b/layouts/next-prev.erb @@ -1,13 +1,26 @@ -
    -

    - - ‹ <%= @item[:title] %> - - - - - <%= @item[:title] %> › - - -

    -
    +<% if @item.article? %> +
    +

    + <% items = @site.items_by_date @category + index = items.index(@item) + next_item = items[index + 1] + prev_item = index > 0 ? items[index - 1] : nil %> + + <% unless prev_item.nil? %> + + + ‹ <%= prev_item[:title] %> + + + <% end %> + + <% unless next_item.nil? %> + + + <%= next_item[:title] %> › + + + <% end %> +

    +
    +<% end %> diff --git a/lib/default.rb b/lib/default.rb index b072b2a..767eb84 100644 --- a/lib/default.rb +++ b/lib/default.rb @@ -1,8 +1,11 @@ # Helper functions for site-building. include Nanoc::Helpers::Rendering +include Nanoc::Helpers::XMLSitemap class Nanoc::Item + attr_accessor :category + def add_content content @raw_content += "\n\n#{content}" end @@ -32,7 +35,7 @@ class Nanoc::Item not self[:is_category] and not draft? and cognitive? end - def category + def category_slug if m = self.identifier.match(%r{^\/(?.+?)/}) m[:cat] else @@ -46,8 +49,10 @@ class Category def initialize item, members=[] @item = item - @slug = item.category + @slug = @item.category_slug @members = members + + @members.each {|i| i.category = self} end def includes? item @@ -61,6 +66,17 @@ class Category @members.reject{|i| i.draft?} end end + + def title + @item[:title] + end + + def link count=false + desc = title + desc += " (#{@members.size})" if count + + "#{desc}" + end end class Nanoc::Site @@ -97,7 +113,7 @@ class Nanoc::Site def find_categories # find categories cats = @printed_items.select {|i| i[:is_category]}.map do |c| - members = @printed_items.select{|i| not i[:is_category] and i.category == c.category} + members = @printed_items.select{|i| not i[:is_category] and i.category_slug == c.category_slug} Category.new(c, members) end @@ -110,7 +126,7 @@ class Nanoc::Site end # sort by title - @categories = cats.sort_by {|c| c[:cat].item[:title]} + @categories = cats.sort_by {|c| c[:cat].title} end def categories all=true diff --git a/lib/episteme.rb b/lib/episteme.rb index 8b6bb92..547de71 100644 --- a/lib/episteme.rb +++ b/lib/episteme.rb @@ -1,6 +1,6 @@ # Helper functions for epistemic states. -def techne status +def techne_title status case status when :rough "needs revisiting" @@ -13,7 +13,7 @@ def techne status end end -def episteme status +def episteme_title status case status when :broken "semi-believed" @@ -25,7 +25,7 @@ def episteme status end def episteme_cat status - "[#{episteme status}][Epistemic State]{:.episteme}" + "#{episteme_title status}" end class Nanoc::Item diff --git a/lib/sites.rb b/lib/sites.rb deleted file mode 100644 index 319e93a..0000000 --- a/lib/sites.rb +++ /dev/null @@ -1,52 +0,0 @@ -module Nanoc - class Site - def main_site? - $site == "muflax" - end - - def blog? - !main_site? # everything is a blog except for the main site - end - - def disqus_site - # TODO merge them all? - # site -> disqus shortname - case $site - when "muflax" - "muflax" - when "sutra" - "muflaxsutra" - when "daily" - "dailymuflax" - when "blog" - "muflaxblog" - else # put 'em on the main site - "muflax" - end - end - - def url - "http://#{main_site? ? "" : "#{$site}."}muflax.com" - end - - - def disqus_url item - url + item.identifier - end - - def title - case $site - when "muflax" - "lies and wonderland" - when "sutra" - "Blogchen" - when "daily" - "muflax becomes a saint" - when "blog" - "muflax' mindstream" - else # placeholder - "muflaxia" - end - end - end -end diff --git a/lib/toc.rb b/lib/toc.rb index b9da82d..371dd81 100644 --- a/lib/toc.rb +++ b/lib/toc.rb @@ -11,7 +11,7 @@ class Nanoc::Item max_levels = 3 # begin toc - res = '

    Content

    ' + res = '

    Content

    ' # iterate through the body, find headers and build toc as we go along level = 0