$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) = @_;
$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 = <static/fullpics/$id-*>;
- 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 '/';
<meta charset="utf-8">
<link rel="stylesheet" href="/static/style.css">
<link rel="canonical" href="https://example.org">
-<title>Pictures of an item | ledparts4you</title>
+<title>Item | ledparts4you</title>
+
+<script id="jsonld" type="application/ld+json">
+</script>
<h1 id="title">ledparts4you</h1>
<div id="subtitle">Issues/Questions? Contact us at <a href="mailto:orders@ledparts4you.uk.to">orders@ledparts4you.uk.to</a></div>