| | |
| | |
|
| | | System.out.println(MessageFormat.format("Generating site from {0} Markdown Docs in {1} ",
|
| | | markdownFiles.length, sourceFolder.getAbsolutePath()));
|
| | | String linkPattern = "<li><a href=''{0}''>{1}</a></li>";
|
| | | StringBuilder sb = new StringBuilder();
|
| | | for (File file : markdownFiles) {
|
| | | String documentName = getDocumentName(file);
|
| | | if (!params.skips.contains(documentName)) {
|
| | | String displayName = documentName;
|
| | | if (aliasMap.containsKey(documentName)) {
|
| | | displayName = aliasMap.get(documentName);
|
| | | } else {
|
| | | displayName = displayName.replace('_', ' ');
|
| | | }
|
| | | String fileName = documentName + ".html";
|
| | | sb.append(MessageFormat.format(linkPattern, fileName, displayName));
|
| | | sb.append(" | ");
|
| | | }
|
| | | }
|
| | | sb.setLength(sb.length() - 3);
|
| | | sb.trimToSize();
|
| | |
|
| | | String htmlHeader = FileUtils.readContent(new File(params.pageHeader), "\n");
|
| | |
|
| | |
| | | }
|
| | | }
|
| | | String htmlFooter = FileUtils.readContent(new File(params.pageFooter), "\n");
|
| | | String links = sb.toString();
|
| | | final String date = new SimpleDateFormat("yyyy-MM-dd").format(new Date());
|
| | | final String footer = MessageFormat.format(htmlFooter, "generated " + date);
|
| | | for (File file : markdownFiles) {
|
| | | String documentName = getDocumentName(file);
|
| | | if (params.skips.contains(documentName)) {
|
| | | continue;
|
| | | }
|
| | | try {
|
| | | String links = createLinks(file, markdownFiles, aliasMap, params.skips);
|
| | | String header = MessageFormat.format(htmlHeader, Constants.FULL_NAME, links);
|
| | | if (!StringUtils.isEmpty(params.analyticsSnippet)) {
|
| | | File snippet = new File(params.analyticsSnippet);
|
| | |
| | | header = header.replace("<!-- ANALYTICS -->", htmlSnippet);
|
| | | }
|
| | | }
|
| | | 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 documentName = getDocumentName(file);
|
| | | if (!params.skips.contains(documentName)) {
|
| | |
|
| | | String fileName = documentName + ".html";
|
| | | System.out.println(MessageFormat.format(" {0} => {1}", file.getName(),
|
| | | fileName));
|
| | | System.out.println(MessageFormat.format(" {0} => {1}", file.getName(), fileName));
|
| | | String rawContent = FileUtils.readContent(file, "\n");
|
| | | String markdownContent = rawContent;
|
| | |
|
| | |
| | | if (endCode == 0) {
|
| | | strippedContent.append(markdownContent.substring(0, beginCode));
|
| | | } else {
|
| | | strippedContent.append(markdownContent
|
| | | .substring(endCode, beginCode));
|
| | | strippedContent.append(markdownContent.substring(endCode, beginCode));
|
| | | }
|
| | | strippedContent.append(nomarkdownKey);
|
| | | endCode = markdownContent.indexOf(endToken, beginCode);
|
| | |
| | | loadedContent = StringUtils.breakLinesForHtml(loadedContent);
|
| | | content = content.replace(kv[0], loadedContent);
|
| | | }
|
| | | 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);
|
| | | if (!StringUtils.isEmpty(htmlAdSnippet)) {
|
| | | writer.write(htmlAdSnippet);
|
| | |
| | | writer.write(content);
|
| | | writer.write(footer);
|
| | | writer.close();
|
| | | }
|
| | | } catch (Throwable t) {
|
| | | System.err.println("Failed to transform " + file.getName());
|
| | | t.printStackTrace();
|
| | |
| | | return displayName;
|
| | | }
|
| | |
|
| | | private static String createLinks(File currentFile, File[] markdownFiles,
|
| | | Map<String, String> aliasMap, List<String> skips) {
|
| | | String linkPattern = "<li><a href=''{0}''>{1}</a></li>";
|
| | | String currentLinkPattern = "<li class=''active''><a href=''{0}''>{1}</a></li>";
|
| | | StringBuilder sb = new StringBuilder();
|
| | | for (File file : markdownFiles) {
|
| | | String documentName = getDocumentName(file);
|
| | | if (!skips.contains(documentName)) {
|
| | | String displayName = documentName;
|
| | | if (aliasMap.containsKey(documentName)) {
|
| | | displayName = aliasMap.get(documentName);
|
| | | } else {
|
| | | displayName = displayName.replace('_', ' ');
|
| | | }
|
| | | String fileName = documentName + ".html";
|
| | | if (currentFile.getName().equals(file.getName())) {
|
| | | sb.append(MessageFormat.format(currentLinkPattern, fileName, displayName));
|
| | | } else {
|
| | | sb.append(MessageFormat.format(linkPattern, fileName, displayName));
|
| | | }
|
| | | }
|
| | | }
|
| | | sb.setLength(sb.length() - 3);
|
| | | sb.trimToSize();
|
| | | return sb.toString();
|
| | | }
|
| | |
|
| | | private static String generatePropertiesContent(File propertiesFile) throws Exception {
|
| | | // Read the current Gitblit properties
|
| | | BufferedReader propertiesReader = new BufferedReader(new FileReader(propertiesFile));
|