From a5f4e1ed470b96c1f97f3827fe07d530c53f0e5c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Tue, 3 Jan 2017 20:57:36 -0500 Subject: I hate URL handling. --- bin/index | 8 +++++++- bin/index.atom.erb | 7 +++---- bin/index.md.erb | 2 +- bin/page | 2 ++ bin/page.html.erb | 2 +- bin/util.rb | 22 ++++++++++++++-------- 6 files changed, 28 insertions(+), 15 deletions(-) (limited to 'bin') diff --git a/bin/index b/bin/index index 2443380..dc57798 100755 --- a/bin/index +++ b/bin/index @@ -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 @@ <%= @pages.map{|p|p.updated}.sort.last.rfc3339 %> <%= Person.new("Andrew Murrell").atom %> - https://lukeshu.com/blog/ + <%= $url %> <% @pages.sort_by{|p| p.updated}.reverse.each do |page| %> - - - https://andrewdm.me/<%= page.url %> + + <%= page.url %> <%= page.updated.rfc3339 %> <%= page.published.rfc3339 %> <%= page.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.title %><% a.tags.each do |t| %><%= t.html %><% end %><% end %> + * <%= a.title %><% a.tags.each do |t| %><%= t.html %><% end %><% end %> diff --git a/bin/page b/bin/page index ca8b5bd..1b631cf 100755 --- a/bin/page +++ b/bin/page @@ -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 @@ 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 "

This page is licensed under the #{license.html} license.

" 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("#{File.basename(u, File.extname(u))}") u = File.dirname(u) -- cgit v1.2.3