Generate content for static sites

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

using GroupDocs.Markdown;

var options = new ConvertOptions
{
    IncludeFrontMatter = true,
    HeadingLevelOffset = 1,   // Reserve H1 for the page title
    ImageExportStrategy = new ExportImagesToFileSystemStrategy("content/posts/images")
    {
        ImagesRelativePath = "images"
    }
};

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
// ...

Batch-convert a folder for Hugo

using GroupDocs.Markdown;

string inputDir = "source-documents";
string outputDir = "content/docs";

var options = new ConvertOptions
{
    IncludeFrontMatter = true,
    HeadingLevelOffset = 1,
    ImageExportStrategy = new SkipImagesStrategy() // or file system
};

foreach (string file in Directory.GetFiles(inputDir))
{
    string ext = Path.GetExtension(file).ToLower();
    if (ext is ".docx" or ".pdf" or ".xlsx" or ".epub")
    {
        try
        {
            string outputPath = Path.Combine(
                outputDir,
                Path.GetFileNameWithoutExtension(file) + ".md");

            MarkdownConverter.ToFile(file, outputPath, options);
            Console.WriteLine($"Converted: {Path.GetFileName(file)}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Skipped: {Path.GetFileName(file)} — {ex.Message}");
        }
    }
}