Skip to content

Commit

Permalink
Update to use static website
Browse files Browse the repository at this point in the history
  • Loading branch information
andersme committed Dec 27, 2023
1 parent f1088eb commit 723ea61
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 24 deletions.
17 changes: 17 additions & 0 deletions Source/.run/Run.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Run" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/Tazor.Sample/Tazor.Sample.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net8.0" />
<option name="LAUNCH_PROFILE_NAME" value="Run" />
<option name="USE_EXTERNAL_CONSOLE" value="0" />
<option name="USE_MONO" value="0" />
<option name="RUNTIME_ARGUMENTS" value="" />
<option name="GENERATE_APPLICATIONHOST_CONFIG" value="1" />
<option name="SHOW_IIS_EXPRESS_OUTPUT" value="0" />
<option name="SEND_DEBUG_REQUEST" value="1" />
<option name="ADDITIONAL_IIS_EXPRESS_ARGUMENTS" value="" />
<method v="2">
<option name="Build" />
</method>
</configuration>
</component>
1 change: 0 additions & 1 deletion Source/Tazor.Sample/Pages/Index.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
@page "/"
@layout _Layout

<h1>Welcome to Tazor</h1>
4 changes: 1 addition & 3 deletions Source/Tazor.Sample/Pages/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@layout _Layout

@using Tazor.Sample.Components
@layout Shared._Layout
17 changes: 13 additions & 4 deletions Source/Tazor.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
using Tazor;
using Tazor.Sample2;

var builder = new RunnerBuilder(args);
var runner = builder.Build();
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddHostedService<TazorHostedService>();

await runner.Run();
var app = builder.Build();

app.UseDefaultFiles();
app.UseStaticFiles(new StaticFileOptions
{
ServeUnknownFileTypes = true,
DefaultContentType = "text/plain"
});

app.Run();
14 changes: 14 additions & 0 deletions Source/Tazor.Sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Run": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7250;http://localhost:5153",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tazor</title>
<base href="@Options.BasePath" />

<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-T3c6CoIi6uLrA9TneNEoa7RxnatzjcDSCmG1MXxSR1GAsXEV/Dwwykc2MPK8M2HN" crossorigin="anonymous"/>
</head>
Expand All @@ -17,4 +16,4 @@
</main>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
</body>
</html>
</html>
13 changes: 8 additions & 5 deletions Source/Tazor.Sample/Tazor.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<RootNamespace>Tazor.Sample2</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components" Version="8.0.0" />
<AdditionalFiles Include="Components\Navbar.razor" />
<AdditionalFiles Include="Pages\Blog\Index.razor" />
<AdditionalFiles Include="Pages\Index.razor" />
<AdditionalFiles Include="Pages\_Imports.razor" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Tazor\Tazor.csproj" />
</ItemGroup>

<ItemGroup>
<Content Update="wwwroot\*">
<Content Update="wwwroot\robots.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
Expand Down
29 changes: 29 additions & 0 deletions Source/Tazor.Sample/TazorHostedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace Tazor.Sample2;

public class TazorHostedService : IHostedService
{
private readonly IHostEnvironment _environment;

public TazorHostedService(IHostEnvironment environment)
{
_environment = environment;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
var wwwroot = Path.Combine(_environment.ContentRootPath, "wwwroot");
var builder = new RunnerBuilder(new RunnerOptions
{
OutputPath = wwwroot
});

var runner = builder.Build();

await runner.Run();
}

public Task StopAsync(CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
4 changes: 1 addition & 3 deletions Source/Tazor.Sample/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
@using Tazor.Sample.Components

@inject IRunnerOptions Options
@using Tazor.Sample2.Components
9 changes: 9 additions & 0 deletions Source/Tazor.Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
12 changes: 6 additions & 6 deletions Source/Tazor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tazor", "Tazor\Tazor.csproj", "{9F2CBC9D-F174-4D88-B1D6-72689DB19D21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tazor.Sample", "Tazor.Sample\Tazor.Sample.csproj", "{FEAA2AA3-CA68-440A-AE4D-031DB01A8E71}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Other", "Other", "{416C7771-71F7-4036-A235-A305B4C34AEA}"
ProjectSection(SolutionItems) = preProject
..\README.md = ..\README.md
..\.github\workflows\develop.yml = ..\.github\workflows\develop.yml
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tazor.Sample", "Tazor.Sample\Tazor.Sample.csproj", "{BE036DA2-9BA2-4561-B12E-92F968964F68}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -20,9 +20,9 @@ Global
{9F2CBC9D-F174-4D88-B1D6-72689DB19D21}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F2CBC9D-F174-4D88-B1D6-72689DB19D21}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F2CBC9D-F174-4D88-B1D6-72689DB19D21}.Release|Any CPU.Build.0 = Release|Any CPU
{FEAA2AA3-CA68-440A-AE4D-031DB01A8E71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FEAA2AA3-CA68-440A-AE4D-031DB01A8E71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEAA2AA3-CA68-440A-AE4D-031DB01A8E71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEAA2AA3-CA68-440A-AE4D-031DB01A8E71}.Release|Any CPU.Build.0 = Release|Any CPU
{BE036DA2-9BA2-4561-B12E-92F968964F68}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE036DA2-9BA2-4561-B12E-92F968964F68}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE036DA2-9BA2-4561-B12E-92F968964F68}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE036DA2-9BA2-4561-B12E-92F968964F68}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
12 changes: 12 additions & 0 deletions Source/Tazor/RunnerBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ public RunnerBuilder(IEnumerable<string> args)
_services.AddTransient<IComponentRenderer, ComponentRenderer>();
_services.AddLogging();
}

public RunnerBuilder(RunnerOptions options)
{
_options = options;
_services.AddTransient<IRunnerOptions>(_ => _options);
_services.AddTransient<Runner>();
_services.AddTransient<IDocumentResolver, RazorComponentsResolver>();
_services.AddTransient<IDocumentsProcessor, OutputProcessor>();
_services.AddTransient<IDocumentsProcessor, SitemapProcessor>();
_services.AddTransient<IComponentRenderer, ComponentRenderer>();
_services.AddLogging();
}

public RunnerBuilder WithOutput(string outputPath)
{
Expand Down

0 comments on commit 723ea61

Please sign in to comment.