all repos — h3rald @ 2ae78b6bb7e79e0355eb61ef2e7fc5f54e23ac83

The sources of https://h3rald.com

Disqus integration + migrated old comments
* Closes #3.
h3rald h3rald@h3rald.com
Sun, 09 Aug 2009 20:57:40 +0200
commit

2ae78b6bb7e79e0355eb61ef2e7fc5f54e23ac83

parent

038a385c8fa60b3b207d8e4eeb6120d174f2120a

M RakefileRakefile

@@ -1,4 +1,4 @@

-Dir['tasks/**/*.rake'].sort.each { |rakefile| load rakefile; puts rakefile } +Dir['tasks/**/*.rake'].sort.each { |rakefile| load rakefile} task :default => ["site:update"] do end
M layouts/default.htmlayouts/default.htm

@@ -110,21 +110,21 @@ <!-- CONTENT END -->

</div> <!-- CONTAINER END --> <div class="inner-border"></div> - <div id="border-bottom"></div> - <div class="clearfooter"></div> - </div> <!-- WRAPPER END --> - <div id="footer"> - <div id="footer-container"> - - + <div id="border-bottom"> <% if @page.permalink == 'home' then %> <%= render 'services' %> <% end %> - <% if @page.type == 'article' then %> + <script type="text/javascript"> + var disqus_developer = 1; + </script> <%= render 'comments' %> <% end %> - + </div> + <div class="clearfooter"></div> + </div> <!-- WRAPPER END --> + <div id="footer"> + <div id="footer-container"> <div class="footer-div"> H3RALD Web Site v8.0.0 <em>"xStatic"</em> &mdash; &copy; 2004-2009 <strong>Fabio Cevasco</strong> &mdash; <a class="link" href="http://creativecommons.org/licenses/by-nc-nd/3.0/">Some rights reserved</a> | <a href="http://validator.w3.org/check?uri=referer" class="link">XHTML 1.1</a> | <a href="http://jigsaw.w3.org/css-validator/" class="link">CSS 2.1</a> </div>
M resources/css/elements.cssresources/css/elements.css

@@ -127,6 +127,10 @@ }

/*** HOME Page ***/ +#services +{ + height: 450px; +} #services li { margin-left: 0;
M resources/css/layout.cssresources/css/layout.css

@@ -149,21 +149,22 @@

#wrapper { min-height: 100%; - margin-bottom: -450px; + margin-bottom: -40px; position: relative; background: #fff url('../images/bkg.png') top repeat; } #border-top { - background: #000 url('../images/border-top.png') top repeat-x; + background: #000 url('../images/border-top.png') bottom repeat-x; height: 35px; } #border-bottom { - background: #000 url('../images/border-bottom.png') bottom repeat-x; - height: 35px; + background: #000 url('../images/border-bottom.png') top repeat-x; + height: auto; + padding-top: 35px } .inner-border

@@ -179,7 +180,7 @@ }

#footer { position: relative; - height: 450px; + height: 40px; font-family: Georgia, Serif; width: 100%; font-size: 95%;

@@ -189,7 +190,7 @@ }

.clearfooter { - height: 450px; + height: 40px; clear: both; } .footer-left, .footer-right, .footer-center
D tasks/db.rake

@@ -1,98 +0,0 @@

-require 'rubygems' -require 'extlib' -require 'pathname' -require 'fileutils' -begin - require 'mysql' - require 'sequel' -rescue Exception => e -end -require 'yaml' -require 'iconv' - -module TypoUtils - - def get_filter(db, fid) - filter = db[:text_filters].where("id = ?", fid).get(:name).downcase - # Multiple filters are not handled (e.g. markdown smartypants) - filter = filter.split(' ')[0] - # Prepare metadata - case filter - when 'textile' then - return ['redcloth'], 'textile' - when 'markdown' then - return ['bluecloth'], 'markdown' - when 'bbcode' then - return ['bbcode'], 'bbcode' - else - return [], 'txt' - end - end - - def convert_code_blocks(text) - text.gsub!(/<typo:code lang="([a-zA-Z0-9]+)">/, '<% highlight :\1 do %>') - text.gsub!(/<typo:code>/, '<% highlight :text do %>') - text.gsub!(/<\/typo:code>/, "<% end %>") - text - end - - def write_page(meta, contents, extension) - path = (meta['type'] == 'article') ? Pathname.new(Dir.pwd)/"content/articles/" : Pathname.new(Dir.pwd)/"content/" - name = "#{meta['permalink']}.#{extension}" - path.mkpath - (path/name).open('w+') do |f| - f.print "--" - f.puts meta.to_yaml - f.puts "-----" - f.puts contents - end - end - -end - -include TypoUtils - -namespace :db do - - task :migrate => [:migrate_contents] do - end - - task :migrate_contents, :db, :usr, :pwd, :host do |t, args| - raise RuntimeError, "Please provide :db, :usr, :pass" unless args[:db] && args[:usr] && args[:pwd] - db = Sequel.mysql args[:db], :user => args[:usr], :password => args[:pwd], :host => args[:host] || 'localhost' - # Remove all existing pages! - dir = Pathname.new(Dir.pwd/'content') - dir.rmtree if dir.exist? - dir.mkpath - # Prepare page data - db[:contents].where("state = 'published' || type = 'Page'").each do |a| - meta = {} - # Process tags - if a[:keywords] then - if a[:keywords].match ',' then - meta['tags'] = a[:keywords].downcase.split(", ") - else - meta['tags'] = a[:keywords].downcase.split(" ") - end - else - meta['tags'] = [] - end - meta['permalink'] = a[:permalink] || a[:name] - meta['title'] = a[:title] - meta['type'] = a[:type].downcase - meta['date'] = a[:published_at] - meta['toc'] = true - meta['filters_pre'], extension = get_filter db, a[:text_filter_id] - contents = a[:body]+a[:extended].to_s - if contents.match /<typo:code/ then - # troubles if erb filter is enabled! - contents.gsub! /<%/, '&lt;%' - contents.gsub! /%>/, '%&gt;' - contents = convert_code_blocks contents - meta['filters_pre'] = ['erb'].concat meta['filters_pre'] - end - write_page meta, contents, extension - end - end - -end
M tasks/site.raketasks/site.rake

