File Name Generation

There are two types of namers in xStatic, file name generators and image crop name generators.

Image crop name generators are used by the `CroppedImageUrlTransformer` and the base generator class to determine how image files should be stored.

File name generators are used to determine the file names of the static files generated by xStatic. There are built in file name generators, but if you want to alter this it is easy to do so. You can then choose the namer when defining your export types in the CMS dashboard.

File Name Generators

To create a custom file name generator, implement the `IFileNameGenerator` interface. Once deployed xStatic will automatically discover all the implementations of this class and show them as options on the export types page so that you can use them when generating static sites.

The `GetFilePartialPath` method takes in the relative url of the page that is having its static file generated. Simply manipulate the string and return the result.

public class JsonFileNameGenerator : IFileNameGenerator
{
    public string GetFilePartialPath(string relativeUrl)
    {
        var trimmedPath = relativeUrl?.Trim('/');

        return string.IsNullOrEmpty(trimmedPath) ? "index.json" : trimmedPath + ".json";
    }
}

Image Crop Name Generators

Image crop name generators are a little less flexible than other parts of xStatic as it is unlikely to require changing unless creating your own generator. Creating your own version of this component requires the following steps:
1. Implement IImageCropNameGenerator

public string GetCropFileName(string fileNameWithoutExtension, Crop crop)
    {
        return $"{fileNameWithoutExtension}--{crop.Width ?? 0}x{crop.Height ?? 0}";
    }
2. Create a TransformerListFactory that uses the new class with the `CroppedImageUrlTransformer`

if (!string.IsNullOrEmpty(siteConfig.ImageCrops))
    {
        var crops = Crop.GetCropsFromCommaDelimitedString(siteConfig.ImageCrops);
        yield return new CroppedImageUrlTransformer(new YourImageCropNameGenerator(), crops);
    }
3. Manually register the service on startup with the `GeneratorServiceBuilder`. 
You'll need to not use the automatic version.