You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2018/11/30 22:27:05 UTC

[21/34] tomee-site-generator git commit: Link documentation to new (work in progress) docs index

Link documentation to new (work in progress) docs index


Project: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/commit/a9b50301
Tree: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/tree/a9b50301
Diff: http://git-wip-us.apache.org/repos/asf/tomee-site-generator/diff/a9b50301

Branch: refs/heads/master
Commit: a9b50301eab3460c8d69698c395accecf2e25a14
Parents: efed31f
Author: dblevins <da...@gmail.com>
Authored: Mon Nov 26 01:04:27 2018 -0800
Committer: dblevins <da...@gmail.com>
Committed: Mon Nov 26 01:04:27 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/tomee/website/Docs.java     | 91 ++++++++++++++++++++
 .../java/org/apache/tomee/website/JBake.java    |  8 +-
 .../java/org/apache/tomee/website/Sources.java  | 18 ++--
 .../org/apache/tomee/website/VersionIndex.java  | 67 ++++++++++++++
 .../org/apache/tomee/website/VersionsIndex.java | 70 +++++++++++++++
 src/main/jbake/templates/menu.gsp               |  1 -
 6 files changed, 245 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/java/org/apache/tomee/website/Docs.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Docs.java b/src/main/java/org/apache/tomee/website/Docs.java
index 500cf3a..547837a 100644
--- a/src/main/java/org/apache/tomee/website/Docs.java
+++ b/src/main/java/org/apache/tomee/website/Docs.java
@@ -17,9 +17,15 @@
 package org.apache.tomee.website;
 
 import org.apache.openejb.loader.IO;
