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 2021/05/03 14:44:53 UTC
[tomee-site-generator] 01/03: Add favicons for javadocs
This is an automated email from the ASF dual-hosted git repository.
dblevins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomee-site-generator.git
commit bea15354e5c0857e71dd20d458538ae9dba8a629
Author: David Blevins <da...@gmail.com>
AuthorDate: Sun Aug 9 20:12:28 2020 -0700
Add favicons for javadocs
---
.../java/org/apache/tomee/website/Javadocs.java | 70 +++++++++++++++++----
src/main/jbake/assets/img/jakarta-favicon.ico | Bin 0 -> 32988 bytes
src/main/jbake/assets/img/microprofile-favicon.png | Bin 0 -> 683 bytes
3 files changed, 57 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/apache/tomee/website/Javadocs.java b/src/main/java/org/apache/tomee/website/Javadocs.java
index 01226d8..33779f8 100644
--- a/src/main/java/org/apache/tomee/website/Javadocs.java
+++ b/src/main/java/org/apache/tomee/website/Javadocs.java
@@ -16,6 +16,7 @@
*/
package org.apache.tomee.website;
+import lombok.Data;
import org.apache.openejb.loader.Files;
import org.apache.openejb.loader.IO;
import org.apache.openejb.util.Join;
@@ -23,6 +24,7 @@ import org.apache.openejb.util.Pipe;
import java.io.File;
import java.io.IOException;
+import java.io.UncheckedIOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
@@ -122,6 +124,8 @@ public class Javadocs {
throw new IllegalStateException("Command failed");
}
+ final String favicon = getFavicon(source);
+
// Scrub generated timestamps as it causes 26k needless file updates
// on the svn commit for every time the generator runs
try {
@@ -129,31 +133,71 @@ public class Javadocs {
.map(Path::toFile)
.filter(File::isFile)
.filter(this::isHtml)
- .forEach(Javadocs::removeGeneratedDate);
+ .map(Content::from)
+ .map(Javadocs::removeGeneratedDate)
+ .map(content -> addFavicon(content, favicon))
+ .forEach(Content::write);
} catch (IOException e) {
- throw new IllegalStateException("Failed to remove timestamp from generated javadoc html");
+ throw new IllegalStateException("Failed to update generated javadoc html");
}
});
}
+ private String getFavicon(final Source source) {
+ if (source.getName().startsWith("jakarta")) {
+ return "/img/jakarta-favicon.ico";
+ } else if (source.getName().startsWith("microprofile")) {
+ return "/img/microprofile-favicon.png";
+ } else {
+ return "/favicon.png";
+ }
+ }
+
public List<JavadocSource> getJavadocSources() {
return javadocSources;
}
- public static void removeGeneratedDate(final File file) {
- try {
- final List<String> lines = Stream.of(IO.slurp(file).split("\n"))
- .filter(line -> !line.contains("<!-- Generated by javadoc"))
- .filter(line -> !line.contains("<meta name=\"date\" content=\""))
- .collect(Collectors.toList());
- final String updated = Join.join("\n", lines) + "\n";
+ private static Content removeGeneratedDate(final Content content) {
+ final List<String> lines = Stream.of(content.content.split("\n"))
+ .filter(line -> !line.contains("<!-- Generated by javadoc"))
+ .filter(line -> !line.contains("<meta name=\"date\" content=\""))
+ .collect(Collectors.toList());
- // Write the cleaned version to disk
- IO.copy(IO.read(updated), file);
+ final String updated = Join.join("\n", lines) + "\n";
- } catch (IOException e) {
- throw new IllegalStateException(e);
+ return content.modified(updated);
+ }
+
+ private static Content addFavicon(final Content content, final String favicon) {
+ final String link = String.format("%n<link rel=\"shortcut icon\" href=\"%s\">%n", favicon);
+ return content.modified(content.content.replace("</head>", link + "</head>"));
+ }
+
+ @Data
+ @lombok.AllArgsConstructor
+ private static class Content {
+ private final File file;
+ private final String content;
+
+ public Content modified(final String newContent) {
+ return new Content(file, newContent);
+ }
+
+ public void write() {
+ try {
+ IO.copy(IO.read(content), file);
+ } catch (IOException e) {
+ throw new UncheckedIOException("Unable to write file: " + file.getAbsolutePath(), e);
+ }
+ }
+
+ public static Content from(final File file) {
+ try {
+ return new Content(file, IO.slurp(file));
+ } catch (IOException e) {
+ throw new UncheckedIOException("Unable to read file: " + file.getAbsolutePath(), e);
+ }
}
}
diff --git a/src/main/jbake/assets/img/jakarta-favicon.ico b/src/main/jbake/assets/img/jakarta-favicon.ico
new file mode 100644
index 0000000..1557db1
Binary files /dev/null and b/src/main/jbake/assets/img/jakarta-favicon.ico differ
diff --git a/src/main/jbake/assets/img/microprofile-favicon.png b/src/main/jbake/assets/img/microprofile-favicon.png
new file mode 100644
index 0000000..0559671
Binary files /dev/null and b/src/main/jbake/assets/img/microprofile-favicon.png differ