]> source.dussan.org Git - gitblit.git/commitdiff
Indicate current page on documentation.
authorJames Moger <james.moger@gitblit.com>
Sun, 9 Oct 2011 13:53:13 +0000 (09:53 -0400)
committerJames Moger <james.moger@gitblit.com>
Sun, 9 Oct 2011 13:53:13 +0000 (09:53 -0400)
build.xml
resources/bootstrap.gb.css
src/com/gitblit/build/BuildSite.java

index 9a589711dbe91da6c5a230bbee574a1805a22856..99c6e2e11a2ee41edbb0375b9c8846860cae4425 100644 (file)
--- a/build.xml
+++ b/build.xml
                                        <include name="book_16x16.png" />\r
                                        <include name="blank.png" />\r
                                        <include name="federated_16x16.png" />\r
+                                       <include name="arrow_page.png" />\r
                                </fileset>\r
 \r
                                <!-- Copy Doc images -->\r
                                <include name="book_16x16.png" />\r
                                <include name="blank.png" />\r
                                <include name="federated_16x16.png" />\r
+                               <include name="arrow_page.png" />\r
                        </fileset>\r
 \r
                        <!-- Copy Doc images -->\r
index 6ff047b113f82e5d351adbea93bf1dbfbe865a97..aa6c4095db4597fe731a6cb30e135cfd25900960 100644 (file)
@@ -52,6 +52,10 @@ hr {
        background-position: center bottom;\r
 }\r
 \r
+.topbar .active a {\r
+       background-color: transparent !important;\r
+}\r
+\r
 .breadcrumb {\r
        margin-top: 5px !important;\r
        margin-bottom: 5px !important;\r
index 0746a6b7a11e77483aa8e1848a47945b3ddbe530..efff5a34d0b04e5892ef4ae5b7f961250aa2898f 100644 (file)
@@ -56,7 +56,7 @@ import com.gitblit.utils.StringUtils;
 public class BuildSite {\r
 \r
        private static final String SPACE_DELIMITED = "SPACE-DELIMITED";\r
-       \r
+\r
        private static final String CASE_SENSITIVE = "CASE-SENSITIVE";\r
 \r
        private static final String RESTART_REQUIRED = "RESTART REQUIRED";\r
@@ -91,24 +91,6 @@ public class BuildSite {
 \r
                System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",\r
                                markdownFiles.length, sourceFolder.getAbsolutePath()));\r
-               String linkPattern = "<li><a href=''{0}''>{1}</a></li>";\r
-               StringBuilder sb = new StringBuilder();\r
-               for (File file : markdownFiles) {\r
-                       String documentName = getDocumentName(file);\r
-                       if (!params.skips.contains(documentName)) {\r
-                               String displayName = documentName;\r
-                               if (aliasMap.containsKey(documentName)) {\r
-                                       displayName = aliasMap.get(documentName);\r
-                               } else {\r
-                                       displayName = displayName.replace('_', ' ');\r
-                               }\r
-                               String fileName = documentName + ".html";\r
-                               sb.append(MessageFormat.format(linkPattern, fileName, displayName));\r
-                               sb.append(" | ");\r
-                       }\r
-               }\r
-               sb.setLength(sb.length() - 3);\r
-               sb.trimToSize();\r
 \r
                String htmlHeader = FileUtils.readContent(new File(params.pageHeader), "\n");\r
 \r
@@ -120,105 +102,105 @@ public class BuildSite {
                        }\r
                }\r
                String htmlFooter = FileUtils.readContent(new File(params.pageFooter), "\n");\r
