1717import org .jsoup .nodes .Element ;
1818import org .jsoup .nodes .TextNode ;
1919
20+ import java .io .File ;
2021import java .io .IOException ;
2122import java .nio .charset .StandardCharsets ;
2223import java .nio .file .Files ;
2324import java .nio .file .Path ;
2425import java .nio .file .Paths ;
2526import java .nio .file .StandardCopyOption ;
27+ import java .util .Arrays ;
28+ import java .util .Collection ;
29+ import java .util .HashSet ;
2630import java .util .LinkedHashSet ;
31+ import java .util .List ;
32+ import java .util .Set ;
2733import java .util .UUID ;
2834import java .util .stream .Collectors ;
2935
3036public 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 {
0 commit comments