Skip to content

Commit

Permalink
Update generator to take output path.
Browse files Browse the repository at this point in the history
  • Loading branch information
pawchen committed Jul 26, 2024
1 parent 083bb7c commit 271c8fd
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
with:
dotnet-version: '8.x'
- name: Run generator
run: dotnet run -c Release --project ./src/generator -- ${{ github.workspace }}/src/books
run: dotnet run -c Release --project ./src/generator -- ${{ github.workspace }}/src/books ${{ github.workspace }}/out
- name: Copy static files
run: cp -r ./src/static/ ./out
- name: Setup Pages
Expand Down
5 changes: 4 additions & 1 deletion src/generator/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class Options
[Option('i', HelpText = "Only generate index pages, for fast iterations.")]
public bool IndexPagesOnly { get; set; }

[Value(0, Required = true, HelpText = "The src folder path to the books.")]
[Value(0, Required = true, HelpText = "The folder path to the books.")]
public required string SourcePath { get; set; }

[Value(1, Required = true, HelpText = "The folder path to the outpot.")]
public required string OutputPath { get; set; }
}
18 changes: 8 additions & 10 deletions src/generator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,18 @@ public Program(Options options)

private async Task BuildOutput(CancellationToken cancellation)
{
var outputRootFolder = Path.Combine(Path.GetDirectoryName(Options.SourcePath)!, "out");

if (Directory.Exists(outputRootFolder))
if (Directory.Exists(Options.OutputPath))
{
Directory.Delete(outputRootFolder, true);
Directory.Delete(Options.OutputPath, true);
}

Directory.CreateDirectory(outputRootFolder);
Directory.CreateDirectory(Options.OutputPath);

foreach (var language in Languages)
{
var templateDocument = GetHtmlDocument(Path.Combine(Options.SourcePath, language, "template.html"));

Directory.CreateDirectory(Path.Combine(outputRootFolder, language));
Directory.CreateDirectory(Path.Combine(Options.OutputPath, language));

if (!Options.IndexPagesOnly)
{
Expand All @@ -97,7 +95,7 @@ private async Task BuildOutput(CancellationToken cancellation)
var bookUrlName = pages[0].url;
var bookFolderName = Path.GetFileName(bookFolder);

CopyImages(outputRootFolder, language, bookFolderName, bookUrlName);
CopyImages(Options.OutputPath, language, bookFolderName, bookUrlName);

await Parallel.ForEachAsync(pages,
new ParallelOptions
Expand All @@ -111,7 +109,7 @@ await Parallel.ForEachAsync(pages,
{
try
{
var pageFolder = Path.Combine(outputRootFolder, language, page.url);
var pageFolder = Path.Combine(Options.OutputPath, language, page.url);

Directory.CreateDirectory(pageFolder);

Expand All @@ -127,10 +125,10 @@ await Parallel.ForEachAsync(pages,
}
}

ProcessPage("", "", ("Index", "index.html", ""), language, templateDocument, Path.Combine(outputRootFolder, language, "index.html"));
ProcessPage("", "", ("Index", "index.html", ""), language, templateDocument, Path.Combine(Options.OutputPath, language, "index.html"));
}

File.Copy(Path.Combine(outputRootFolder, "en", "index.html"), Path.Combine(outputRootFolder, "index.html"));
File.Copy(Path.Combine(Options.OutputPath, "en", "index.html"), Path.Combine(Options.OutputPath, "index.html"));
}

private void ProcessPage(string bookUrlName, string bookFolderName, (string title, string file, string url) page, string language, IHtmlDocument templateDocument, string destinationPath)
Expand Down
7 changes: 7 additions & 0 deletions static.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C39C4385-B04
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "generator", "src\generator\generator.csproj", "{95D21C85-6600-4F9D-867D-DDCA35C6D6B7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{094B90D9-73C3-452F-8FDC-E2B183C1A456}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
.github\workflows\main.yml = .github\workflows\main.yml
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down

0 comments on commit 271c8fd

Please sign in to comment.