From 48ae1bf456ca8dc3b55e55adfc752e4398779145 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Mon, 23 Sep 2024 10:33:19 +0200 Subject: [PATCH] Fix SEO links --- blog/site/_includes/head.html | 2 +- .../frontmatter/runtime/RoqCollection.java | 14 +++++--- .../frontmatter/runtime/RoqCollections.java | 34 ++++++++++++++++++- .../runtime/RoqTemplateExtension.java | 4 +-- .../main/resources/templates/tags/seo.html | 2 +- .../templates/tags/seoPaginator.html | 24 +++++++++---- .../resources/templates/tags/seoTitle.html | 7 ++-- 7 files changed, 70 insertions(+), 17 deletions(-) diff --git a/blog/site/_includes/head.html b/blog/site/_includes/head.html index d9397771..6cb1f922 100755 --- a/blog/site/_includes/head.html +++ b/blog/site/_includes/head.html @@ -1,7 +1,7 @@ - {#seo page site /} + {#seo page site collections /} diff --git a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollection.java b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollection.java index 3eb5ca54..f687ed6f 100644 --- a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollection.java +++ b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollection.java @@ -12,16 +12,22 @@ public RoqCollection(List pages) { .toList()); } - public Page findNext(Page page) { + public Page resolveNextPage(Page page) { + if (page.next() == null) { + return null; + } return this.get(page.next()); } - public Page findPrevious(Page page) { + public Page resolvePreviousPage(Page page) { + if (page.previous() == null) { + return null; + } return this.get(page.previous()); } - public Page findPrev(Page page) { - return this.findPrevious(page); + public Page resolvePrevPage(Page page) { + return this.resolvePreviousPage(page); } public List paginated(Paginator paginator) { diff --git a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollections.java b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollections.java index ad180c3a..48d27dbc 100644 --- a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollections.java +++ b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqCollections.java @@ -3,5 +3,37 @@ import java.util.Map; public record RoqCollections(Map collections) { + public RoqCollection get(String name) { + return collections.get(name); + } -} + public Page resolveNextPage(Page page) { + final RoqCollection collection = resolveCollection(page); + if (collection == null) + return null; + return collection.resolveNextPage(page); + } + + public Page resolvePreviousPage(Page page) { + final RoqCollection collection = resolveCollection(page); + if (collection == null) + return null; + return collection.resolvePreviousPage(page); + } + + public RoqCollection resolveCollection(Page page) { + if (page.collection() == null) { + return null; + } + final RoqCollection collection = this.get(page.collection()); + if (collection == null) { + return null; + } + return collection; + } + + public Page resolvePrevPage(Page page) { + return this.resolvePreviousPage(page); + } + +} \ No newline at end of file diff --git a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqTemplateExtension.java b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqTemplateExtension.java index ed8c853a..1c3338b4 100644 --- a/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqTemplateExtension.java +++ b/roq-frontmatter/runtime/src/main/java/io/quarkiverse/roq/frontmatter/runtime/RoqTemplateExtension.java @@ -30,8 +30,8 @@ public static Object data(Page page, String key) { } @TemplateExtension(matchName = "*") - public static RoqCollection data(RoqCollections collections, String key) { - return collections.collections().get(key); + public static RoqCollection collection(RoqCollections collections, String key) { + return collections.get(key); } public static Object readTime(Page page) { diff --git a/roq-frontmatter/runtime/src/main/resources/templates/tags/seo.html b/roq-frontmatter/runtime/src/main/resources/templates/tags/seo.html index 40a6fee3..48bee2a0 100644 --- a/roq-frontmatter/runtime/src/main/resources/templates/tags/seo.html +++ b/roq-frontmatter/runtime/src/main/resources/templates/tags/seo.html @@ -5,7 +5,7 @@ {#seoType page /} {#seoImage page site /} {#seoVerifications webmasterVerifications=site.webmasterVerifications /} -{#seoPaginator paginator=page.paginator /} +{#seoPaginator page collections /} {#seoFacebook facebook=site.facebook /} {#seoTwitter twitter=site.twitter /} {#seoLocale pageLocale=page.lang siteLocale=site.lang defaultLocale=global:locale /} diff --git a/roq-frontmatter/runtime/src/main/resources/templates/tags/seoPaginator.html b/roq-frontmatter/runtime/src/main/resources/templates/tags/seoPaginator.html index d86f923a..63116a92 100644 --- a/roq-frontmatter/runtime/src/main/resources/templates/tags/seoPaginator.html +++ b/roq-frontmatter/runtime/src/main/resources/templates/tags/seoPaginator.html @@ -1,9 +1,21 @@ -{#if paginator} +{#if page.paginator} - {#if paginator.previous} - + {#if page.paginator.previous} + {/if} - {#if paginator.next} - + {#if page.paginator.next} + {/if} -{/if} \ No newline at end of file +{#else} + + {#let prevPage = collections.resolvePreviousPage(page)} + {#if prevPage} + + {/if} + {/let} + {#let nextPage = collections.resolveNextPage(page) } + {#if nextPage} + + {/if} + {/let} +{/if} diff --git a/roq-frontmatter/runtime/src/main/resources/templates/tags/seoTitle.html b/roq-frontmatter/runtime/src/main/resources/templates/tags/seoTitle.html index 4a6b8bed..141ee19e 100644 --- a/roq-frontmatter/runtime/src/main/resources/templates/tags/seoTitle.html +++ b/roq-frontmatter/runtime/src/main/resources/templates/tags/seoTitle.html @@ -1,9 +1,12 @@ {#if pageTitle || siteTitle} + {#fragment title rendered=false} + {#if pageTitle && pageTitle ne siteTitle}{pageTitle} - {siteTitle}{#else}{siteTitle}{/if} + {/fragment} - {#if pageTitle ne siteTitle}{pageTitle} - {siteTitle}{#else}{siteTitle}{/if} + {#include $title /} - + {/if} {#if siteTitle}