-               String links = sb.toString();\r
-               String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);\r
-               if (!StringUtils.isEmpty(params.analyticsSnippet)) {\r
-                       File snippet = new File(params.analyticsSnippet);\r
-                       if (snippet.exists()) {\r
-                               String htmlSnippet = FileUtils.readContent(snippet, "\n");\r
-                               header = header.replace("<!-- ANALYTICS -->", htmlSnippet);\r
-                       }\r
-               }\r
                final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());\r
                final String footer = MessageFormat.format(htmlFooter, "generated " + date);\r
                for (File file : markdownFiles) {\r
+                       String documentName = getDocumentName(file);\r
+                       if (params.skips.contains(documentName)) {\r
+                               continue;\r
+                       }\r
                        try {\r
-                               String documentName = getDocumentName(file);\r
-                               if (!params.skips.contains(documentName)) {\r
-                                       String fileName = documentName + ".html";\r
-                                       System.out.println(MessageFormat.format("  {0} => {1}", file.getName(),\r
-                                                       fileName));\r
-                                       String rawContent = FileUtils.readContent(file, "\n");\r
-                                       String markdownContent = rawContent;\r
-\r
-                                       Map<String, List<String>> nomarkdownMap = new HashMap<String, List<String>>();\r
-\r
-                                       // extract sections marked as no-markdown\r
-                                       int nmd = 0;\r
-                                       for (String token : params.nomarkdown) {\r
-                                               StringBuilder strippedContent = new StringBuilder();\r
-\r
-                                               String nomarkdownKey = "%NOMARKDOWN" + nmd + "%";\r
-                                               String[] kv = token.split(":", 2);\r
-                                               String beginToken = kv[0];\r
-                                               String endToken = kv[1];\r
-\r
-                                               // strip nomarkdown chunks from markdown and cache them\r
-                                               List<String> chunks = new Vector<String>();\r
-                                               int beginCode = 0;\r
-                                               int endCode = 0;\r
-                                               while ((beginCode = markdownContent.indexOf(beginToken, endCode)) > -1) {\r
-                                                       if (endCode == 0) {\r
-                                                               strippedContent.append(markdownContent.substring(0, beginCode));\r
-                                                       } else {\r
-                                                               strippedContent.append(markdownContent\r
-                                                                               .substring(endCode, beginCode));\r
-                                                       }\r
-                                                       strippedContent.append(nomarkdownKey);\r
-                                                       endCode = markdownContent.indexOf(endToken, beginCode);\r
-                                                       chunks.add(markdownContent.substring(beginCode, endCode));\r
-                                                       nomarkdownMap.put(nomarkdownKey, chunks);\r
-                                               }\r
-\r
-                                               // get remainder of text\r
-                                               if (endCode < markdownContent.length()) {\r
-                                                       strippedContent.append(markdownContent.substring(endCode,\r
-                                                                       markdownContent.length()));\r
-                                               }\r
-                                               markdownContent = strippedContent.toString();\r
-                                               nmd++;\r
+                               String links = createLinks(file, markdownFiles, aliasMap, params.skips);\r
+                               String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);\r
+                               if (!StringUtils.isEmpty(params.analyticsSnippet)) {\r
+                                       File snippet = new File(params.analyticsSnippet);\r
+                                       if (snippet.exists()) {\r
+                                               String htmlSnippet = FileUtils.readContent(snippet, "\n");\r
+                                               header = header.replace("<!-- ANALYTICS -->", htmlSnippet);\r
                                        }\r
+                               }\r
 \r
-                                       // transform markdown to html\r
-                                       String content = transformMarkdown(markdownContent.toString());\r
-\r
-                                       // reinsert nomarkdown chunks\r
-                                       for (Map.Entry<String, List<String>> nomarkdown : nomarkdownMap.entrySet()) {\r
-                                               for (String chunk : nomarkdown.getValue()) {\r
-                                                       content = content.replaceFirst(nomarkdown.getKey(), chunk);\r
+                               String fileName = documentName + ".html";\r
+                               System.out.println(MessageFormat.format("  {0} => {1}", file.getName(), fileName));\r
+                               String rawContent = FileUtils.readContent(file, "\n");\r
+                               String markdownContent = rawContent;\r
+\r
+                               Map<String, List<String>> nomarkdownMap = new HashMap<String, List<String>>();\r
+\r
+                               // extract sections marked as no-markdown\r
+                               int nmd = 0;\r
+                               for (String token : params.nomarkdown) {\r
+                                       StringBuilder strippedContent = new StringBuilder();\r
+\r
+                                       String nomarkdownKey = "%NOMARKDOWN" + nmd + "%";\r
+                                       String[] kv = token.split(":", 2);\r
+                                       String beginToken = kv[0];\r
+                                       String endToken = kv[1];\r
+\r
+                                       // strip nomarkdown chunks from markdown and cache them\r
+                                       List<String> chunks = new Vector<String>();\r
+                                       int beginCode = 0;\r
+                                       int endCode = 0;\r
+                                       while ((beginCode = markdownContent.indexOf(beginToken, endCode)) > -1) {\r
+                                               if (endCode == 0) {\r
+                                                       strippedContent.append(markdownContent.substring(0, beginCode));\r
+                                               } else {\r
+                                                       strippedContent.append(markdownContent.substring(endCode, beginCode));\r
                                                }\r
+                                               strippedContent.append(nomarkdownKey);\r
+                                               endCode = markdownContent.indexOf(endToken, beginCode);\r
+                                               chunks.add(markdownContent.substring(beginCode, endCode));\r
+                                               nomarkdownMap.put(nomarkdownKey, chunks);\r
                                        }\r
 \r
-                                       for (String token : params.substitutions) {\r
-                                               String[] kv = token.split("=", 2);\r
-                                               content = content.replace(kv[0], kv[1]);\r
-                                       }\r
-                                       for (String token : params.regex) {\r
-                                               String[] kv = token.split("!!!", 2);\r
-                                               content = content.replaceAll(kv[0], kv[1]);\r
-                                       }\r
-                                       for (String alias : params.properties) {\r
-                                               String[] kv = alias.split("=", 2);\r
-                                               String loadedContent = generatePropertiesContent(new File(kv[1]));\r
-                                               content = content.replace(kv[0], loadedContent);\r
-                                       }\r
-                                       for (String alias : params.loads) {\r
-                                               String[] kv = alias.split("=", 2);\r
-                                               String loadedContent = FileUtils.readContent(new File(kv[1]), "\n");\r
-                                               loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
-                                               loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
-                                               content = content.replace(kv[0], loadedContent);\r
+                                       // get remainder of text\r
+                                       if (endCode < markdownContent.length()) {\r
+                                               strippedContent.append(markdownContent.substring(endCode,\r
+                                                               markdownContent.length()));\r
                                        }\r
-                                       OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(\r
-                                                       new File(destinationFolder, fileName)), Charset.forName("UTF-8"));\r
-                                       writer.write(header);\r
-                                       if (!StringUtils.isEmpty(htmlAdSnippet)) {\r
-                                               writer.write(htmlAdSnippet);\r
+                                       markdownContent = strippedContent.toString();\r
+                                       nmd++;\r
+                               }\r
+\r
+                               // transform markdown to html\r
+                               String content = transformMarkdown(markdownContent.toString());\r
+\r
+                               // reinsert nomarkdown chunks\r
+                               for (Map.Entry<String, List<String>> nomarkdown : nomarkdownMap.entrySet()) {\r
+                                       for (String chunk : nomarkdown.getValue()) {\r
+                                               content = content.replaceFirst(nomarkdown.getKey(), chunk);\r
                                        }\r
-                                       writer.write(content);\r
-                                       writer.write(footer);\r
-                                       writer.close();\r
                                }\r
+\r
+                               for (String token : params.substitutions) {\r
+                                       String[] kv = token.split("=", 2);\r
+                                       content = content.replace(kv[0], kv[1]);\r
+                               }\r
+                               for (String token : params.regex) {\r
+                                       String[] kv = token.split("!!!", 2);\r
+                                       content = content.replaceAll(kv[0], kv[1]);\r
+                               }\r
+                               for (String alias : params.properties) {\r
+                                       String[] kv = alias.split("=", 2);\r
+                                       String loadedContent = generatePropertiesContent(new File(kv[1]));\r
+                                       content = content.replace(kv[0], loadedContent);\r
+                               }\r
+                               for (String alias : params.loads) {\r
+                                       String[] kv = alias.split("=", 2);\r
+                                       String loadedContent = FileUtils.readContent(new File(kv[1]), "\n");\r
+                                       loadedContent = StringUtils.escapeForHtml(loadedContent, false);\r
+                                       loadedContent = StringUtils.breakLinesForHtml(loadedContent);\r
+                                       content = content.replace(kv[0], loadedContent);\r
+                               }\r
+                               OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(\r
+                                               destinationFolder, fileName)), Charset.forName("UTF-8"));\r
+                               writer.write(header);\r
+                               if (!StringUtils.isEmpty(htmlAdSnippet)) {\r
+                                       writer.write(htmlAdSnippet);\r
+                               }\r
+                               writer.write(content);\r
+                               writer.write(footer);\r
+                               writer.close();\r
                        } catch (Throwable t) {\r
                                System.err.println("Failed to transform " + file.getName());\r
                                t.printStackTrace();\r
@@ -237,6 +219,33 @@ public class BuildSite {
                return displayName;\r
        }\r
 \r
+       private static String createLinks(File currentFile, File[] markdownFiles,\r
+                       Map<String, String> aliasMap, List<String> skips) {\r
+               String linkPattern = "<li><a href=''{0}''>{1}</a></li>";\r
+               String currentLinkPattern = "<li class=''active''><a href=''{0}''>{1}</a></li>";\r
+               StringBuilder sb = new StringBuilder();\r
+               for (File file : markdownFiles) {\r
+                       String documentName = getDocumentName(file);\r
+                       if (!skips.contains(documentName)) {\r
+                               String displayName = documentName;\r
+                               if (aliasMap.containsKey(documentName)) {\r
+                                       displayName = aliasMap.get(documentName);\r
+                               } else {\r
+                                       displayName = displayName.replace('_', ' ');\r
+                               }\r
+                               String fileName = documentName + ".html";\r
+                               if (currentFile.getName().equals(file.getName())) {\r
+                                       sb.append(MessageFormat.format(currentLinkPattern, fileName, displayName));\r
+                               } else {\r
+                                       sb.append(MessageFormat.format(linkPattern, fileName, displayName));\r
+                               }\r
+                       }\r
+               }\r
+               sb.setLength(sb.length() - 3);\r
+               sb.trimToSize();\r
+               return sb.toString();\r
+       }\r
+\r
        private static String generatePropertiesContent(File propertiesFile) throws Exception {\r
                // Read the current Gitblit properties\r
                BufferedReader propertiesReader = new BufferedReader(new FileReader(propertiesFile));\r