feat(*): refactor metadata handling; move metadata to backend where possible, refine client views
This commit is contained in:
parent
929bc9f9f8
commit
9687509e4a
35 changed files with 506 additions and 339 deletions
|
@ -11,18 +11,18 @@
|
|||
|
||||
if (strpos($url, "music/artists/") !== 0) redirectTo404();
|
||||
|
||||
$artist = (new ArtistFetcher())->fetch($url);
|
||||
$fetcher = new ArtistFetcher();
|
||||
$artist = $fetcher->fetch($url);
|
||||
|
||||
if (!$artist) redirectTo404();
|
||||
|
||||
$artist["description"] = parseMarkdown($artist["description"]);
|
||||
$pageTitle = htmlspecialchars("Artists • " . $artist["name"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(htmlspecialchars(strip_tags($artist["description"]), ENT_QUOTES, "UTF-8"), 250);
|
||||
$ogImage = htmlspecialchars($artist["metadata"]["open_graph_image"], ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
$artist["description_html"] = parseMarkdown($artist["description"]);
|
||||
$artist["globals"] = $fetcher->getGlobals();
|
||||
$page = $artist;
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,18 +11,19 @@
|
|||
|
||||
if (!preg_match('/^reading\/books\/([\dXx-]+)$/', $url)) redirectTo404();
|
||||
|
||||
$book = (new BookFetcher())->fetch($url);
|
||||
$fetcher = new BookFetcher();
|
||||
$book = $fetcher->fetch($url);
|
||||
|
||||
if (!$book) redirectTo404();
|
||||
|
||||
$book["description"] = parseMarkdown($book["description"]);
|
||||
$pageTitle = htmlspecialchars("Books • {$book["title"]} by {$book["author"]}", ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(htmlspecialchars(strip_tags($book["description"]), ENT_QUOTES, "UTF-8"), 250);
|
||||
$ogImage = htmlspecialchars($book["metadata"]["open_graph_image"], ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
$book["description_html"] = parseMarkdown($book["description"]);
|
||||
$book["globals"] = $fetcher->getGlobals();
|
||||
$page = $book;
|
||||
$globals = $page["globals"];
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
if (!preg_match('/^music\/genres\/[\w-]+$/', $url)) redirectTo404();
|
||||
|
||||
$genre = (new GenreFetcher())->fetch($url);
|
||||
$fetcher = new GenreFetcher();
|
||||
$genre = $fetcher->fetch($url);
|
||||
|
||||
if (!$genre) redirectTo404();
|
||||
|
||||
$pageTitle = htmlspecialchars("Genres • " . $genre["name"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(
|
||||
htmlspecialchars(strip_tags($genre["description"]), ENT_QUOTES, "UTF-8"),
|
||||
250
|
||||
);
|
||||
$ogImage = htmlspecialchars($genre["metadata"]["open_graph_image"] ?? "", ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
$genre["globals"] = $fetcher->getGlobals();
|
||||
$page = $genre;
|
||||
$globals = $page["globals"];
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,18 +11,19 @@
|
|||
|
||||
if (!preg_match('/^watching\/movies\/[\w-]+$/', $url)) redirectTo404();
|
||||
|
||||
$movie = (new MovieFetcher())->fetch($url);
|
||||
$fetcher = new MovieFetcher();
|
||||
$movie = $fetcher->fetch($url);
|
||||
|
||||
if (!$movie) redirectTo404();
|
||||
|
||||
$movie["description"] = parseMarkdown($movie["description"]);
|
||||
$pageTitle = htmlspecialchars("Movies • " . $movie["title"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(htmlspecialchars(strip_tags($movie["description"]), ENT_QUOTES, "UTF-8"), 250);
|
||||
$ogImage = htmlspecialchars($movie["metadata"]["open_graph_image"], ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
$movie["description_html"] = parseMarkdown($movie["description"]);
|
||||
$movie["globals"] = $fetcher->getGlobals();
|
||||
$page = $movie;
|
||||
$globals = $page["globals"];
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -11,20 +11,19 @@
|
|||
|
||||
if (!preg_match('/^watching\/shows\/[\w-]+$/', $url)) redirectTo404();
|
||||
|
||||
$show = (new ShowFetcher())->fetch($url);
|
||||
$fetcher = new ShowFetcher();
|
||||
$show = $fetcher->fetch($url);
|
||||
|
||||
if (!$show) redirectTo404();
|
||||
|
||||
$pageTitle = htmlspecialchars("Show • " . $show["title"], ENT_QUOTES, "UTF-8");
|
||||
$pageDescription = truncateText(
|
||||
htmlspecialchars(strip_tags($show["description"]), ENT_QUOTES, "UTF-8"),
|
||||
250
|
||||
);
|
||||
$ogImage = htmlspecialchars($show["metadata"]["open_graph_image"], ENT_QUOTES, "UTF-8");
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
$show["description_html"] = parseMarkdown($show["description"]);
|
||||
$show["globals"] = $fetcher->getGlobals();
|
||||
$page = $show;
|
||||
$globals = $page["globals"];
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
require __DIR__ . "/../server/utils/init.php";
|
||||
|
||||
use App\Classes\TagFetcher;
|
||||
use App\Classes\GlobalsFetcher;
|
||||
use voku\helper\HtmlMin;
|
||||
|
||||
$requestUri = $_SERVER["REQUEST_URI"];
|
||||
|
@ -25,9 +26,10 @@
|
|||
|
||||
if (!preg_match('/^[\p{L}\p{N} _\.\-\&]+$/u', $tag)) redirectTo404();
|
||||
|
||||
$page = isset($matches[2]) ? max(1, (int)$matches[2]) : 1;
|
||||
$pageNum = isset($matches[2]) ? max(1, (int)$matches[2]) : 1;
|
||||
$pageSize = 20;
|
||||
$tagged = (new TagFetcher())->fetch($tag, $page, $pageSize);
|
||||
$fetcher = new TagFetcher();
|
||||
$tagged = $fetcher->fetch($tag, $pageNum, $pageSize);
|
||||
|
||||
if (!$tagged || count($tagged) === 0) {
|
||||
header("Location: /404/", true, 302);
|
||||
|
@ -37,21 +39,32 @@
|
|||
$totalCount = $tagged[0]['total_count'] ?? 0;
|
||||
$totalPages = max(ceil($totalCount / $pageSize), 1);
|
||||
$pagination = [
|
||||
'pageNumber' => $page,
|
||||
'pageNumber' => $pageNum,
|
||||
'pages' => range(1, $totalPages),
|
||||
'href' => [
|
||||
'previous' => $page > 1 ? "/tags/{$tag}/" . ($page - 1) : null,
|
||||
'next' => $page < $totalPages ? "/tags/{$tag}/" . ($page + 1) : null
|
||||
'previous' => $pageNum > 1 ? "/tags/{$tag}/" . ($pageNum - 1) : null,
|
||||
'next' => $pageNum < $totalPages ? "/tags/{$tag}/" . ($pageNum + 1) : null
|
||||
],
|
||||
'links' => range(1, $totalPages)
|
||||
];
|
||||
$globals = (new GlobalsFetcher())->fetch();
|
||||
$page = [
|
||||
'tag' => $tag,
|
||||
'items' => $tagged,
|
||||
'pagination' => $pagination,
|
||||
'metadata' => [
|
||||
'title' => '#' . ucfirst($tag) . ' • ' . $globals['site_name'],
|
||||
'description' => 'All content tagged with #' . ucfirst($tag) . '.',
|
||||
'open_graph_image' => $globals['metadata']['open_graph_image'],
|
||||
'url' => $globals['url'] . $requestUri,
|
||||
'type' => 'tag'
|
||||
],
|
||||
'globals' => $globals
|
||||
];
|
||||
|
||||
$pageTitle = "#" . strtolower(ucfirst($tag));
|
||||
$pageDescription = "All content tagged with #" . strtolower(ucfirst($tag)) . ".";
|
||||
$fullUrl = "https://www.coryd.dev" . $requestUri;
|
||||
$oembedUrl = "https://www.coryd.dev/oembed" . $requestUri;
|
||||
|
||||
extract(setupPageMetadata($page, $requestUri));
|
||||
ob_start();
|
||||
header("Cache-Control: public, max-age=3600");
|
||||
header("Expires: " . gmdate("D, d M Y H:i:s", time() + 3600) . " GMT");
|
||||
|
||||
?>
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<title><?= cleanMeta($pageTitle ?? "{{ pageTitle }}") ?> • {{ globals.site_name }}</title>
|
||||
<meta name="description" content="<?= cleanMeta($pageDescription ?? '{{ pageDescription | escape }}') ?>" />
|
||||
<meta property="og:title" content="<?= cleanMeta($pageTitle ?? '{{ pageTitle }}') ?> • {{ globals.site_name }}" />
|
||||
<meta property="og:description" content="<?= cleanMeta($pageDescription ?? '{{ pageDescription | escape }}') ?>" />
|
||||
<meta property="og:image" content="{{ globals.url }}<?= cleanMeta("/og/w800/{% appVersion %}" . ($ogImage ?? '{{ ogImage }}')) ?>" />
|
||||
<meta property="og:url" content="<?= cleanMeta($fullUrl ?? '{{ fullUrl }}') ?>" />
|
||||
<link rel="alternate" type="application/json+oembed" href="<?= cleanMeta($oembedUrl ?? '{{ oembedUrl }}') ?>" title="<?= cleanMeta($pageTitle ?? '{{ pageTitle }}') ?> • {{ globals.site_name }}">
|
||||
<link rel="canonical" href="<?= cleanMeta($fullUrl ?? '{{ fullUrl }}') ?>" />
|
||||
<title><?= cleanMeta($page['metadata']['title']) ?></title>
|
||||
<meta name="description" content="<?= cleanMeta($page['metadata']['description']) ?>" />
|
||||
<meta property="og:title" content="<?= cleanMeta($page['metadata']['title']) ?>" />
|
||||
<meta property="og:description" content="<?= cleanMeta($page['metadata']['description']) ?>" />
|
||||
<meta property="og:image" content="<?= cleanMeta($globals['url'] . '/og/w800' . $page['metadata']['open_graph_image']) ?>" />
|
||||
<meta property="og:url" content="<?= cleanMeta($page['metadata']['url'] ?? $fullUrl) ?>" />
|
||||
<link rel="alternate" type="application/json+oembed" href="<?= cleanMeta($oembedUrl) ?>" title="<?= cleanMeta($page['metadata']['title']) ?>">
|
||||
<link rel="canonical" href="<?= cleanMeta($page['metadata']['url'] ?? $fullUrl) ?>" />
|
||||
<?php if (!empty($pagination)): ?>
|
||||
<?php if (!empty($pagination['href']['next'])): ?>
|
||||
<link rel="next" href="<?= cleanMeta($pagination['href']['next']) ?>">
|
||||
|
|
|
@ -1,103 +1,63 @@
|
|||
{%- assign fullUrl = globals.url | append: page.url -%}
|
||||
{%- assign oembedUrl = globals.url | append: "/oembed" | append: page.url -%}
|
||||
{%- capture appVersionString -%}{% appVersion %}{%- endcapture -%}
|
||||
{%- assign ogImageBaseUrl = globals.url | append: "/og/w800/" | append: appVersionString -%}
|
||||
{%- capture pageTitle -%}
|
||||
{%- if page.title -%}
|
||||
{{ page.title | append: ' • ' | append: globals.site_name }}
|
||||
{%- elsif title -%}
|
||||
{{ title | append: ' • ' | append: globals.site_name }}
|
||||
{%- else -%}
|
||||
{{ globals.site_name }}
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
{%- capture pageDescription -%}
|
||||
{%- if page.description -%}
|
||||
{{ page.description }}
|
||||
{%- elsif description -%}
|
||||
{{ description }}
|
||||
{%- else -%}
|
||||
{{ globals.site_description }}
|
||||
{%- endif -%}
|
||||
{%- endcapture -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: globals.metadata.open_graph_image -%}
|
||||
{%- assign source = page -%}
|
||||
{%- case schema -%}
|
||||
{%- when 'artist' -%}
|
||||
{% render "fetchers/artist.php.liquid" %}
|
||||
{%- when 'genre' -%}
|
||||
{% render "fetchers/genre.php.liquid" %}
|
||||
{%- when 'book' -%}
|
||||
{% render "fetchers/book.php.liquid" %}
|
||||
{%- when 'movie' -%}
|
||||
{% render "fetchers/movie.php.liquid" %}
|
||||
{%- when 'show' -%}
|
||||
{% render "fetchers/show.php.liquid" %}
|
||||
{%- when 'tags' -%}
|
||||
{% render "fetchers/tags.php.liquid" %}
|
||||
{%- when 'artist', 'genre', 'book', 'movie', 'show', 'tags' -%}
|
||||
{% render "fetchers/{{ schema }}.php.liquid" %}
|
||||
{%- when 'blog' -%}
|
||||
{%- assign pageTitle = post.title -%}
|
||||
{%- assign pageDescription = post.description -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: post.metadata.open_graph_image -%}
|
||||
{%- assign source = post -%}
|
||||
{%- when 'music-index', 'music-week-artists' -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: music.week.artists[0].metadata.open_graph_image -%}
|
||||
{%- assign source = music.week.artists[0] -%}
|
||||
{%- when 'music-week-albums', 'music-week-tracks' -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: music.week.albums[0].metadata.open_graph_image -%}
|
||||
{%- assign source = music.week.albums[0] -%}
|
||||
{%- when 'music-month-artists' -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: music.month.artists[0].metadata.open_graph_image -%}
|
||||
{%- assign source = music.month.artists[0] -%}
|
||||
{%- when 'music-month-albums' -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: music.month.albums[0].metadata.open_graph_image -%}
|
||||
{%- assign source = music.month.albums[0] -%}
|
||||
{%- when 'music-releases' -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: albumReleases.upcoming[0].metadata.open_graph_image -%}
|
||||
{%- assign source = albumReleases.upcoming[0] -%}
|
||||
{%- when 'books' -%}
|
||||
{%- assign overviewBook = books.all | filterBooksByStatus: 'started' | reverse | first %}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: overviewBook.metadata.open_graph_image -%}
|
||||
{%- assign source = books.all | filterBooksByStatus: 'started' | reverse | first -%}
|
||||
{%- when 'reading-year' -%}
|
||||
{%- assign pageTitle = 'Books' | append: ' • ' | append: year.value | append: ' • ' | append: globals.site_name -%}
|
||||
{%- capture pageDescription -%}
|
||||
Here's what I read in {{ year.value }}.
|
||||
{%- endcapture -%}
|
||||
{%- assign bookData = year.data | filterBooksByStatus: 'finished' -%}
|
||||
{%- assign bookYear = bookData | shuffleArray | first -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: bookYear.metadata.open_graph_image -%}
|
||||
{%- assign title = 'Books • ' | append: year.value | append: ' • ' | append: globals.site_name -%}
|
||||
{%- assign description = "Here's what I read in " | append: year.value | append: '.' -%}
|
||||
{%- assign bookYear = year.data | filterBooksByStatus: 'finished' | shuffleArray | first -%}
|
||||
{%- assign source = bookYear -%}
|
||||
{%- when 'favorite-movies' -%}
|
||||
{%- assign favoriteMovie = movies.favorites | shuffleArray | first %}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: favoriteMovie.metadata.open_graph_image -%}
|
||||
{%- assign source = movies.favorites | shuffleArray | first -%}
|
||||
{%- when 'favorite-shows' -%}
|
||||
{%- assign favoriteShow = tv.favorites | shuffleArray | first %}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: favoriteShow.metadata.open_graph_image -%}
|
||||
{%- assign source = tv.favorites | shuffleArray | first -%}
|
||||
{%- when 'watching' -%}
|
||||
{%- assign mergedMovies = movies.recentlyWatched | mergeArray: movies.favorites %}
|
||||
{%- assign mergedShows = tv.recentlyWatched | mergeArray: tv.favorites %}
|
||||
{%- assign overviewWatched = mergedMovies | mergeArray: mergedShows | shuffleArray | first -%}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: overviewWatched.metadata.open_graph_image -%}
|
||||
{%- assign mergedMovies = movies.recentlyWatched | mergeArray: movies.favorites -%}
|
||||
{%- assign mergedShows = tv.recentlyWatched | mergeArray: tv.favorites -%}
|
||||
{%- assign source = mergedMovies | mergeArray: mergedShows | shuffleArray | first -%}
|
||||
{%- when 'upcoming-shows' -%}
|
||||
{%- assign upcomingShow = upcomingShows.watching | shuffleArray | first %}
|
||||
{%- assign ogImage = ogImageBaseUrl | append: upcomingShow.metadata.open_graph_image -%}
|
||||
{%- when 'page' -%}
|
||||
{%- assign pageDescription = page.description -%}
|
||||
{% endcase %}
|
||||
{%- assign source = upcomingShows.watching | shuffleArray | first -%}
|
||||
{%- endcase %}
|
||||
{%- assign meta = source | getMetadata: globals, page, title, description, schema -%}
|
||||
{%- assign fullUrl = meta.url -%}
|
||||
{%- assign oembedUrl = globals.url | append: "/oembed" | append: page.url -%}
|
||||
{%- if type == 'dynamic' -%}
|
||||
{% render "metadata/dynamic.php.liquid"
|
||||
fullUrl:fullUrl,
|
||||
oembedUrl:oembedUrl,
|
||||
pageTitle:pageTitle,
|
||||
pageDescription:pageDescription,
|
||||
ogImage:globals.metadata.open_graph_image,
|
||||
globals:globals,
|
||||
%}
|
||||
{% render "metadata/dynamic.php.liquid"
|
||||
fullUrl: fullUrl,
|
||||
oembedUrl: oembedUrl,
|
||||
pageTitle: meta.title,
|
||||
pageDescription: meta.description,
|
||||
ogImage: meta.open_graph_image,
|
||||
globals: globals,
|
||||
%}
|
||||
{%- else -%}
|
||||
{% render "metadata/static.liquid"
|
||||
fullUrl:fullUrl,
|
||||
oembedUrl:oembedUrl,
|
||||
pageTitle:pageTitle,
|
||||
pageDescription:pageDescription,
|
||||
ogImage:ogImage,
|
||||
globals:globals,
|
||||
%}
|
||||
{%- endif -%}
|
||||
{% render "metadata/static.liquid"
|
||||
fullUrl: fullUrl,
|
||||
oembedUrl: oembedUrl,
|
||||
pageTitle: meta.title,
|
||||
pageDescription: meta.description,
|
||||
ogImage: meta.open_graph_image,
|
||||
globals: globals,
|
||||
%}
|
||||
{%- endif %}
|
||||
{% render "metadata/base.liquid"
|
||||
pageTitle:pageTitle,
|
||||
globals:globals,
|
||||
eleventy:eleventy,
|
||||
appVersion:appVersion,
|
||||
pageTitle: meta.title,
|
||||
globals: globals,
|
||||
eleventy: eleventy,
|
||||
appVersion: appVersion,
|
||||
%}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
{%- assign description = pageDescription | markdown | strip_html | htmlTruncate | escape -%}
|
||||
<title>{{ pageTitle }}</title>
|
||||
<meta name="description" content="{{ pageDescription | markdown | strip_html | htmlTruncate | escape }}" />
|
||||
<meta property="og:title" content="{{ pageTitle }}" />
|
||||
<meta name="description" content="{{ description }}" />
|
||||
<meta property="og:description" content="{{ description }}" />
|
||||
<meta property="og:type" content="article" />
|
||||
<meta property="og:description" content="{{ pageDescription | markdown | strip_html | htmlTruncate | escape }}" />
|
||||
<meta property="og:type" content="{{ page.metadata.type | default: 'article' }}" />
|
||||
<meta property="og:url" content="{{ fullUrl }}" />
|
||||
<link rel="alternate" type="application/json+oembed" href="{{ oembedUrl }}" title="{{ pageTitle }}">
|
||||
<link rel="canonical" href="{{ fullUrl }}" />
|
||||
<meta property="og:image" content="{{ ogImage }}" />
|
||||
<link rel="alternate" type="application/json+oembed" href="{{ oembedUrl }}" title="{{ pageTitle }}" />
|
||||
<link rel="canonical" href="{{ fullUrl }}" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue