From: Marius Gavrilescu Date: Tue, 3 May 2016 16:08:58 +0000 (+0100) Subject: Add Schema.org product markup and change title of details pages X-Git-Tag: 0.000_006~2 X-Git-Url: http://git.ieval.ro/?a=commitdiff_plain;h=8bb7ab90a1720dcc48a016aff68cfcdfddf6f49d;p=app-web-oof.git Add Schema.org product markup and change title of details pages --- diff --git a/lib/App/Web/Oof.pm b/lib/App/Web/Oof.pm index dffaaa5..fa256a6 100644 --- a/lib/App/Web/Oof.pm +++ b/lib/App/Web/Oof.pm @@ -62,6 +62,25 @@ sub make_slug { $slug } +sub product_to_schemaorg { + my ($include_url, %data) = @_; + my $stock = $data{stock} > 0 ? 'InStock' : 'OutOfStock'; + +{ + '@context' => 'http://schema.org/', + '@type' => 'Product', + name => $data{title}, + image => "/static/fullpics/$data{product}-1.jpg", + description => $data{summary}, + offers => { + '@type' => 'Offer', + price => ($data{price} =~ s/(..)$/\.$1/r), + priceCurrency => 'GBP', + availability => "http://schema.org/$stock", + ($include_url ? (url => "/details/$data{product}/" . make_slug $data{title}) : ()) + } + } +} + our %highlight; sub form_table_row { my ($data, $tr) = @_; @@ -230,14 +249,15 @@ sub details_app { $db{$$} //= DBIx::Simple->connect($ENV{OOF_DSN} // 'dbi:Pg:'); my $tree = $details->clone; my ($id) = $env->{PATH_INFO} =~ m,^/(\d+),; - my ($title, $summary) = $db{$$}->select(products => [qw/title summary/], {product => $id})->list; + my %data = %{$db{$$}->select(products => '*', {product => $id})->hash}; my @pics = ; - my $slug = make_slug $title; - $tree->find('title')->replace_content("Pictures of $title | ledparts4you"); - $tree->find('h2')->replace_content($title); - $tree->fid('summary')->replace_content($summary); + my $slug = make_slug $data{title}; + $tree->find('title')->replace_content("$data{title} | ledparts4you"); + $tree->find('h2')->replace_content($data{title}); + $tree->fid('summary')->replace_content($data{summary}); $tree->look_down(rel => 'canonical')->attr(href => "/details/$id/$slug"); $tree->fid('pictures')->find('li')->iter3(\@pics, \&details_list_element); + $tree->fid('jsonld')->replace_content(encode_json product_to_schemaorg '', %data); for my $ahref ($tree->find('a')) { $ahref->attr(href => "/form?highlight=$id") if $ahref->attr('href') eq '/'; diff --git a/tmpl/details.html b/tmpl/details.html index ec99046..aa9b4cd 100644 --- a/tmpl/details.html +++ b/tmpl/details.html @@ -2,7 +2,10 @@ -Pictures of an item | ledparts4you +Item | ledparts4you + +

ledparts4you

Issues/Questions? Contact us at orders@ledparts4you.uk.to