Generate content for static sites

Static site generators like Jekyll, Hugo, and Docusaurus expect Markdown files with YAML front matter. GroupDocs.Markdown can automatically generate front matter from document metadata.

Convert with front matter and relative images

import com.groupdocs.markdown.*;

public class SsgExample {

    public static void main(String[] args) {
        ExportImagesToFileSystemStrategy imageStrategy =
                new ExportImagesToFileSystemStrategy("content/posts/images");
        imageStrategy.setImagesRelativePath("images");

        DocumentConvertOptions options = new DocumentConvertOptions();
        options.setIncludeFrontMatter(true);
        options.setHeadingLevelOffset(1);   // Reserve H1 for the page title
        options.setImageExportStrategy(imageStrategy);

        MarkdownConverter.toFile("annual-report.docx", "content/posts/annual-report.md", options);

        // Output file starts with:
        // ---
        // title: "Annual Report 2025"
        // author: "Finance Team"
        // format: Docx
        // pages: 24
        // ---
        //
        // ## Executive Summary
        // ...
    }
}

annual-report.docx is a sample file used in this example. Click here to download it.

content/posts/annual-report.md (5 KB)
content/posts/images/img-001.png (4 KB)
content/posts/images/img-002.png (14 KB)
content/posts/images/img-003.png (15 KB)

Download full output

Batch-convert a folder for Hugo

import com.groupdocs.markdown.*;

import java.io.File;
import java.util.Arrays;
import java.util.List;

public class SsgBatchHugo {

    private static final List<String> EXTENSIONS =
            Arrays.asList(".docx", ".pdf", ".xlsx", ".epub");

    public static void main(String[] args) {
        String inputDir = "documents";
        String outputDir = "content/docs";

        DocumentConvertOptions options = new DocumentConvertOptions();
        options.setIncludeFrontMatter(true);
        options.setHeadingLevelOffset(1);
        options.setImageExportStrategy(new SkipImagesStrategy());   // or file system

        File[] files = new File(inputDir).listFiles();
        if (files == null) {
            files = new File[0];
        }

        for (File file : files) {
            if (!EXTENSIONS.contains(extension(file.getName()))) {
                continue;
            }

            try {
                String outputPath =
                        new File(outputDir, baseName(file.getName()) + ".md").getPath();

                MarkdownConverter.toFile(file.getPath(), outputPath, options);
                System.out.println("Converted: " + file.getName());
            } catch (Exception e) {
                System.out.println("Skipped: " + file.getName() + " — " + e.getMessage());
            }
        }
    }

    private static String extension(String fileName) {
        int dot = fileName.lastIndexOf('.');
        return dot < 0 ? "" : fileName.substring(dot).toLowerCase();
    }

    private static String baseName(String fileName) {
        int dot = fileName.lastIndexOf('.');
        return dot < 0 ? fileName : fileName.substring(0, dot);
    }
}
content/docs/business-plan.md (0 bytes)
content/docs/cost-analysis.md (9 KB)

Download full output

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.