Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
niltor committed Mar 29, 2024
1 parent c1cb0d5 commit 5d4eb87
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- run: dotnet run --project ./Lib/BuildSite ./Content ./WebApp
- run: dotnet run --project ./Lib/BuildSite ./Content ./WebApp Production

- name: Upload artifact
uses: actions/upload-pages-artifact@v3
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# User-specific files
WebApp/blogs/
webinfo.json
WebApp/data/
*.rsuser
*.suo
*.user
Expand Down
13 changes: 7 additions & 6 deletions Lib/BuildSite/HtmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public HtmlBuilder(string input, string output)

public void BuildWebSite()
{
GetBaseUrl();
BuildData();
BuildBlogs();
BuildIndex();
Expand Down Expand Up @@ -87,6 +86,11 @@ public void BuildBlogs()
/// </summary>
public void BuildData()
{
if (!Directory.Exists(DataPath))
{
Directory.CreateDirectory(DataPath);
}

// copy webinfo.json
var webInfoPath = Path.Combine(Environment.CurrentDirectory, "webinfo.json");
if (File.Exists(webInfoPath))
Expand All @@ -99,10 +103,7 @@ public void BuildData()
TraverseDirectory(ContentPath, rootCatalog);
string json = JsonSerializer.Serialize(rootCatalog, _jsonSerializerOptions);

if (!Directory.Exists(DataPath))
{
Directory.CreateDirectory(DataPath);
}

string blogData = Path.Combine(DataPath, "blogs.json");
File.WriteAllText(blogData, json, Encoding.UTF8);
}
Expand Down Expand Up @@ -181,7 +182,7 @@ private static string GetFullPath(Catalog catalog)
}
return path.Replace("Root", "");
}
private void GetBaseUrl()
public void EnableBaseUrl()
{
var webInfoPath = Path.Combine(DataPath, "webinfo.json");
if (File.Exists(webInfoPath))
Expand Down
9 changes: 8 additions & 1 deletion Lib/BuildSite/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@

var input = args.FirstOrDefault() ?? "./";
var output = args.Skip(1).FirstOrDefault() ?? "./_site";
var environment = args.Skip(2).FirstOrDefault() ?? "Development";


var builder = new HtmlBuilder(input, output);

try
{
if (environment.Equals("Production", StringComparison.OrdinalIgnoreCase))
{
builder.EnableBaseUrl();
}

builder.BuildWebSite();
}
catch (Exception e)
{
Console.WriteLine(e.Message);
Console.WriteLine(e.Message + e.StackTrace);
Console.WriteLine("请尝试在根目录下运行本项目");
}
2 changes: 1 addition & 1 deletion Lib/BuildSite/TemplateContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class TemplateContent
<link rel="stylesheet" href="@{BaseUrl}css/app.css" />
<link rel="stylesheet" href="@{BaseUrl}css/markdown.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<script src="./js/index.js"></script>
<script src="@{BaseUrl}js/index.js"></script>
</head>
<body class="dark:bg-neutral-900">
Expand Down
6 changes: 3 additions & 3 deletions WebApp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Ater Blog</title>
<base href="/" />
<link rel="stylesheet" href="/blazor-blog/css/app.css" />
<link rel="stylesheet" href="/blazor-blog/css/markdown.css" />
<link rel="stylesheet" href="/css/app.css" />
<link rel="stylesheet" href="/css/markdown.css" />
<link rel="icon" type="image/png" href="favicon.png" />
<script src="./js/index.js"></script>
<script src="/js/index.js"></script>
</head>

<body class="dark:bg-neutral-900">
Expand Down

0 comments on commit 5d4eb87

Please sign in to comment.