Skip to content

Commit 57809c6

Browse files
committed
chore(LLms): add llms.txt router (#7471)
1 parent 620fafe commit 57809c6

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

src/BootstrapBlazor.Server/Directory.Build.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22

3-
<Target Name="LLMs" AfterTargets="Build" Condition="'$(TargetFramework)' == '$(RunTargetFramework)'">
3+
<Target Name="LLMs" AfterTargets="Publish" Condition="'$(TargetFramework)' == '$(RunTargetFramework)'">
44
<Message Text="LLMs documentation generating ..." Importance="high"></Message>
55
<Exec Command="dotnet tool restore"></Exec>
66
<Exec Command="dotnet llms-docs --root=$(MSBuildThisFileDirectory) --debug"></Exec>

src/BootstrapBlazor.Server/Extensions/WebApplicationExtensions.cs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -20,4 +20,39 @@ public static void UseUploaderStaticFiles(this WebApplication app)
2020
RequestPath = "/images/uploader"
2121
});
2222
}
23+
24+
public static void UseLLMsStaticFiles(this WebApplication app)
25+
{
26+
var llms = Path.Combine(app.Environment.WebRootPath, "llms");
27+
Directory.CreateDirectory(llms);
28+
29+
app.UseStaticFiles(new StaticFileOptions
30+
{
31+
FileProvider = new PhysicalFileProvider(llms),
32+
RequestPath = "/llms",
33+
OnPrepareResponse = context =>
34+
{
35+
context.Context.Response.ContentType = "text/plain; charset=utf-8";
36+
}
37+
});
38+
39+
app.MapGet("/llms.txt", async context =>
40+
{
41+
context.Response.Headers.ContentType = "text/plain; charset=utf-8";
42+
var filePath = Path.Combine(app.Environment.WebRootPath, "llms", "llms.txt");
43+
if (File.Exists(filePath))
44+
{
45+
var fileInfo = new FileInfo(filePath);
46+
context.Response.ContentLength = fileInfo.Length;
47+
48+
using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 4096, useAsync: true);
49+
await fileStream.CopyToAsync(context.Response.Body);
50+
return;
51+
}
52+
53+
var defaultContent = "no llms.txt";
54+
context.Response.ContentLength = defaultContent.Length;
55+
await context.Response.WriteAsync(defaultContent);
56+
});
57+
}
2358
}

src/BootstrapBlazor.Server/Program.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Licensed to the .NET Foundation under one or more agreements.
1+
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the Apache 2.0 License
33
// See the LICENSE file in the project root for more information.
44
// Maintainer: Argo Zhang(argo@live.ca) Website: https://www.blazor.zone
@@ -38,6 +38,9 @@
3838
// 增加上传目录静态资源文件
3939
app.UseUploaderStaticFiles();
4040

41+
// 增加 llms 静态资源文件
42+
app.UseLLMsStaticFiles();
43+
4144
app.UseAntiforgery();
4245
app.UseBootstrapBlazor();
4346

0 commit comments

Comments
 (0)