private static ModuleCollection GetIndexPageModules(Documents documents, ArchiveSettings settings) { IModule[] paginateModules = settings.Sort == null ? new IModule[] { documents } : new IModule[] { documents, new Sort(settings.Sort) }; return(new ModuleCollection { new Execute(c => { Paginate paginate = new Paginate(settings.PageSize?.Invoke <int>(c) ?? int.MaxValue, paginateModules); paginate = paginate.WithPageMetadata(Keys.Title, (doc, ctx) => { string indexTitle = settings.Title?.Invoke <string>(doc, ctx) ?? string.Empty; return doc.Get <int>(Keys.CurrentPage) <= 1 ? indexTitle : (string.IsNullOrEmpty(indexTitle) ? $"Page {doc[Keys.CurrentPage]}" : $"{indexTitle} (Page {doc[Keys.CurrentPage]})"); }); if (settings.TakePages != null) { paginate = paginate.TakePages(settings.TakePages.Invoke <int>(c)); } if (settings.SkipPages != null) { paginate = paginate.SkipPages(settings.SkipPages.Invoke <int>(c)); } if (!string.IsNullOrEmpty(settings.GroupDocumentsMetadataKey)) { paginate = paginate.WithPageMetadata(settings.GroupDocumentsMetadataKey, (doc, ctx) => doc[Keys.GroupDocuments]); } if (!string.IsNullOrEmpty(settings.GroupKeyMetadataKey)) { paginate = paginate.WithPageMetadata(settings.GroupKeyMetadataKey, (doc, ctx) => doc.String(Keys.GroupKey)); } paginate = paginate.WithPageMetadata(Keys.RelativeFilePath, (doc, ctx) => { FilePath filePath = settings.RelativePath?.Invoke <FilePath>(doc, ctx) ?? settings.TemplateFile.Invoke <FilePath>(ctx); bool hasExtension = filePath.HasExtension; if (hasExtension) { filePath = filePath.Directory.CombineFile(filePath.FileNameWithoutExtension); } string path = filePath .FullPath .Replace(' ', '-') .Replace("'", string.Empty) .Replace(".", string.Empty); return doc.Get <int>(Keys.CurrentPage) <= 1 ? (hasExtension ? $"{path}.html" : $"{path}/index.html") : (hasExtension ? $"{path}{doc.String(Keys.CurrentPage)}.html" : $"{path}/page{doc.String(Keys.CurrentPage)}.html"); }); return paginate; }) }); }