Skip to content

Commit

Permalink
Add serie extension
Browse files Browse the repository at this point in the history
  • Loading branch information
jtama committed Dec 2, 2024
1 parent 680e2b3 commit 1d370fc
Show file tree
Hide file tree
Showing 22 changed files with 349 additions and 3 deletions.
1 change: 1 addition & 0 deletions blog/content/posts/2024-10-08-tagging.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ image: https://images.unsplash.com/photo-1523309375637-b3f4f2347f2d?q=80&w=3732&
description: We introduced the first Roq plugin, it is for collection tagging & with pagination support!
author: ia3andy
tags: plugin, frontmatter, guide, cool-stuff
serie: roq-plugins
---

My mind is getting blown by how much Quarkus was made for Static Site Generation. I just implemented a new plugin to generate tag pages and that was soooo easy.
Expand Down
1 change: 1 addition & 0 deletions blog/content/posts/2024-10-09-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: We introduced a way to declare aliases in FrontMatter. It is now ea
author: mcruzdev
tags: plugin, frontmatter, guide, cool-stuff
aliases: [aliases-very-cool, aliases-4-ever, aliases-again]
serie: roq-plugins
---

In the last post, we saw how easy it is to use Quarkus for static site generator (@ia3andy's was right!). I am excited to share that we now have a new plugin that allows you to set up redirects for your blog posts! For this post, I've created three aliases.
Expand Down
1 change: 1 addition & 0 deletions blog/content/posts/2024-10-22-asciidoc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ img: https://images.unsplash.com/photo-1455390582262-044cdead277a?q=80&w=3198&au
tags: plugin, frontmatter, guide, asciidoc
author: jtama
aliases: [asciidoc]
serie: roq-plugins
---

Writing content is AsciiDoc format is an absolut no brainer. Roq provides a plugin to handle it transparently for you.
Expand Down
1 change: 1 addition & 0 deletions blog/content/posts/2024-11-14-qrcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: Add a QR Code to your Roq website.
author: ia3andy
tags: qrcode, guide, cool-stuff
date: 2024-11-14 14:00:00 +0200
serie: roq-plugins
---

Need to add a scannable QR Code to your website? Whether it's for a restaurant menu, event ticket, or any other use case where you want to make your content easily accessible via mobile devices, the Roq QR Code plugin has you covered.
Expand Down
5 changes: 5 additions & 0 deletions blog/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@
<artifactId>quarkus-roq-plugin-asciidoc</artifactId>
<version>${quarkus-roq.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-serie</artifactId>
<version>${quarkus-roq.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-qrcode</artifactId>
Expand Down
3 changes: 2 additions & 1 deletion blog/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
%gh-pages.site.url=https://pages.quarkiverse.io/
%gh-pages.quarkus.http.root-path=/quarkus-roq/
quarkus.web-bundler.dependencies.auto-import=all
quarkus.log.category."io.quarkiverse.roq.frontmatter.deployment.scan".level=DEBUG
quarkus.log.category."io.quarkiverse.roq.frontmatter.deployment.scan".level=DEBUG
quarkus.default-locale=en
4 changes: 3 additions & 1 deletion blog/src/test/java/io/quarkiverse/roq/it/RoqBlogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.hamcrest.Matchers.containsString;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.response.ValidatableResponse;
import org.junit.jupiter.api.Test;

@QuarkusTest
Expand Down Expand Up @@ -33,10 +34,11 @@ public void testPosts() {

@Test
public void testPostsAsciidoc() {
given().when().get("/posts/write-your-blog-posts-in-asciidoc").then().statusCode(200).body(containsString(
ValidatableResponse body = given().when().get("/posts/write-your-blog-posts-in-asciidoc").then().statusCode(200).body(containsString(
"Writing content is AsciiDoc format is an absolut no brainer"))
.body(containsString("<pre class=\"highlightjs highlight\"><code class=\"language-shell hljs\" data-lang=\"shell\">quarkus extension add io.quarkiverse.roq:quarkus-roq-plugin-asciidoc</code></pre>"))
.body(containsString("2024 &copy; ROQ"));
System.out.println(body.extract().body().asString());
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion blog/templates/layouts/roq-default/post.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
layout: theme-layouts/roq-default/post
layout: roq-serie/post
---

{@io.quarkiverse.roq.frontmatter.runtime.model.DocumentPage page}
Expand Down
28 changes: 28 additions & 0 deletions docs/modules/ROOT/pages/quarkus-roq-plugins.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,31 @@ By default, the plugin produces HTML output compatible with both `HTML` and `Mar
{#qrcode value="https://luigis.com/menu/" alt="Luigi's Menu" foreground="#000066" background="#FFFFFF" width=300 height=300 asciidoc=true/} // Will save the file in the static folder and generate an asciidoc image macro pointing to it
----

[#plugin-serie]
== Roq Plugin Serie

This plugin allows you to join multiple posts in a serie.

To install it add:
[source,xml,subs=attributes+]
----
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-serie</artifactId>
<version>{project-version}</version>
</dependency>
----

Then add the `serie` attribute in the Front Matter of the posts you want to join.

[source,yaml]
----
---
layout: :theme/post
title: Assemble you blog post in a serie
description: Automatically serie header for your posts
tags: plugin, frontmatter, guide, serie
author: John Doe
serie: Serie Title
---
----
1 change: 1 addition & 0 deletions plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@
<module>markdown</module>
<module>asciidoc</module>
<module>qrcode</module>
<module>serie</module>
</modules>
</project>
59 changes: 59 additions & 0 deletions plugin/serie/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-serie-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-roq-plugin-serie-deployment</artifactId>
<name>Quarkus Roq - Plugin - Serie - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-frontmatter-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-serie</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package io.quarkiverse.roq.plugin.serie.deployment;

import static io.quarkus.deployment.annotations.ExecutionTime.STATIC_INIT;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import jakarta.inject.Singleton;

import io.quarkiverse.roq.frontmatter.deployment.RoqFrontMatterOutputBuildItem;
import io.quarkiverse.roq.frontmatter.deployment.scan.RoqFrontMatterRawTemplateBuildItem;
import io.quarkiverse.roq.plugin.series.runtime.SerieMessage;
import io.quarkiverse.roq.plugin.series.runtime.Series;
import io.quarkiverse.roq.plugin.series.runtime.SeriesRecorder;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;

public class RoqPluginSerieProcessor {

private static final String FEATURE = "roq-plugin-series";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void registerAdditionalBeans(RoqFrontMatterOutputBuildItem roqOutput,
BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
if (roqOutput == null) {
return;
}
additionalBeans.produce(AdditionalBeanBuildItem.builder()
.addBeanClasses(
SerieMessage.class)
.setUnremovable().build());
}

@BuildStep
@Record(value = STATIC_INIT)
void generateSeries(
SeriesRecorder recorder,
BuildProducer<SyntheticBeanBuildItem> beansProducer,
List<RoqFrontMatterRawTemplateBuildItem> templates) {
Map<String, List<String>> serieTemplates = templates.stream()
.filter(Predicate.not(RoqFrontMatterRawTemplateBuildItem::isLayout))
.filter(item -> item.data().containsKey("serie"))
.collect(Collectors.toMap(
item -> item.data().getString("serie"),
item -> new ArrayList<>(List.of(item.data().getString("title"))),
(a, b) -> {
a.addAll(b);
return a;
}));
if (serieTemplates.isEmpty()) {
return;
}
beansProducer.produce(SyntheticBeanBuildItem.configure(Series.class)
.named("series")
.scope(Singleton.class)
.unremovable()
.runtimeValue(recorder.generateSeries(serieTemplates))
.done());
}

}
22 changes: 22 additions & 0 deletions plugin/serie/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>quarkus-roq-plugin-serie-parent</artifactId>
<packaging>pom</packaging>
<name>Quarkus Roq - Plugin - Serie</name>

<properties>
<quarkus-barcode.version>0.0.3</quarkus-barcode.version>
</properties>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
53 changes: 53 additions & 0 deletions plugin/serie/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-plugin-serie-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<artifactId>quarkus-roq-plugin-serie</artifactId>
<name>Quarkus Roq - Plugin - Serie - Runtime</name>

<dependencies>
<dependency>
<groupId>io.quarkiverse.roq</groupId>
<artifactId>quarkus-roq-frontmatter</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
<version>${quarkus.version}</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>${project.groupId}:${project.artifactId}-deployment:${project.version}</deployment>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package io.quarkiverse.roq.plugin.series.runtime;

import io.quarkus.qute.i18n.Message;
import io.quarkus.qute.i18n.MessageBundle;

@MessageBundle(value = "serie", defaultKey = Message.UNDERSCORED_ELEMENT_NAME)
public interface SerieMessage {

@Message
String header(String serieName);

@Message
String navigate_to();

@Message
String select_post();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkiverse.roq.plugin.series.runtime;

import java.util.List;

import io.quarkiverse.roq.data.runtime.annotations.DataMapping;
import io.quarkiverse.roq.frontmatter.runtime.RoqTemplateExtension;

@DataMapping("series")
public record Series(List<Serie> series) {
public record Serie(String title, List<Entry> entries) {
public record Entry(String title) {
public String link() {
return "/posts/%s".formatted(RoqTemplateExtension.slugify(title));
}
}
}

public Serie findSerie(String title) {
return series.stream()
.filter(serie -> serie.title().equals(title))
.findFirst()
.orElse(null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkiverse.roq.plugin.series.runtime;

import java.util.List;
import java.util.Map;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class SeriesRecorder {
public RuntimeValue<Series> generateSeries(Map<String, List<String>> serieTemplates) {
return new RuntimeValue<>(
new Series(serieTemplates.entrySet().stream()
.map(entry -> new Series.Serie(entry.getKey(),
entry.getValue().stream().map(Series.Serie.Entry::new).toList()))
.toList()));
}
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
header=This post is part of the posts serie : {serieName}
navigate_to=Navigate to
select_post=Select a post
Loading

0 comments on commit 1d370fc

Please sign in to comment.