Permalink
Browse files

if there's no TITLE tag (Yes Glasgow we are looking at you) then look…

… for the first H1 or use Untitled
  • Loading branch information...
1 parent 7a42cbe commit 98fbab990f29dc075cff756d5bd252df0d6d69d7 @stefl committed Jun 9, 2010
Showing with 12 additions and 7 deletions.
  1. +5 −5 app.rb
  2. +7 −2 lib/diy.rb
View
@@ -144,16 +144,16 @@ class CostSavingExercise < Sinatra::Base
get "/:council_slug/page" do |council_slug|
@council = DIY::Council.from_slug(council_slug)
- begin
+ #begin
@page = @council.get_page(params[:url])
@page.load_title
@page_title = "#{@page.title}"
STDERR.puts @page.inspect
haml :page
- rescue
- @page_title = "Sorry, that page isn't available currently"
- haml :sorry
- end
+ #rescue
+ # @page_title = "Sorry, that page isn't available currently"
+ # haml :sorry
+ #end
end
get "/:council_slug/on/:keyword" do |council_slug,keyword|
View
@@ -345,8 +345,13 @@ def title
end
def load_title
- doc = Nokogiri::HTML(Weary.get(self.url).perform_sleepily.body)
- @title = @data["title"] = DIY.titleize(doc.at_css("title").text, self.council)
+ doc = Nokogiri::HTML(Weary.get(self.url).perform_sleepily.body)
+ STDERR.puts "Got :#{doc.inspect}"
+ STDERR.puts "Title: #{doc.at_css('h1')}"
+
+ @title = DIY.titleize(doc.at_css("title").text, self.council) rescue @title = nil
+ @title ||= (doc.at_css("h1").text) rescue @title = "Untitled"
+ @data["title"] = @title
end
def url

0 comments on commit 98fbab9

Please sign in to comment.