Skip to content

Commit

Permalink
Allow templating in aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed Oct 9, 2024
1 parent 66a4a7a commit 5d6f4e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docs/modules/ROOT/pages/quarkus-roq-plugins.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ aliases: [first-roq-article-ever]
---
----

Now, when you access the URL `http://localhost:8081/first-roq-article-ever`, you will be redirected to the `2024-08-29-welcome-to-roq` blog post.
Now, when you access the URL `http://localhost:8081/first-roq-article-ever`, you will be redirected to the `2024-08-29-welcome-to-roq` blog post.

NOTE: you can use link templating in aliases
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@
import java.util.Map;
import java.util.Set;

import io.quarkiverse.roq.frontmatter.deployment.Link;
import io.quarkiverse.roq.frontmatter.deployment.data.RoqFrontMatterTemplateBuildItem;
import io.quarkiverse.roq.frontmatter.runtime.RoqSiteConfig;
import io.quarkiverse.roq.frontmatter.runtime.model.RoqUrl;
import io.quarkiverse.roq.generator.deployment.items.SelectedPathBuildItem;
import io.quarkiverse.roq.plugin.aliases.deployment.items.RoqFrontMatterAliasesBuildItem;
import io.quarkiverse.roq.plugin.aliases.runtime.RoqFrontMatterAliasesRecorder;
import io.quarkiverse.roq.util.PathUtils;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.vertx.http.deployment.HttpRootPathBuildItem;
import io.quarkus.vertx.http.deployment.RouteBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
import io.vertx.core.json.JsonArray;
Expand All @@ -33,7 +35,9 @@ FeatureBuildItem feature() {
}

@BuildStep
public void consumeTemplates(List<RoqFrontMatterTemplateBuildItem> templates,
public void consumeTemplates(
RoqSiteConfig config,
List<RoqFrontMatterTemplateBuildItem> templates,
BuildProducer<RoqFrontMatterAliasesBuildItem> aliasesProducer,
BuildProducer<SelectedPathBuildItem> selectedPathsProducer,
BuildProducer<NotFoundPageDisplayableEndpointBuildItem> notFoundPageDisplayableEndpointProducer) {
Expand All @@ -55,7 +59,9 @@ public void consumeTemplates(List<RoqFrontMatterTemplateBuildItem> templates,
}
RoqUrl url = item.url();
for (String alias : aliasesName) {
aliasMap.put(alias, url.path());
String aliasLink = Link.pageLink(config.rootPath(), alias, new Link.PageLinkData(
item.raw().info().baseFileName(), item.raw().info().date(), item.raw().collection(), item.data()));
aliasMap.put(aliasLink, url.path());
}
}

Expand All @@ -71,12 +77,14 @@ public void consumeTemplates(List<RoqFrontMatterTemplateBuildItem> templates,

@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
public void createVertxRedirects(RoqFrontMatterAliasesRecorder recorder,
public void createVertxRedirects(
HttpRootPathBuildItem httpRootPath,
RoqFrontMatterAliasesRecorder recorder,
BuildProducer<RouteBuildItem> routes,
List<RoqFrontMatterAliasesBuildItem> aliases) {
for (RoqFrontMatterAliasesBuildItem item : aliases) {
routes.produce(RouteBuildItem.builder()
.route(PathUtils.prefixWithSlash(item.alias()))
.route(httpRootPath.relativePath(item.alias()))
.handler(recorder.addRedirect(item.target()))
.build());
}
Expand Down

0 comments on commit 5d6f4e0

Please sign in to comment.