io.quarkiverse.roq.frontmatter.deployment.RoqFrontMatterProcessor Maven / Gradle / Ivy
package io.quarkiverse.roq.frontmatter.deployment;
import static io.quarkiverse.roq.util.PathUtils.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import io.quarkiverse.roq.frontmatter.deployment.scan.RoqFrontMatterRawTemplateBuildItem;
import io.quarkiverse.roq.frontmatter.deployment.scan.RoqFrontMatterStaticFileBuildItem;
import io.quarkiverse.roq.frontmatter.runtime.RoqFrontMatterMessages;
import io.quarkiverse.roq.frontmatter.runtime.RoqTemplateExtension;
import io.quarkiverse.roq.frontmatter.runtime.RoqTemplateGlobal;
import io.quarkiverse.roq.frontmatter.runtime.config.RoqSiteConfig;
import io.quarkiverse.roq.frontmatter.runtime.model.*;
import io.quarkiverse.roq.generator.deployment.items.SelectedPathBuildItem;
import io.quarkiverse.roq.util.PathUtils;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.qute.deployment.TemplatePathBuildItem;
import io.quarkus.qute.deployment.ValidationParserHookBuildItem;
import io.quarkus.vertx.http.deployment.devmode.NotFoundPageDisplayableEndpointBuildItem;
import io.quarkus.vertx.http.deployment.spi.GeneratedStaticResourceBuildItem;
public class RoqFrontMatterProcessor {
public static final String FEATURE = "roq-frontmatter";
@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
@BuildStep
void bindQuteTemplates(
BuildProducer templatePathProducer,
BuildProducer validationParserHookProducer,
List roqFrontMatterTemplates,
RoqFrontMatterOutputBuildItem roqOutput) {
if (roqOutput == null) {
return;
}
final Set docTemplates = new HashSet<>();
final Set pageTemplates = new HashSet<>();
final Set layoutTemplates = new HashSet<>();
// Produce generated Qute templates
for (RoqFrontMatterRawTemplateBuildItem item : roqFrontMatterTemplates) {
templatePathProducer
.produce(TemplatePathBuildItem.builder().path(item.info().generatedTemplatePath()).extensionInfo(FEATURE)
.content(item.generatedContent()).build());
if (item.published()) {
if (item.collection() != null) {
docTemplates.add(item.info().generatedTemplatePath());
} else {
pageTemplates.add(item.info().generatedTemplatePath());
}
} else {
layoutTemplates.add(item.info().generatedTemplatePath());
}
}
// Setup type-safety for generate templates
validationParserHookProducer.produce(new ValidationParserHookBuildItem(c -> {
if (docTemplates.contains(c.getTemplateId())) {
c.addParameter("page", DocumentPage.class.getName());
c.addParameter("site", Site.class.getName());
} else if (pageTemplates.contains(c.getTemplateId())) {
c.addParameter("page", NormalPage.class.getName());
c.addParameter("site", Site.class.getName());
} else if (layoutTemplates.contains(c.getTemplateId())) {
c.addParameter("page", Page.class.getName());
c.addParameter("site", Site.class.getName());
}
}));
}
@BuildStep
void registerAdditionalBeans(RoqFrontMatterOutputBuildItem roqOutput,
BuildProducer additionalBeans) {
if (roqOutput == null) {
return;
}
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClasses(
RoqFrontMatterMessages.class,
RoqTemplateExtension.class,
RoqTemplateGlobal.class,
Page.class,
RoqUrl.class,
RootUrl.class,
DocumentPage.class,
NormalPage.class,
RoqCollections.class,
RoqCollection.class,
Paginator.class)
.setUnremovable().build());
}
@BuildStep
void bindEndpoints(
RoqSiteConfig config,
BuildProducer selectedPathProducer,
BuildProducer notFoundPageDisplayableEndpointProducer,
RoqFrontMatterOutputBuildItem roqOutput) {
if (roqOutput == null) {
return;
}
// Bind Roq Generator and dev-ui endpoints
if (config.generator()) {
for (String path : roqOutput.allPagesByPath().keySet()) {
// If there is no extension, we add a trailing slash to make it detected as a html page (this is Roq Generator api)
final String selectedPath = getExtension(path) != null ? path : addTrailingSlash(path);
selectedPathProducer.produce(new SelectedPathBuildItem(selectedPath, null));
notFoundPageDisplayableEndpointProducer
.produce(new NotFoundPageDisplayableEndpointBuildItem(prefixWithSlash(path)));
}
}
}
@BuildStep
void bindStaticFiles(
RoqSiteConfig config,
List staticFiles,
BuildProducer staticResourcesProducer) {
for (RoqFrontMatterStaticFileBuildItem staticFile : staticFiles) {
staticResourcesProducer.produce(new GeneratedStaticResourceBuildItem(
PathUtils.join(config.rootPath(), staticFile.link()), staticFile.filePath()));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy