From 17c417dad5c7be28df4b6e1fd25ec56b484faaff Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Thu, 26 May 2011 17:22:03 -0400
Subject: [PATCH] Changed git.otherUrls to web.otherUrls.
---
src/com/gitblit/BuildSite.java | 80 ++++++++++++++++++++++++++++++---------
1 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/src/com/gitblit/BuildSite.java b/src/com/gitblit/BuildSite.java
index ae85c06..f3a1a9f 100644
--- a/src/com/gitblit/BuildSite.java
+++ b/src/com/gitblit/BuildSite.java
@@ -1,3 +1,18 @@
+/*
+ * Copyright 2011 gitblit.com.
+ *
+ * Licensed 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 com.gitblit;
import java.io.BufferedReader;
@@ -10,8 +25,12 @@
import java.nio.charset.Charset;
import java.text.MessageFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
@@ -41,34 +60,49 @@
});
Arrays.sort(markdownFiles);
- System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ", markdownFiles.length, sourceFolder.getAbsolutePath()));
+ Map<String, String> aliasMap = new HashMap<String, String>();
+ for (String alias : params.aliases) {
+ String[] values = alias.split("=");
+ aliasMap.put(values[0], values[1]);
+ }
+
+ System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",
+ markdownFiles.length, sourceFolder.getAbsolutePath()));
String linkPattern = "<a href=''{0}''>{1}</a>";
StringBuilder sb = new StringBuilder();
for (File file : markdownFiles) {
- String displayName = getDocumentName(file);
- String fileName = displayName + ".html";
+ String documentName = getDocumentName(file);
+ String displayName = documentName;
+ if (aliasMap.containsKey(documentName)) {
+ displayName = aliasMap.get(documentName);
+ }
+ String fileName = documentName + ".html";
sb.append(MessageFormat.format(linkPattern, fileName, displayName));
sb.append(" | ");
}
sb.setLength(sb.length() - 3);
sb.trimToSize();
- String html_header = readContent(new File(params.pageHeader));
- String html_footer = readContent(new File(params.pageFooter));
+
+ String htmlHeader = readContent(new File(params.pageHeader));
+ String htmlFooter = readContent(new File(params.pageFooter));
final String links = sb.toString();
- final String header = MessageFormat.format(html_header, Constants.FULL_NAME, links);
- final String date = new SimpleDateFormat("yyyy MMM dd").format(new Date());
- final String footer = MessageFormat.format(html_footer, "generated " + date);
+ final String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);
+ final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
+ final String footer = MessageFormat.format(htmlFooter, "generated " + date);
for (File file : markdownFiles) {
try {
- String displayName = getDocumentName(file);
- String fileName = displayName + ".html";
+ String documentName = getDocumentName(file);
+ String fileName = documentName + ".html";
System.out.println(MessageFormat.format(" {0} => {1}", file.getName(), fileName));
- InputStreamReader reader = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
+ InputStreamReader reader = new InputStreamReader(new FileInputStream(file),
+ Charset.forName("UTF-8"));
String content = MarkdownUtils.transformMarkdown(reader);
- if (displayName.equalsIgnoreCase("overview")) {
- content = MessageFormat.format(content, Constants.VERSION, "gitblit-" + Constants.VERSION + ".zip", Constants.getJGitVersion(), date);
+ for (String token : params.substitutions) {
+ String[] kv = token.split("=");
+ content = content.replace(kv[0], kv[1]);
}
- OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(destinationFolder, fileName)), Charset.forName("UTF-8"));
+ OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(
+ destinationFolder, fileName)), Charset.forName("UTF-8"));
writer.write(header);
writer.write(content);
writer.write(footer);
@@ -84,7 +118,8 @@
private static String readContent(File file) {
StringBuilder sb = new StringBuilder();
try {
- InputStreamReader is = new InputStreamReader(new FileInputStream(file), Charset.forName("UTF-8"));
+ InputStreamReader is = new InputStreamReader(new FileInputStream(file),
+ Charset.forName("UTF-8"));
BufferedReader reader = new BufferedReader(is);
String line = null;
while ((line = reader.readLine()) != null) {
@@ -99,13 +134,14 @@
}
private static String getDocumentName(File file) {
- String displayName = file.getName().substring(0, file.getName().lastIndexOf('.')).toLowerCase();
+ String displayName = file.getName().substring(0, file.getName().lastIndexOf('.'))
+ .toLowerCase();
// trim leading ##_ which is to control display order
return displayName.substring(3);
}
-
+
private static void usage(JCommander jc, ParameterException t) {
- System.out.println(Constants.getRunningVersion());
+ System.out.println(Constants.getGitBlitVersion());
System.out.println();
if (t != null) {
System.out.println(t.getMessage());
@@ -116,7 +152,7 @@
}
System.exit(0);
}
-
+
@Parameters(separators = " ")
private static class Params {
@@ -132,5 +168,11 @@
@Parameter(names = { "--pageFooter" }, description = "Page Footer HTML Snippet", required = true)
public String pageFooter;
+ @Parameter(names = { "--alias" }, description = "Filename=Linkname aliases", required = false)
+ public List<String> aliases = new ArrayList<String>();
+
+ @Parameter(names = { "--substitute" }, description = "@TOKEN@=value", required = false)
+ public List<String> substitutions = new ArrayList<String>();
+
}
}
--
Gitblit v1.9.1