This is an automated email from the ASF dual-hosted git repository.

solomax pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openmeetings.git


The following commit(s) were added to refs/heads/master by this push:
     new 41f21a2fd no jira: index page for blog posts is added
41f21a2fd is described below

commit 41f21a2fdf69e9ba4a4391a2da33b2fe265e41e7
Author: Maxim Solodovnik <[email protected]>
AuthorDate: Mon Feb 6 13:18:32 2023 +0700

    no jira: index page for blog posts is added
---
 openmeetings-server/pom.xml                        |  51 ++++++++-
 .../openmeetings/util/site/BlogIndexGenerator.java | 115 +++++++++++++++++++++
 2 files changed, 162 insertions(+), 4 deletions(-)

diff --git a/openmeetings-server/pom.xml b/openmeetings-server/pom.xml
index 5bae89146..ff2ef6f7f 100644
--- a/openmeetings-server/pom.xml
+++ b/openmeetings-server/pom.xml
@@ -158,6 +158,12 @@
                                                <goals>
                                                        <goal>java</goal>
                                                </goals>
+                                               <configuration>
+                                                       
<mainClass>org.apache.openmeetings.backup.BackupExport</mainClass>
+                                                       <arguments>
+                                                               
<argument>${project.build.directory}/generated-sources/GeneralConfiguration.xml</argument>
+                                                       </arguments>
+                                               </configuration>
                                        </execution>
                                        <execution>
                                                
<id>generate-configs-xml-build</id>
@@ -165,6 +171,40 @@
                                                <goals>
                                                        <goal>java</goal>
                                                </goals>
+                                               <configuration>
+                                                       
<mainClass>org.apache.openmeetings.backup.BackupExport</mainClass>
+                                                       <arguments>
+                                                               
<argument>${project.build.directory}/generated-sources/GeneralConfiguration.xml</argument>
+                                                       </arguments>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>generate-blog-idx-site</id>
+                                               <phase>pre-site</phase>
+                                               <goals>
+                                                       <goal>java</goal>
+                                               </goals>
+                                               <configuration>
+                                                       
<mainClass>org.apache.openmeetings.util.site.BlogIndexGenerator</mainClass>
+                                                       <arguments>
+                                                               
<argument>${project.basedir}/src/site/markdown/blog</argument>
+                                                               
<argument>${project.build.directory}/generated-site/markdown/blog</argument>
+                                                       </arguments>
+                                               </configuration>
+                                       </execution>
+                                       <execution>
+                                               <id>generate-blog-idx-build</id>
+                                               <phase>generate-sources</phase>
+                                               <goals>
+                                                       <goal>java</goal>
+                                               </goals>
+                                               <configuration>
+                                                       
<mainClass>org.apache.openmeetings.util.site.BlogIndexGenerator</mainClass>
+                                                       <arguments>
+                                                               
<argument>${project.basedir}/src/site/markdown/blog</argument>
+                                                               
<argument>${project.build.directory}/generated-site/markdown/blog</argument>
+                                                       </arguments>
+                                               </configuration>
                                        </execution>
                                </executions>
                                <configuration>
@@ -172,10 +212,6 @@
                                        
<includeProjectDependencies>true</includeProjectDependencies>
                                        
<includePluginDependencies>true</includePluginDependencies>
                                        
<addOutputToClasspath>true</addOutputToClasspath>
-                                       
<mainClass>org.apache.openmeetings.backup.BackupExport</mainClass>
-                                       <arguments>
-                                               
<argument>${project.build.directory}/generated-sources/GeneralConfiguration.xml</argument>
-                                       </arguments>
                                </configuration>
                        </plugin>
                        <plugin>
@@ -388,9 +424,16 @@
                        <groupId>org.apache.openmeetings</groupId>
                        <artifactId>openmeetings-screenshare</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>org.apache.openmeetings</groupId>
+                       <artifactId>openmeetings-util</artifactId>
+                       <version>${project.version}</version>
+                       <scope>runtime</scope>
+               </dependency>
                <dependency>
                        <groupId>org.apache.openmeetings</groupId>
                        <artifactId>openmeetings-install</artifactId>
