Skip to content

Commit a37f3c3

Browse files
committed
Move PageLinks down.
1 parent 11b0d44 commit a37f3c3

3 files changed

Lines changed: 23 additions & 23 deletions

File tree

converter/generator/DocBookTransformer.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Diagnostics;
2-
using System.Xml.Linq;
1+
using System.Xml.Linq;
32
using AngleSharp.Dom;
43
using AngleSharp.Html.Dom;
54
using OriginLab.DocumentGeneration.Templates;

converter/generator/DocToStaticPagesTransformer.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Buffers;
22
using System.Net;
3+
using System.Xml.Linq;
34
using AngleSharp.Dom;
45
using AngleSharp.Html.Dom;
56
using AngleSharp.Html.Parser;
@@ -11,6 +12,8 @@ internal abstract partial class DocToStaticPagesTransformer : DocTransformer
1112
{
1213
public const int MaxSiblingNodes = 10 * 2;
1314

15+
private readonly Dictionary<string, (string book, string url, string titleEn)> PageLinks;
16+
1417
private readonly bool UseWebp;
1518

1619
#region Language specific members
@@ -25,6 +28,25 @@ internal abstract partial class DocToStaticPagesTransformer : DocTransformer
2528

2629
protected DocToStaticPagesTransformer(DocToStaticPagesTransformerArgs args, ProblemRecorder problems) : base(args, problems)
2730
{
31+
var pages = new List<(string file, string book, string url, string title)>();
32+
33+
foreach (var xmlFile in Directory.EnumerateFiles(BooksXmlFolder, "*.xml"))
34+
{
35+
var dirName = Path.GetFileNameWithoutExtension(xmlFile);
36+
37+
foreach (var p in XElement.Load(xmlFile).Descendants("page"))
38+
{
39+
var file = $"{dirName}/{p.Attribute("file")!.Value}";
40+
var url = p.Attribute("url")!.Value;
41+
var sep = url.IndexOf('/');
42+
var title = p.Attribute("title")!.Value;
43+
44+
pages.Add((file, book: sep < 0 ? url : url[..sep], url: sep < 0 ? "" : url[(sep + 1)..], title));
45+
}
46+
}
47+
48+
PageLinks = pages.ToDictionary(p => p.file, p => (p.book.ToLowerInvariant(), p.url.ToLowerInvariant(), p.title), StringComparer.OrdinalIgnoreCase);
49+
2850
UseWebp = args.UseWebp;
2951
}
3052

converter/generator/DocTransformer.cs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ internal abstract partial class DocTransformer : IDocTransformer
2222

2323
protected string[] AvailableLanguages { get; }
2424

25-
protected readonly Dictionary<string, (string book, string url, string titleEn)> PageLinks;
26-
2725
protected Dictionary<string, string> MovedPages => field ??= GetMovedPages();
2826

2927
protected static Dictionary<string, string> SharedImages => field ??= GetSharedImages();
@@ -63,25 +61,6 @@ protected DocTransformer(DocTransformerArgs args, ProblemRecorder problems)
6361
}
6462

6563
AvailableLanguages = languages;
66-
67-
var pages = new List<(string file, string book, string url, string title)>();
68-
69-
foreach (var xmlFile in Directory.EnumerateFiles(booksXmlFolder, "*.xml"))
70-
{
71-
var dirName = Path.GetFileNameWithoutExtension(xmlFile);
72-
73-
foreach (var p in XElement.Load(xmlFile).Descendants("page"))
74-
{
75-
var file = $"{dirName}/{p.Attribute("file")!.Value}";
76-
var url = p.Attribute("url")!.Value;
77-
var sep = url.IndexOf('/');
78-
var title = p.Attribute("title")!.Value;
79-
80-
pages.Add((file, book: sep < 0 ? url : url[..sep], url: sep < 0 ? "" : url[(sep + 1)..], title));
81-
}
82-
}
83-
84-
PageLinks = pages.ToDictionary(p => p.file, p => (p.book.ToLowerInvariant(), p.url.ToLowerInvariant(), p.title), StringComparer.OrdinalIgnoreCase);
8564
}
8665

8766
private Dictionary<string, string> GetMovedPages()

0 commit comments

Comments
 (0)