transition complete

* word count
* categories in nav-bar
* next / prev item
* robots.txt (including sitemap)
* many minor tweaks
master
muflax 2012-04-18 23:06:03 +02:00
parent a186dacd2c
commit 1b781a23f6
26 changed files with 279 additions and 146 deletions

30
Rules
View File

@ -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

View File

@ -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

View File

@ -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 = ["<!-- (auto-generated) internal links for #{shared ? "shared content" : "site: #{site}"} -->"]
@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}"

View File

@ -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

22
commands/wc.rb Normal file
View File

@ -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

View File

@ -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 %>

11
content/date.mkd Normal file
View File

@ -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 %>

14
content/robots.erb Normal file
View File

@ -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

6
content/sitemap.erb Normal file
View File

@ -0,0 +1,6 @@
---
is_hidden: true
non_cognitive: true
---
<%= xml_sitemap :items => @site.printed_items %>

View File

@ -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;

View File

@ -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.

View File

@ -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:

View File

@ -3,6 +3,7 @@ title: FAQ
date: 2012-04-15
techne: :done
episteme: :believed
non_cognitive: true
---
- Q: What's the tl;dr?

4
layouts/all-posts.erb Normal file
View File

@ -0,0 +1,4 @@
<div id="allposts">
<a href=''>all posts by category</a>
<a href=''>all posts by date</a>
</div>

View File

@ -3,6 +3,7 @@
<% render 'main',
:navbar => true,
:search => true,
:categories => true,
:breadcrumbs => true do %>
<%= yield %>
<% end %>

View File

@ -1,3 +1,23 @@
<div id="cat-nav">
<%= @item.toc %>
<h2>Categories</h2>
<ul>
<% @site.categories.each do |cat| %>
<li><%= cat.link true %></li>
<% if @item.category == cat %>
<ul>
<% @item.category.members.each do |i| %>
<%= render 'list-item', :item => i, :episteme => false %>
<% end %>
</ul>
<% end %>
<% end %>
</ul>
<h2>All Posts</h2>
<ul>
<li><a href='/categories/'>All Posts By Category</a></li>
<li><a href='/date/'>All Posts By Date</a></li>
<li><a href='/rss.xml'>RSS feed</a></li>
</ul>
</div>

View File

@ -1,24 +1,14 @@
<!-- print all items in a category, nicely formatted -->
<!-- find category index -->
<% cat = @site.category @category %>
<!-- header -->
# [<%= cat.item[:title] %>][]
<h1><%= cat.link %></h1>
<!-- print items in nice list -->
<% cat.members.sort_by{|i| i[:date]}.reverse.each do |i|
techne = "<span class='techne_#{i[:techne]}'>#{i[:date]}</span>"
status = "(#{episteme_cat i[:episteme]}) (#{techne})"
%>
{:.table}
- <span class='align_left'>[<%= i[:title]%>][]</span>
<span class='align_right'><%= status %></span>
<div style='clear: both'></div>
<% end %>
<ul class="table">
<% cat.members.sort_by{|i| i[:date]}.reverse.each do |i| %>
<%= render 'list-item', :item => i, :episteme => true %>
<% end %>
</ul>

View File

@ -12,7 +12,7 @@
<%= render 'next-prev', :item => @item %>
<%= render 'comments' %>
<%= render 'comments', :item => @item %>
</div>

View File

@ -2,12 +2,12 @@
<% if @item.epistemic? %>
<div id="episteme">
<p><span class="align_left">
Last modified: <%= @item[:date] %> (<%= techne @item[:techne] %>).
Last modified: <%= @item[:date] %> (<%= techne_title @item[:techne] %>).
</span>
<span class="align_right">
Epistemic state:
<a class='episteme' href='/episteme/'>
<%= episteme @item[:episteme] %></a>.
<%= episteme_title @item[:episteme] %></a>.
</span>
</p>
</div>

15
layouts/list-item.erb Normal file
View File

@ -0,0 +1,15 @@
<li>
<span class='align_left'>
<a href="<%= @item.identifier %>">
<%= @item[:title]%>
</a>
</span>
<% if @episteme %>
<span class='align_right'>
<%= "(#{episteme_cat @item[:episteme]}) (<span class='techne_#{@item[:techne]}'>#{@item[:date]}</span>)" %>
</span>
<% end %>
<div style='clear: both'></div>
</li>

View File

@ -23,6 +23,8 @@
<!-- navigation sidebar -->
<div id="nav">
<h1 class="title">Navigation</h1>
<% if @search %>
<%= google_search %>
<% end %>
@ -32,7 +34,7 @@
<% end %>
<% if @categories %>
<%= render 'cat-nav' %>
<%= render 'cat-nav', :item => @item %>
<% end %>
</div>

View File

@ -1,13 +1,26 @@
<div id="next-prev">
<p><span class="align_left">
<a class='nextprev' href='<%= @item.path %>'>
<%= @item[:title] %>
</a>
</span>
<span class="align_right">
<a class='nextprev' href='<%= @item.path %>'>
<%= @item[:title] %>
</a>
</span>
</p>
</div>
<% if @item.article? %>
<div id="next_prev">
<p>
<% 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? %>
<span class="align_left">
<a class='next_prev' href='<%= prev_item.path %>'>
<%= prev_item[:title] %>
</a>
</span>
<% end %>
<% unless next_item.nil? %>
<span class="align_right">
<a class='next_prev' href='<%= next_item.path %>'>
<%= next_item[:title] %>
</a>
</span>
<% end %>
</p>
</div>
<% end %>

View File

@ -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{^\/(?<cat>.+?)/})
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
"<a href='#{@item.identifier}'>#{desc}</a>"
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

View File

@ -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}"
"<a class='episteme' href='/episteme/'>#{episteme_title status}</a>"
end
class Nanoc::Item

View File

@ -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

View File

@ -11,7 +11,7 @@ class Nanoc::Item
max_levels = 3
# begin toc
res = '<h1>Content</h1>'
res = '<h2>Content</h2>'
# iterate through the body, find headers and build toc as we go along
level = 0