Files
StatiKosev/Pages/Gallery.cshtml.cs
T
2026-10-28 13:23:35 +02:00

26 lines
868 B
C#

using Microsoft.AspNetCore.Mvc.RazorPages;
namespace StatiKosev.Pages;
public class Gallery(IWebHostEnvironment env) : PageModel
{
static readonly string[] ImageExtensions = [".png", ".jpg", ".jpeg", ".webp", ".gif"];
public IReadOnlyList<string> Images { get; private set; } = [];
//every image in wwwroot/images except the profile photo used on the home page
public void OnGet()
{
var dir = Path.Combine(env.WebRootPath, "images");
if (!Directory.Exists(dir)) return;
Images = Directory.EnumerateFiles(dir)
.Where(f => ImageExtensions.Contains(Path.GetExtension(f).ToLowerInvariant()))
.Select(Path.GetFileName)
.Where(n => !n!.StartsWith("profile.", StringComparison.OrdinalIgnoreCase))
.Order()
.Select(n => "/images/" + n)
.ToList();
}
}