Improve home page layout
This commit is contained in:
+48
-36
@@ -10,48 +10,60 @@ using WebApp.Components;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Load optional appsettings from Data directory (overrides defaults)
|
||||
var dataAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "Data", "appsettings.json");
|
||||
if (!File.Exists(dataAppSettingsPath))
|
||||
// Load optional appsettings from Data directory in production (overrides defaults)
|
||||
// In development, use appsettings.Development.json instead
|
||||
if (builder.Environment.IsProduction())
|
||||
{
|
||||
Console.WriteLine($"appsettings.json not found at {dataAppSettingsPath}. Creating with template values...");
|
||||
|
||||
var templateSettings = new
|
||||
var dataAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "Data", "appsettings.json");
|
||||
if (!File.Exists(dataAppSettingsPath))
|
||||
{
|
||||
ChapterSettings = new
|
||||
Console.WriteLine($"appsettings.json not found at {dataAppSettingsPath}. Creating from template...");
|
||||
|
||||
try
|
||||
{
|
||||
Name = "Your Chapter Name",
|
||||
ShortName = "YCN",
|
||||
NationalId = "0000",
|
||||
StateId = "00000",
|
||||
RegionalId = "00000",
|
||||
CompetitionYear = "2025"
|
||||
// Ensure Data directory exists
|
||||
Directory.CreateDirectory(Path.Combine(builder.Environment.ContentRootPath, "Data"));
|
||||
|
||||
// Copy ChapterSettings from the base appsettings.json
|
||||
var baseAppSettingsPath = Path.Combine(builder.Environment.ContentRootPath, "appsettings.json");
|
||||
if (File.Exists(baseAppSettingsPath))
|
||||
{
|
||||
var baseConfig = File.ReadAllText(baseAppSettingsPath);
|
||||
var baseDoc = JsonDocument.Parse(baseConfig);
|
||||
|
||||
if (baseDoc.RootElement.TryGetProperty("ChapterSettings", out var chapterSettings))
|
||||
{
|
||||
var templateSettings = new
|
||||
{
|
||||
ChapterSettings = JsonSerializer.Deserialize<object>(chapterSettings.GetRawText())
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(templateSettings, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
|
||||
File.WriteAllText(dataAppSettingsPath, json);
|
||||
Console.WriteLine("appsettings.json created in Data directory. Please update ChapterSettings with your chapter information.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("WARNING: ChapterSettings not found in base appsettings.json");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"WARNING: Unable to create appsettings.json: {ex.Message}");
|
||||
}
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(templateSettings, new JsonSerializerOptions
|
||||
{
|
||||
WriteIndented = true
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
// Ensure Data directory exists
|
||||
Directory.CreateDirectory(Path.Combine(builder.Environment.ContentRootPath, "Data"));
|
||||
File.WriteAllText(dataAppSettingsPath, json);
|
||||
Console.WriteLine("appsettings.json created in Data directory. Please update ChapterSettings with your chapter information.");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"WARNING: Unable to create appsettings.json: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// Add Data/appsettings.json as additional configuration source
|
||||
if (File.Exists(dataAppSettingsPath))
|
||||
{
|
||||
builder.Configuration.AddJsonFile(dataAppSettingsPath, optional: true, reloadOnChange: true);
|
||||
Console.WriteLine($"Loaded configuration from {dataAppSettingsPath}");
|
||||
// Add Data/appsettings.json as additional configuration source
|
||||
if (File.Exists(dataAppSettingsPath))
|
||||
{
|
||||
builder.Configuration.AddJsonFile(dataAppSettingsPath, optional: true, reloadOnChange: true);
|
||||
Console.WriteLine($"Loaded configuration from {dataAppSettingsPath}");
|
||||
}
|
||||
}
|
||||
|
||||
// Configure Serilog
|
||||
|
||||
Reference in New Issue
Block a user