+import org.apache.openejb.util.Join;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 public class Docs {
 
@@ -40,5 +46,90 @@ public class Docs {
         } catch (IOException e) {
             throw new RuntimeException(e);
         }
+
+        if (!hasIndex(destDocs)) {
+            buildIndex(destDocs);
+        }
+    }
+
+    private boolean hasIndex(final File destDocs) {
+        return Stream.of(destDocs.listFiles())
+                .filter(File::isFile)
+                .filter(file -> file.getName().startsWith("index."))
+                .filter(this::isRendered)
+                .findFirst().isPresent();
+    }
+
+    private void buildIndex(final File destDocs) {
+        try {
+            final List<String> links = Files.walk(destDocs.toPath())
+                    .filter(path -> path.toFile().isFile())
+                    .filter(this::isRendered)
+                    .map(path -> toLink(destDocs, path))
+                    .map(Link::toAdoc)
+                    .collect(Collectors.toList());
+
+            final StringBuilder index = new StringBuilder();
+            index.append(":jbake-type: page\n")
+                    .append(":jbake-status: published\n")
+                    .append(":jbake-title: Documentation\n")
+                    .append("\n")
+                    .append("Documentation\n\n")
+            ;
+
+            index.append(Join.join("\n", links));
+
+            IO.copy(IO.read(index.toString()), new File(destDocs, "index.adoc"));
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private Link toLink(final File base, final Path path) {
+        final int baseLength = base.getAbsolutePath().length() + 1;
+
+        final String href = path.toFile().getAbsolutePath().substring(baseLength)
+                .replace(".adoc", ".html")
+                .replace(".mdtext", ".html")
+                .replace(".md", ".html");
+
+        final String name = href.replace(".html", "");
+        return new Link(href, name);
+    }
+
+    public static class Link {
+        private final String href;
+        private final String name;
+
+        public Link(final String href, final String name) {
+            this.href = href;
+            this.name = name;
+        }
+
+        public String getHref() {
+            return href;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public String toAdoc() {
+            return " - link:" + href + "[" + name + "]";
+        }
+    }
+
+    private boolean isRendered(final Path path) {
+        final File file = path.toFile();
+        return isRendered(file);
+    }
+
+    private boolean isRendered(final File file) {
+        if (file.getName().endsWith(".mdtext")) return true;
+        if (file.getName().endsWith(".md")) return true;
+        if (file.getName().endsWith(".adoc")) return true;
+        if (file.getName().endsWith(".html")) return true;
+        return false;
     }
 }

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/java/org/apache/tomee/website/JBake.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/JBake.java b/src/main/java/org/apache/tomee/website/JBake.java
index e2e2ea9..20bbbd0 100755
--- a/src/main/java/org/apache/tomee/website/JBake.java
+++ b/src/main/java/org/apache/tomee/website/JBake.java
@@ -42,10 +42,10 @@ public class JBake {
                 new File("target/jbake"),
                 new File("repos"),
                 new File("src/main/jbake"),
-                new Source("https://git-wip-us.apache.org/repos/asf/tomee.git", "master", "master"),
+                new Source("https://github.com/dblevins/tomee.git", "tomee-8.0.x-docs", "tomee-8.0", true),
                 new Source("https://git-wip-us.apache.org/repos/asf/tomee.git", "tomee-7.1.0", "tomee-7.1"),
                 new Source("https://git-wip-us.apache.org/repos/asf/tomee.git", "tomee-7.0.5", "tomee-7.0"),
-                new Source("https://git-wip-us.apache.org/repos/asf/tomee.git", "tomee-8.0.0-M1", "tomee-8.0", true)
+                new Source("https://git-wip-us.apache.org/repos/asf/tomee.git", "master", "master")
         );
 
         sources.prepare();
@@ -200,11 +200,11 @@ public class JBake {
         final File fileLayoutPdf = new File(adminFolder, "file-layout.pdf");
         final File dirStructurePdf = new File(adminFolder, "directory-structure.pdf");
 
-        if(fileLayoutPdf.exists()){
+        if (fileLayoutPdf.exists()) {
             FileUtils.copyFile(fileLayoutPdf, dirStructurePdf);
         }
 
-        if(fileLayoutHtml.exists()){
+        if (fileLayoutHtml.exists()) {
             FileUtils.copyFile(fileLayoutHtml, dirStructureHtml);
         }
     }

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/java/org/apache/tomee/website/Sources.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/Sources.java b/src/main/java/org/apache/tomee/website/Sources.java
index c8592a4..3af5ca4 100644
--- a/src/main/java/org/apache/tomee/website/Sources.java
+++ b/src/main/java/org/apache/tomee/website/Sources.java
@@ -64,6 +64,10 @@ public class Sources {
         return destination;
     }
 
+    public List<Source> getSources() {
+        return sources;
+    }
+
     /**
      * This is the heart of the code to merge several documentation
      * sources into one tree.
@@ -71,20 +75,24 @@ public class Sources {
     public void prepare() {
         final Docs docs = new Docs(this);
         final Examples2 examples = new Examples2(this);
+        final VersionIndex versionIndex = new VersionIndex(this);
+
+        try {
+            IO.copyDirectory(mainSource, destination);
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
 
         sources.stream()
                 .peek(source -> source.setDir(new File(repos, source.getName())))
                 .peek(Repos::download)
                 .peek(docs::prepare)
                 .peek(examples::prepare)
+                .peek(versionIndex::prepare)
                 .forEach(Sources::done);
         ;
 
-        try {
-            IO.copyDirectory(mainSource, destination);
-        } catch (IOException e) {
-            throw new RuntimeException(e);
-        }
+        VersionsIndex.prepare(this);
     }
 
     public File getDestinationFor(final Source source, final String... parts) {

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/java/org/apache/tomee/website/VersionIndex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/VersionIndex.java b/src/main/java/org/apache/tomee/website/VersionIndex.java
new file mode 100644
index 0000000..68960aa
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/VersionIndex.java
@@ -0,0 +1,67 @@
+/*
+ * 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.tomee.website;
+
+import org.apache.openejb.loader.IO;
+import org.apache.openejb.util.Join;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+public class VersionIndex {
+
+    private final Sources sources;
+
+    public VersionIndex(final Sources sources) {
+        this.sources = sources;
+    }
+
+    public void prepare(final Source source) {
+        final File docs = sources.getDestinationFor(source, "docs");
+        final File examples = sources.getDestinationFor(source, "examples");
+
+        try {
+            final StringBuilder index = new StringBuilder();
+            index.append(":jbake-type: page\n")
+                    .append(":jbake-status: published\n")
+                    .append(":jbake-title: ")
+                    .append(source.getName())
+                    .append(" resources")
+                    .append("\n")
+                    .append("\n")
+            ;
+
+            if (docs.exists()) {
+                index.append(" - link:docs[Documentation]\n");
+            }
+            if (examples.exists()) {
+                index.append(" - link:examples[Examples]\n");
+            }
+
+            IO.copy(IO.read(index.toString()), new File(docs.getParentFile(), "index.adoc"));
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/java/org/apache/tomee/website/VersionsIndex.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/tomee/website/VersionsIndex.java b/src/main/java/org/apache/tomee/website/VersionsIndex.java
new file mode 100644
index 0000000..d44def4
--- /dev/null
+++ b/src/main/java/org/apache/tomee/website/VersionsIndex.java
@@ -0,0 +1,70 @@
+/*
+ * 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.tomee.website;
+
+import org.apache.openejb.loader.IO;
+
+import java.io.File;
+import java.io.IOException;
+
+public class VersionsIndex {
+
+
+    public static void prepare(final Sources sources) {
+
+
+        try {
+            final StringBuilder index = new StringBuilder();
+            index.append(":jbake-type: page\n")
+                    .append(":jbake-status: published\n")
+                    .append(":jbake-title: Apache TomEE Documentation\n")
+                    .append("\n")
+            ;
+
+
+            for (final Source source : sources.getSources()) {
+                if ("master".equals(source.getName())) continue;
+                if ("latest".equals(source.getName())) continue;
+
+                index.append("*").append(source.getName());
+                if (source.isLatest()) {
+                    index.append(" (latest)");
+                }
+
+                index.append("*\n\n");
+
+                final File docs = sources.getDestinationFor(source, "docs");
+                final File examples = sources.getDestinationFor(source, "examples");
+
+                if (docs.exists()) {
+                    index.append(" - link:").append(source.getName()).append("/docs[Documentation]\n");
+                }
+                if (examples.exists()) {
+                    index.append(" - link:").append(source.getName()).append("/examples[Examples]\n");
+                }
+                index.append("\n\n");
+            }
+
+            IO.copy(IO.read(index.toString()), new File(sources.getDestination(), "content/documentation.adoc"));
+            IO.copy(IO.read(index.toString()), new File(sources.getDestination(), "content/docs.adoc"));
+
+        } catch (IOException e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/tomee-site-generator/blob/a9b50301/src/main/jbake/templates/menu.gsp
----------------------------------------------------------------------
diff --git a/src/main/jbake/templates/menu.gsp b/src/main/jbake/templates/menu.gsp
index d4c46c7..d84aceb 100755
--- a/src/main/jbake/templates/menu.gsp
+++ b/src/main/jbake/templates/menu.gsp
@@ -27,7 +27,6 @@
 			<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
 				<ul class="nav navbar-nav navbar-right main-nav">
 					<li><a href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>docs.html">Documentation</a></li>
-					<li><a href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>examples/index.html">Examples</a></li>
 					<li><a href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>community/index.html">Community</a></li>
 					<li><a href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>security/index.html">Security</a></li>
 					<li><a href="<%if (content.rootpath) {%>${content.rootpath}<% } else { %><% }%>download-ng.html">Downloads</a></li>