summaryrefslogtreecommitdiff
path: root/lib.rb
blob: 3a94d396ed7e77bd0b691f7634ba0480581cc73a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env ruby

MEDIA_DIR = '/srv/media'
MEDIA_URL = 'https://media.pdp8.info'
WWW_DIR = '/srv/www/pdp8-test'
SNIPPETS = File.join(File.dirname(__FILE__), 'html')

def nav(cat)
  html = '<nav>'
  html += "<a id='logo' href='/about.html'><img src='/pdp8.png' alt='pdp8'></a>"
  %w[music pictures videos climbing code contact].each do |c|
    cl = c == cat ? 'item current' : 'item'
    html += "&nbsp;<a class='#{cl}' href='/#{c}.html'>#{c}</a>"
  end
  html += "&nbsp;<a class='item' href='/social/create.html'>social</a>"
  html += "&nbsp;<a class='item' href='/rss.xml'>rss</a>"
  html += "&nbsp;<a id='menu' href='#' onclick='show_vertical_menu()'>&equiv;</a>"
  html += '</nav>'
  html
end

def file_html(basename)
  path = File.join(SNIPPETS, basename + '.html')
  html = File.read(File.join(SNIPPETS, 'head.html'))
  html += nav basename
  html += "<div class='post'>"
  html += File.read(path)
  html += '</div>'
  html += File.read(File.join(SNIPPETS, 'tail.html'))
  print_html basename, html
end

def print_html(basename, html)
  out = File.join(WWW_DIR, basename + '.html')
  puts out
  File.open(out, 'w+') { |f| f.puts html }
  puts `tidy -iqm -w 0 #{out} 2>&1`
end