checkpoint
This commit is contained in:
+17
-3
@@ -2,10 +2,24 @@ using Microsoft.AspNetCore.Mvc.RazorPages;
|
||||
|
||||
namespace StatiKosev.Pages;
|
||||
|
||||
public class Gallery : PageModel
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user