@@ -2,6 +2,7 @@ require 'rubygems'

require 'extlib' require 'pathname' require 'fileutils' +require 'nanoc' namespace :site do

@@ -12,18 +13,25 @@ puts "Deleting all files in output dir..."

output.rmtree end - task :update => [:copy_files] do + task :update => [:copy_resources, :build_tag_pages] do system "nanoc co" end - task :run => [:copy_files] do + task :run => [:copy_resources, :build_tag_pages] do system "nanoc aco" end - task :rebuild => [:clear_output, :copy_files, :update] do + task :rebuild => [:clear_output, :update] do end - task :copy_files do + task :build_tag_pages do + site = Nanoc::Site.new(YAML.load_file('config.yaml')) + site.load_data + # TODO + # site.pages.each { |p| p.tags ...} + end + + task :copy_resources do pwd = Pathname.new Dir.pwd copy_f = lambda do |src| if src.file? then
A tasks/typo.rake

@@ -0,0 +1,119 @@

+require 'rubygems' +require 'extlib' +require 'pathname' +require 'fileutils' +begin + require 'mysql' + require 'sequel' +rescue Exception => e +end +require 'yaml' +require 'iconv' + +module TypoUtils + + def get_filter(db, fid) + filter = db[:text_filters].where("id = ?", fid).get(:name).downcase + # Multiple filters are not handled (e.g. markdown smartypants) + filter = filter.split(' ')[0] + # Prepare metadata + case filter + when 'textile' then + return ['redcloth'], 'textile' + when 'markdown' then + return ['bluecloth'], 'markdown' + when 'bbcode' then + return ['bbcode'], 'bbcode' + else + return [], 'txt' + end + end + + def get_tags(keywords=nil) + tags = [] + if keywords then + if keywords.match ',' then + tags = keywords.downcase.split(", ") + else + tags = keywords.downcase.split(" ") + end + end + tags + end + + def get_comments(db, aid) + dataset = db[:feedback].where("article_id = ? && state LIKE '%ham%'", aid) + comments = [] + dataset.each do |c| + comment = {} + comment[:id] = c[:id] + comment[:author] = c[:author] + comment[:body] = c[:body].to_s + comment[:url] = c[:url] + comment[:date] = c[:published_at] + comments << comment + end + comments + end + + def convert_code_blocks(meta, contents) + if contents.match /<typo:code/ then + # troubles if erb filter is enabled! + contents.gsub! /<%/, '&lt;%' + contents.gsub! /%>/, '%&gt;' + contents.gsub!(/<typo:code lang="([a-zA-Z0-9]+)">/, '<% highlight :\1 do %>') + contents.gsub!(/<typo:code>/, '<% highlight :text do %>') + contents.gsub!(/<\/typo:code>/, "<% end %>") + meta['filters_pre'] = ['erb'].concat meta['filters_pre'] + end + contents + end + + def write_page(meta, contents, extension) + path = (meta['type'] == 'article') ? Pathname.new(Dir.pwd)/"content/articles/" : Pathname.new(Dir.pwd)/"content/" + name = "#{meta['permalink']}.#{extension}" + path.mkpath + (path/name).open('w+') do |f| + f.print "--" + f.puts meta.to_yaml + f.puts "-----" + f.puts contents + end + end + +end + +include TypoUtils + +namespace :typo do + + task :migrate, :db, :usr, :pwd, :host do |t, args| + raise RuntimeError, "Please provide :db, :usr, :pass" unless args[:db] && args[:usr] && args[:pwd] + db = Sequel.mysql args[:db], :user => args[:usr], :password => args[:pwd], :host => args[:host] || 'localhost' + # Remove all existing pages! + dir = Pathname.new(Dir.pwd/'content') + dir.rmtree if dir.exist? + dir.mkpath + # Prepare page data + dataset = db[:contents].where("state = 'published' || type = 'Page'") + total = dataset.count + c = 1 + total_tags = [] + dataset.each do |a| + puts "Migrating [#{c}/#{total}]: '#{a[:title]}'..." + meta = {} + meta['tags'] = get_tags a[:keywords] + meta['comments'] = get_comments db, a[:id] + meta['permalink'] = a[:permalink] || a[:name] + meta['title'] = a[:title] + meta['type'] = a[:type].downcase + meta['date'] = a[:published_at] + meta['toc'] = true + meta['filters_pre'], extension = get_filter db, a[:text_filter_id] + contents = convert_code_blocks meta, a[:body]+a[:extended].to_s + write_page meta, contents, extension + c = c+1 + end + end + +end