Skip to content

Commit ed10212

Browse files
committed
Add 1.x site
1 parent 7968e35 commit ed10212

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
out
22
target
33
site
4+
v1

docs/src/main/java/io/jooby/adoc/DocApp.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static void main(String[] args) throws Exception {
3333

3434
log.info("waiting for doc");
3535

36-
DocGenerator.generate(basedir, false);
36+
DocGenerator.generate(basedir, false, Arrays.asList(args).contains("v1"));
3737

3838
log.info("doc ready");
3939

@@ -46,7 +46,7 @@ public static void main(String[] args) throws Exception {
4646
Path file = event.path();
4747
if (file.toString().endsWith(".adoc")) {
4848
try {
49-
DocGenerator.generate(basedir, false);
49+
DocGenerator.generate(basedir, false, false);
5050

5151
log.info("doc ready");
5252
} catch (Exception x) {

docs/src/main/java/io/jooby/adoc/DocGenerator.java

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,29 @@
1717
import org.jsoup.nodes.Element;
1818
import org.jsoup.nodes.TextNode;
1919

20+
import java.io.File;
2021
import java.io.IOException;
2122
import java.nio.charset.StandardCharsets;
2223
import java.nio.file.Files;
2324
import java.nio.file.Path;
2425
import java.nio.file.Paths;
2526
import java.nio.file.StandardCopyOption;
27+
import java.util.Arrays;
28+
import java.util.Collection;
29+
import java.util.HashSet;
2630
import java.util.LinkedHashSet;
31+
import java.util.List;
32+
import java.util.Set;
2733
import java.util.UUID;
2834
import java.util.stream.Collectors;
2935

3036
public class DocGenerator {
3137
public static void main(String[] args) throws Exception {
32-
generate(basedir(), args.length > 0 && "publish".equals(args[0]));
38+
List<String> options = Arrays.asList(args);
39+
generate(basedir(), options.contains("publish"), options.contains("v1"));
3340
}
3441

35-
public static void generate(Path basedir, boolean publish) throws Exception {
42+
public static void generate(Path basedir, boolean publish, boolean v1) throws Exception {
3643
String version = version();
3744

3845
Path asciidoc = basedir.resolve("asciidoc");
@@ -70,9 +77,13 @@ public static void generate(Path basedir, boolean publish) throws Exception {
7077
}));
7178

7279
// LICENSE
73-
Files.copy(basedir.getParent().resolve("LICENSE"),outdir.resolve("LICENSE.txt"),
80+
Files.copy(basedir.getParent().resolve("LICENSE"), outdir.resolve("LICENSE.txt"),
7481
StandardCopyOption.REPLACE_EXISTING);
7582

83+
if (v1) {
84+
v1doc(basedir, outdir);
85+
}
86+
7687
if (publish) {
7788
Path website = basedir.resolve("target")// Paths.get(System.getProperty("java.io.tmpdir"))
7889
.resolve(Long.toHexString(UUID.randomUUID().getMostSignificantBits()));
@@ -90,6 +101,35 @@ public static void generate(Path basedir, boolean publish) throws Exception {
90101
}
91102
}
92103

104+
private static void v1doc(Path basedir, Path output) throws Exception {
105+
Path v1source = basedir.resolve("v1");
106+
if (!Files.exists(v1source)) {
107+
Files.createDirectories(v1source);
108+
109+
Git git = new Git("jooby-project", "jooby", v1source);
110+
git.clone("--single-branch", "--branch", "gh-pages");
111+
}
112+
Path v1target = output.resolve("v1");
113+
FileUtils.copyDirectory(v1source.toFile(), v1target.toFile());
114+
115+
Collection<File> files = FileUtils.listFiles(v1target.toFile(), new String[]{"html"}, true);
116+
for (File index : files) {
117+
String content = FileUtils.readFileToString(index, "UTF-8")
118+
.replace("http://jooby.org", "https://jooby.org")
119+
.replace("href=\"/resources", "href=\"/v1/resources")
120+
.replace("src=\"/resources", "src=\"/v1/resources");
121+
Document doc = Jsoup.parse(content);
122+
doc.select("a").forEach(a -> {
123+
String href = a.attr("href");
124+
if (!href.startsWith("http") && !href.startsWith("#")) {
125+
href = "/v1" + href;
126+
a.attr("href", href);
127+
}
128+
});
129+
FileUtils.writeStringToFile(index, doc.toString(), "UTF-8");
130+
}
131+
}
132+
93133
private static void processModule(Asciidoctor asciidoctor, Path basedir, Path module, Path outdir,
94134
String version) {
95135
try {

docs/src/main/java/io/jooby/adoc/Git.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515

1616
public class Git {
1717

18+
private final String branch;
19+
1820
private String repo;
1921

2022
private Path dir;
2123

22-
public Git(final String owner, final String project, final Path dir) {
24+
public Git(final String owner, final String project, final String branch, final Path dir) {
2325
this.repo = "[email protected]:" + owner + "/" + project + ".git";
2426
this.dir = dir;
27+
this.branch = branch;
28+
}
29+
30+
public Git(final String owner, final String project, final Path dir) {
31+
this(owner, project, "master", dir);
2532
}
2633

2734
public void clone(final String... args) throws Exception {
@@ -39,7 +46,7 @@ public void clone(final String... args) throws Exception {
3946
public void commit(String comment) throws Exception {
4047
execute(Arrays.asList("git", "add", "."));
4148
execute(Arrays.asList("git", "commit", "-m", "'" + comment + "'"));
42-
execute(Arrays.asList("git", "push", "origin", "master"));
49+
execute(Arrays.asList("git", "push", "origin", branch));
4350
}
4451

4552
private void execute(final List<String> args) throws Exception {

0 commit comments

Comments
 (0)