Commit 95274096 authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

add opengraph metadata output

parent 362db912
Loading
Loading
Loading
Loading
+51 −27
Original line number Diff line number Diff line
@@ -84,12 +84,19 @@ sub user_status {
		image => $self->url_for('/static/icons/icon-512x512.png')
		  ->to_abs->scheme('https'),
	);
	my %og_data = (
		type      => 'article',
		image     => $tw_data{image},
		url       => $self->url_for("/status/${name}")->to_abs->scheme('https'),
		site_name => 'travelynx',
	);

	if ($journey) {
		$tw_data{title} = sprintf( 'Fahrt von %s nach %s',
		$og_data{title} = $tw_data{title} = sprintf( 'Fahrt von %s nach %s',
			$journey->{from_name}, $journey->{to_name} );
		$tw_data{description}
		$og_data{description} = $tw_data{description}
		  = $journey->{rt_arrival}->strftime('Ankunft am %d.%m.%Y um %H:%M');
		$og_data{url} .= "/${ts}";
	}
	elsif (
		$ts
@@ -97,12 +104,14 @@ sub user_status {
			or $status->{sched_departure}->epoch != $ts )
	  )
	{
		$tw_data{title}       = "Bahnfahrt beendet";
		$tw_data{description} = "${name} hat das Ziel erreicht";
		$og_data{title}       = $tw_data{title} = "Bahnfahrt beendet";
		$og_data{description} = $tw_data{description}
		  = "${name} hat das Ziel erreicht";
	}
	elsif ( $status->{checked_in} ) {
		$tw_data{title}       = "${name} ist unterwegs";
		$tw_data{description} = sprintf(
		$og_data{url} .= '/' . $status->{sched_departure}->epoch;
		$og_data{title}       = $tw_data{title}       = "${name} ist unterwegs";
		$og_data{description} = $tw_data{description} = sprintf(
			'%s %s von %s nach %s',
			$status->{train_type}, $status->{train_line} // $status->{train_no},
			$status->{dep_name},   $status->{arr_name}   // 'irgendwo'
@@ -110,11 +119,15 @@ sub user_status {
		if ( $status->{real_arrival}->epoch ) {
			$tw_data{description} .= $status->{real_arrival}
			  ->strftime(' – Ankunft gegen %H:%M Uhr');
			$og_data{description} .= $status->{real_arrival}
			  ->strftime(' – Ankunft gegen %H:%M Uhr');
		}
	}
	else {
		$tw_data{title}       = "${name} ist gerade nicht eingecheckt";
		$tw_data{description} = "Letztes Fahrtziel: $status->{arr_name}";
		$og_data{title} = $tw_data{title}
		  = "${name} ist gerade nicht eingecheckt";
		$og_data{description} = $tw_data{description}
		  = "Letztes Fahrtziel: $status->{arr_name}";
	}

	if ($journey) {
@@ -132,6 +145,7 @@ sub user_status {
			readonly  => 1,
			journey   => $journey,
			twitter   => \%tw_data,
			opengraph => \%og_data,
			%{$map_data},
		);
	}
@@ -142,6 +156,7 @@ sub user_status {
			public_level => $user->{public_level},
			journey      => $status,
			twitter      => \%tw_data,
			opengraph    => \%og_data,
		);
	}
}
@@ -236,21 +251,29 @@ sub public_journey_details {
		}

		if ($journey) {
			my $title = sprintf( 'Fahrt von %s nach %s am %s',
				$journey->{from_name}, $journey->{to_name},
				$journey->{rt_arrival}->strftime('%d.%m.%Y') );
			my $description = sprintf( 'Ankunft mit %s %s %s',
				$journey->{type}, $journey->{no},
				$journey->{rt_arrival}->strftime('um %H:%M') );
			my %tw_data = (
				card  => 'summary',
				site  => '@derfnull',
				image => $self->url_for('/static/icons/icon-512x512.png')
				  ->to_abs->scheme('https'),
				title       => $title,
				description => $description,
			);
			my %og_data = (
				type        => 'article',
				image       => $tw_data{image},
				url         => $self->url_for->to_abs,
				site_name   => 'travelynx',
				title       => $title,
				description => $description,
			);

			if ($journey) {
				$tw_data{title} = sprintf( 'Fahrt von %s nach %s am %s',
					$journey->{from_name}, $journey->{to_name},
					$journey->{rt_arrival}->strftime('%d.%m.%Y') );
				$tw_data{description} = sprintf( 'Ankunft mit %s %s %s',
					$journey->{type}, $journey->{no},
					$journey->{rt_arrival}->strftime('um %H:%M') );
			}
			my $map_data = $self->journeys_to_map_data(
				journeys       => [$journey],
				include_manual => 1,
@@ -268,6 +291,7 @@ sub public_journey_details {
				username  => $name,
				readonly  => 1,
				twitter   => \%tw_data,
				opengraph => \%og_data,
				%{$map_data},
			);
		}
+3 −0
Original line number Diff line number Diff line
@@ -10,6 +10,9 @@
	% while (my ($key, $value) = each %{stash('twitter') // {}}) {
		<meta name="twitter:<%= $key %>" content="<%= $value %>">
	% }
	% while (my ($key, $value) = each %{stash('opengraph') // {}}) {
		<meta property="og:<%= $key %>" content="<%= $value %>">
	% }
	% my $av = 'v34'; # asset version
	<link rel="icon" type="image/png" href="/static/<%= $av %>/icons/icon-16x16.png" sizes="16x16">
	<link rel="icon" type="image/png" href="/static/<%= $av %>/icons/icon-32x32.png" sizes="32x32">