diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-03 20:57:36 -0500 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2017-01-03 20:57:36 -0500 |
commit | a5f4e1ed470b96c1f97f3827fe07d530c53f0e5c (patch) | |
tree | c4ab7430b9c2f54e9ab3ac10f62f0321af6578de /bin | |
parent | 5449dca686d7bdbd5f09acd4e9fd8647535acde9 (diff) |
I hate URL handling.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/index | 8 | ||||
-rw-r--r-- | bin/index.atom.erb | 7 | ||||
-rw-r--r-- | bin/index.md.erb | 2 | ||||
-rwxr-xr-x | bin/page | 2 | ||||
-rw-r--r-- | bin/page.html.erb | 2 | ||||
-rw-r--r-- | bin/util.rb | 22 |
6 files changed, 28 insertions, 15 deletions
@@ -4,12 +4,18 @@ load 'util.rb' require 'yaml' # ARGV[0] -template = "bin/index.#{ARGV.shift}.erb" +type = ARGV.shift +template = "bin/index.#{type}.erb" erb = ERB.new(File.read(template)); erb.filename = template # ARGV[1] @path = ARGV.shift +webpath = (@path+'/').sub(/^(src|out)\//, '/') +if type == 'atom' + webpath += 'index.atom' +end +@url = URI::parse('https://www.andrewdm.me') + webpath indexyaml = @path.sub('out', 'src')+'/index.yaml' if File.exists?(indexyaml) diff --git a/bin/index.atom.erb b/bin/index.atom.erb index 1afbf8c..c02f709 100644 --- a/bin/index.atom.erb +++ b/bin/index.atom.erb @@ -7,13 +7,12 @@ <link rel="alternate" type="text/markdown" href="./index.md"/> <updated><%= @pages.map{|p|p.updated}.sort.last.rfc3339 %></updated> <author><%= Person.new("Andrew Murrell").atom %></author> - <id>https://lukeshu.com/blog/</id> + <id><%= $url %></id> <% @pages.sort_by{|p| p.updated}.reverse.each do |page| %> <entry xmlns="http://www.w3.org/2005/Atom"> - <link rel="alternate" type="text/html" href="<%= page.url %>.html"/> - <link rel="alternate" type="text/markdown" href="<%= page.url %>.md"/> - <id>https://andrewdm.me/<%= page.url %></id> + <link rel="alternate" type="text/html" href="<%= page.url %>"/> + <id><%= page.url %></id> <updated><%= page.updated.rfc3339 %></updated> <published><%= page.published.rfc3339 %></published> <title><%= page.title %></title> diff --git a/bin/index.md.erb b/bin/index.md.erb index ce5e030..34f8677 100644 --- a/bin/index.md.erb +++ b/bin/index.md.erb @@ -4,4 +4,4 @@ class: "index" --- <% @pages.sort_by{|a|a.published}.reverse.each do |a| %> - * <a href="<%= a.url %>" title="Published on <%= a.published.strftime('%Y-%m-%d') %><% if a.updated != a.published %> (updated on<%= a.updated.strftime('%Y-%m-%d') %>)<% end %>"><%= a.title %></a><span><% a.tags.each do |t| %><%= t.html %><% end %></span><% end %> + * <a href="<%= @url.route_to(a.url) %>" title="Published on <%= a.published.strftime('%Y-%m-%d') %><% if a.updated != a.published %> (updated on<%= a.updated.strftime('%Y-%m-%d') %>)<% end %>"><%= a.title %></a><span><% a.tags.each do |t| %><%= t.html %><% end %></span><% end %> @@ -1,9 +1,11 @@ #!/usr/bin/env ruby # -*- coding: utf-8 -*- load 'util.rb' +require 'uri' template = "bin/page.#{ARGV[0]}.erb" @page = Page.new(ARGV[1]) +@url = URI::parse('https://www.andrewdm.me') + @page.absoutpath erb = ERB.new(File.read(template)); erb.filename = template diff --git a/bin/page.html.erb b/bin/page.html.erb index 354b123..49be4e8 100644 --- a/bin/page.html.erb +++ b/bin/page.html.erb @@ -30,7 +30,7 @@ </article> <footer> <%= @page.rights %> - <p>Page source: <a href="<%= File.basename(@page.src) %>"><%= File.basename(@page.src) %></a></p> + <p>Page source: <a href="<%= @url.route_to(@page.srcurl) %>"><%= File.basename(@page.srcurl.to_s) %></a></p> <p>Website source: <a href="https://git.andrewdm.me/www.git">www.git</a></p> </footer> </body> diff --git a/bin/util.rb b/bin/util.rb index 05808b7..2cfc63e 100644 --- a/bin/util.rb +++ b/bin/util.rb @@ -3,6 +3,7 @@ load 'pandoc.rb' require 'erb' require 'date' require 'set' +require 'uri' $license_urls = { "CC BY-SA-3.0" => 'https://creativecommons.org/licenses/by-sa/3.0/', @@ -26,6 +27,8 @@ $tag_names = { "WP" => "WIP", } +$url = URI::parse('https://www.andrewdm.me') + class Tag def initialize(abbr) @abbr = abbr @@ -178,22 +181,25 @@ class Page "<p>This page is licensed under the #{license.html} license.</p>" end - def src - @src ||= infile.sub(/^(src|out)\//, '/') + def abssrcpath + @srcpath ||= infile.sub(/^(src|out)\//, '/') + end + def absoutpath + @outpath ||= abssrcpath.sub(/\.[^\/.]*$/, '.html').sub(/\/index[.]html$/, '') end def url - if @url.nil? - u = src.sub(/\.[^\/.]*$/, '.html').sub(/\/index[.]html$/, '') - @url = u == '' ? '/' : u - end - @url + @url ||= $url + absoutpath + end + def srcurl + @srcurl ||= $url + abssrcpath end def breadcrumbs if @breadcrumbs.nil? bc = [] - u = url + u = url.path + u = "/" if u == "" while u != "/" bc.unshift("<a href=\"#{u}\">#{File.basename(u, File.extname(u))}</a>") u = File.dirname(u) |