+                       <version>${project.version}</version>
                        <scope>runtime</scope>
                </dependency>
        </dependencies>
diff --git 
a/openmeetings-util/src/main/java/org/apache/openmeetings/util/site/BlogIndexGenerator.java
 
b/openmeetings-util/src/main/java/org/apache/openmeetings/util/site/BlogIndexGenerator.java
new file mode 100644
index 000000000..1f86ffb7f
--- /dev/null
+++ 
b/openmeetings-util/src/main/java/org/apache/openmeetings/util/site/BlogIndexGenerator.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") +  you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openmeetings.util.site;
+
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.List;
+import java.util.Objects;
+
+import org.apache.openmeetings.util.XmlExport;
+import org.apache.wicket.util.string.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class BlogIndexGenerator {
+       private static final Logger log = 
LoggerFactory.getLogger(BlogIndexGenerator.class);
+
+       private static record Link (String title, String link, LocalDateTime 
published) {
+               private static Link of(String title, String link, String 
published) {
+                       if (published == null) {
+                               return null;
+                       }
+                       return new Link(title, link, LocalDateTime.parse(
+                                       published.replace("'", "")
+                                       , 
DateTimeFormatter.ISO_OFFSET_DATE_TIME));
+               }
+
+               private boolean isValid() {
+                       boolean result = !Strings.isEmpty(title) && 
!Strings.isEmpty(link) && published != null;
+                       if (!result) {
+                               log.warn("Trying to add link with NULL values 
{}", this);
+                       }
+                       return result;
+               }
+       }
+
+       private static void addLink(StringBuilder sb, Link link) {
+               sb.append('[').append(link.title()).append("](")
+                               
.append("https://openmeetings.apache.org/blog/";).append(link.link()).append(".html)")
+                               .append(System.lineSeparator())
+                               .append(System.lineSeparator());
+       }
+
+       private static String getPrefixed(String line, String prefix) {
+               if (line.startsWith(prefix)) {
+                       return line.substring(prefix.length()).trim();
+               }
+               return null;
+       }
+
+       private static Link toLink(Path post) {
+               if (post.toFile().isDirectory()) {
+                       return null;
+               }
+               try {
+                       List<String> lines = Files.readAllLines(post);
+                       String title = lines.stream().map(line -> 
getPrefixed(line, "title:"))
+                                       
.filter(Objects::nonNull).findFirst().orElse(null);
+                       String link = lines.stream().map(line -> 
getPrefixed(line, "permalink:"))
+                                       
.filter(Objects::nonNull).findFirst().orElse(null);
+                       String published = lines.stream().map(line -> 
getPrefixed(line, "date:"))
+                                       
.filter(Objects::nonNull).findFirst().orElse(null);
+                       return Link.of(title, link, published);
+               } catch (IOException e) {
+                       log.error("Enexpected error", e);
+               }
+               return null;
+       }
+
+       /**
+        * Required during build `generate-blog-idx-*` goal
+        *
+        * @param args - [0] path to ${project.basedir}/src/site/markdown/blog 
folder
+        *               [1] path to 
${project.build.directory}/generated-site/markdown/blog folder
+        * @throws Exception - in case of any error
+        */
+       public static void main(String[] args) throws Exception {
+               StringBuilder sb = new StringBuilder();
+               
sb.append("<!--").append(XmlExport.LICENSE).append("-->").append(System.lineSeparator())
+                               .append("# Apache OpenMeetings blog 
posts").append(System.lineSeparator())
+                               .append(System.lineSeparator());
+               Files.walk(Paths.get(args[0])).map(BlogIndexGenerator::toLink)
+                               .filter(Objects::nonNull)
+                               .filter(Link::isValid)
+                               .sorted((link1, link2) -> 
link1.published().compareTo(link2.published()))
+                               .forEach(link -> addLink(sb, link));
+               Path outDir = Paths.get(args[1]);
+               Files.createDirectories(outDir);
+               Files.write(outDir.resolve("index.md")
+                               , sb.toString().getBytes(StandardCharsets.UTF_8)
+                               , StandardOpenOption.CREATE, 
StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING);
+       }
+}

Reply via email to