Ejemplo n.º 1
0
  private static void convertDir(
      @NotNull PegDownProcessor processor,
      @NotNull PageProperties props,
      @NotNull File srcDir,
      @NotNull File dstDir)
      throws IOException {
    for (File mdFile : Util.listFiles(srcDir)) {
      if (mdFile.equals(props.propsFile)) continue;
      if (!mdFile.isFile()) continue;
      String name = mdFile.getName();
      if (!name.endsWith(".markdown")) continue;

      Util.println("Converting: " + name);
      String rawText = CharsetDetectorHelper.toString(mdFile);
      String htmlBody = processor.markdownToHtml(rawText);
      String newFilename = Util.splitFilename(name)[0] + ".html";
      File htmlFile = new File(dstDir, newFilename);
      String html = convertPage(props, mdFile, htmlBody);
      Files.write(html, htmlFile, Charsets.UTF_8);
    }
  }
Ejemplo n.º 2
0
  public static void main(String[] args) throws Exception {
    for (File srcDir : Util.listFiles(websiteDir)) {
      if (!srcDir.isDirectory()) continue;
      if (srcDir.getName().equals("all")) continue;

      File dstDir = new File("dist/website/" + srcDir.getName());
      dstDir.mkdirs();
      Util.deleteContents(dstDir);

      PegDownProcessor processor = new PegDownProcessor(Extensions.TABLES);
      File propsFile = new File(srcDir, "/page.properties");
      PageProperties props = new PageProperties(propsFile);
      convertDir(processor, props, srcDir, dstDir);
    }

    // Deploy files in the website/all directory
    for (File file : Util.listFiles(new File(websiteDir + "/all"))) {
      File dstFile = new File("dist/website/all", file.getName());
      Files.createParentDirs(dstFile);
      Files.copy(file, dstFile);
    }

    // Deploy PAD file
    File padFileSrc = new File(websiteDir, "docfetcher-pad-template.xml");
    File padFileDst = new File("dist/website", "docfetcher-pad.xml");
    String padContents = CharsetDetectorHelper.toString(padFileSrc);
    padContents = UtilGlobal.replace(padFileSrc.getPath(), padContents, "${version}", version);
    Files.write(padContents, padFileDst, Charsets.UTF_8);
    Util.println("File written: " + padFileDst.getPath());

    // Deploy English Resource.properties; this is currently used for
    // GUI translation via transifex.com
    Properties prop = new Properties();
    for (Msg msg : Msg.values()) prop.put(msg.name(), msg.get());
    File propFile = new File("dist/website", "Resource.properties");
    FileWriter w = new FileWriter(propFile);
    prop.store(w, "");
    Closeables.closeQuietly(w);
    Util.println("File written: " + propFile.getPath());

    // Deploy index.php file
    File indexPhpFile = new File("dist/website/index.php");
    Files.copy(new File(websiteDir, "index.php"), indexPhpFile);
    Util.println("File written: " + indexPhpFile.getPath());

    // Deploy help file for GUI translators
    File propHelpSrc = new File(websiteDir, "prop-help-template.html");
    File propHelpDst = new File("dist/website", "properties-help.html");
    StringBuilder sb = new StringBuilder();
    for (Msg msg : Msg.values()) {
      sb.append("<tr align=\"left\">");
      sb.append("<td>");
      sb.append(escapeHtml(propHelpSrc.getPath(), msg.get()));
      sb.append("</td>");
      sb.append(Util.LS);
      sb.append("<td>");
      sb.append(msg.getComment());
      sb.append("</td>");
      sb.append("</tr>");
      sb.append(Util.LS);
    }
    String propHelpContents = CharsetDetectorHelper.toString(propHelpSrc);
    propHelpContents =
        UtilGlobal.replace(propHelpSrc.getPath(), propHelpContents, "${contents}", sb.toString());
    Files.write(propHelpContents, propHelpDst, Charsets.UTF_8);
    Util.println("File written: " + propHelpDst.getPath());
  }