forked from nota-game/nota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.wyam
970 lines (819 loc) · 32.9 KB
/
config.wyam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
// This directive installs packages from NuGet and it what yuo would normally use
// NOTE: If running the example against a downloaded version of Wyam, uncomment this line and comment the next line
// #a **\*
/* */
// #n Wyam.All -s https://www.myget.org/F/wyam/api/v2?package=Wyam&prerelease
#n Wyam.All
#n jQuery -v [2.2.3]
#n bootstrap -v [3.3.6]
#n MathJax -v [2.7.0]
// Declaration code
using AngleSharp.Dom;
using AngleSharp.Dom.Html;
using AngleSharp.Extensions;
using AngleSharp.Parser.Html;
using IDocument = Wyam.Common.Documents.IDocument;
public static class AutoLinkHelper
{
public static IEnumerable<string> GetKeywords(IDocument doc, params String[] keywords)
{
foreach (var keyword in keywords)
{
if(doc.Metadata.ContainsKey(keyword))
{
var metadata = doc[keyword];
var strings = metadata as String[];
if(strings != null)
foreach (var s in strings)
yield return s;
else
yield return metadata.ToString();
}
}
}
public static ILookup<string,IDocument> ToLookup(IExecutionContext ctx)
{
var erg = ctx.Documents
.FromPipeline("renderOutput") // Get documents from our current pipeline
.Select(x => AutoLinkHelper.GetKeywords(x,"Title","Alias")
.Select(y => new {Document = x, Keyword = y}))
.SelectMany(x=>x)
.ToLookup(x=> x.Keyword, x=> x.Document);
return erg;
}
public static IDocument[] AddImageMetadata(IDocument doc, IExecutionContext ctx)
{
// Alle Documente mit Xmp data finden:
var urlLookup = @ctx.Documents.FromPipeline("Write").Where(x=>x.ContainsKey("TargetUrl")).ToDictionary(x=> ((string)x["TargetUrl"]).Replace('\\','/'));
var parser = new AngleSharp.Parser.Html.HtmlParser();
//Source to be pared
var source = @doc.Content;
//Parse source to document
var document = parser.Parse(source);
//Do something with document like the following
var images = document.QuerySelectorAll("img");
foreach (var image in images)
{
var url = image.GetAttribute("src");
if(!urlLookup.ContainsKey(url))
continue;
var imgDoc = urlLookup[url];
String txt = "";
String title = null;
if(imgDoc.ContainsKey("RightsReserved"))
title = (bool.Parse(imgDoc["RightsReserved"].ToString())? "Urheberrechlich Geschützt" :"Gemeinfrei");
if(imgDoc.ContainsKey("Creator"))
txt +=$"<h4>{imgDoc["Creator"]}</h4>";
if(imgDoc.ContainsKey("Copyright"))
txt +=$"<p>{imgDoc["Copyright"]}</p>";
image.SetAttribute("data-toggle","popover");
image.SetAttribute("data-html","true");
image.SetAttribute("data-placement","auto");
image.SetAttribute("data-trigger","click focus");
if(title!=null)
image.SetAttribute("title",title);
image.SetAttribute("data-content", txt);
}
return new IDocument[]{@ctx.GetDocument(doc, @ctx.GetContentStream(document.DocumentElement.OuterHtml))};
}
public static IDocument[] AddClassToTable(IDocument doc, IExecutionContext ctx)
{
var parser = new AngleSharp.Parser.Html.HtmlParser();
//Source to be pared
var source = @doc.Content;
//Parse source to document
var document = parser.Parse(source);
//Do something with document like the following
var tables = document.QuerySelectorAll("table");
foreach (var table in tables)
{
var url = table.GetAttribute("class");
if(!String.IsNullOrEmpty(url))
continue;
table.SetAttribute("class", "table");
}
return new IDocument[]{@ctx.GetDocument(doc,@ctx.GetContentStream(document.DocumentElement.OuterHtml))};
}
public static IDocument[] FixLink(IDocument doc, IExecutionContext ctx)
{
var parser = new AngleSharp.Parser.Html.HtmlParser();
//Source to be pared
var source = @doc.Content;
//Parse source to document
var document = parser.Parse(source);
//Do something with document like the following
var tables = document.QuerySelectorAll("a");
foreach (var table in tables)
{
var url = table.GetAttribute("href");
if(String.IsNullOrEmpty(url))
continue;
var toSubstitude = new char[]{'ä','ö','ü','Ä','Ö','Ü','ß'};
foreach(var c in toSubstitude)
{
var escapeString = Uri.HexEscape(c);
url = url.Replace(c.ToString(),escapeString);
}
if(!Uri.IsWellFormedUriString(url, UriKind.Relative))
continue;
var extension = System.IO.Path.GetExtension(url);
if(extension == ".cshtml"
|| extension == ".md")
url = System.IO.Path.ChangeExtension(url ,".html");
table.SetAttribute("href", url);
}
return new IDocument[]{@ctx.GetDocument(doc,@ctx.GetContentStream(document.DocumentElement.OuterHtml))};
}
public static void ClearLookups()
{
externalUrlPathLoockup.Clear();
}
private static Dictionary<string, string> externalUrlPathLoockup = new Dictionary<string, string>();
public static IDocument[] DownloadExternaResourcs(IDocument doc, IExecutionContext ctx)
{
var parser = new AngleSharp.Parser.Html.HtmlParser();
//Source to be pared
var source = @doc.Content;
//Parse source to document
var document = parser.Parse(source);
//Do something with document like the following
var list = new List<IDocument>();
var images = document.QuerySelectorAll("img");
foreach (var image in images)
{
var url = image.GetAttribute("src");
// Console.WriteLine(image.OuterHtml);
if(String.IsNullOrEmpty(url))
continue;
if(!Uri.IsWellFormedUriString(url, UriKind.Absolute))
continue;
if(url.StartsWith("https://" + Constants.SiteURL)|| url.StartsWith("http://" + Constants.SiteURL))
continue;
if(externalUrlPathLoockup.ContainsKey(url))
url = externalUrlPathLoockup[url];
else
{
var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
string extension;
var response = request.GetResponse();
switch (response.ContentType)
{
case "image/png":
extension = ".png";
break;
case "image/jpeg":
extension = ".jpg";
break;
case "image/svg+xml":
extension = ".svg";
break;
default:
Console.WriteLine("Unsupported ContentType: " + response.ContentType + " " + url);
extension = "";
break;
}
var memoryStream = new System.IO.MemoryStream();
using (var responseStream = response.GetResponseStream())
responseStream.CopyTo(memoryStream);
memoryStream.Seek(0, System.IO.SeekOrigin.Begin);
var internalUrl = "image/external/"+ Guid.NewGuid()+ extension;
externalUrlPathLoockup.Add(url,internalUrl);
url = internalUrl;
var filePath = @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).CombineFile( new FilePath(url, PathKind.Relative));
var imageDocument = ctx.GetDocument(memoryStream, new []{new KeyValuePair<string,object>("RelativeFilePath",filePath) } ,true);
list.Add(imageDocument);
}
image.SetAttribute("src", "/"+url);
}
list.Add(@ctx.GetDocument(doc,@ctx.GetContentStream(document.DocumentElement.OuterHtml)));
return list.ToArray();
}
}
public static class Constants
{
public static string ProjectName {get; }= "nota";
public static string SiteURL => GitBranch == "master" ? "nota-game.azurewebsites.net" : "nota-dev.azurewebsites.net";
public static string GitUrl {get; }= Environment.GetEnvironmentVariable("GIT_URL")?? "https://github.com/nota-game/nota";
public static string GitBranch {get; }= Environment.GetEnvironmentVariable("GIT_BRANCH")?? "master";
const string timeZoneZerilisation = "W. Europe Standard Time;60;(UTC+01:00) Amsterdam, Berlin, Bern, Rom, Stockholm, Wien;Mitteleuropäische Zeit;Mitteleuropäische Sommerzeit;[01:01:0001;12:31:9999;60;[0;02:00:00;3;5;0;];[0;03:00:00;10;5;0;];];";
public static TimeZoneInfo TimeZone {get; } = TimeZoneInfo.FromSerializedString(timeZoneZerilisation);
}
public static class Helper
{
public static IModule TargetUrlModule()
{
return new Meta("RelativeFilePath", (@doc, @ctx)=>
{
var targetFile = (Wyam.Common.IO.FilePath)@doc["RelativeFilePath"];
string url;
if(targetFile.FileName.FullPath == "index.html")
url = targetFile.Directory.FullPath;
else
url = targetFile.FullPath;
url = "\\"+url;
url = url.Replace('\\','/');
url = url.Replace("//","/");
return new FilePath(url, PathKind.Relative);
});
}
public static IModule ChangeExtension(string newExtension)
{
return new Execute((@doc, @ctx)=>
{
return new IDocument[] {@ctx.GetDocument(doc, doc.Source, new KeyValuePair<string, object>[]{new KeyValuePair<string, object>("RelativeFilePath",((FilePath)@doc["RelativeFilePath"]).ChangeExtension(newExtension))} )};
});
}
public static bool IsExtension(IDocument document , string newExtension)
{
return ((FilePath)document["RelativeFilePath"]).Extension== newExtension;
}
public static IModule FixSkillChecks(){
return new Replace(@"(?<first>\p{Lu}{2})/(?<seccond>\p{Lu}{2})/(?<third>\p{Lu}{2})", @"${first}/${seccond}/${third}").IsRegex(System.Text.RegularExpressions.RegexOptions.None);
}
}
// Auf deutsche Kultur einstellen ( zur Compilezeit)
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = System.Globalization.CultureInfo.GetCultureInfo("de-DE");
IExecutionContext currentContext = null;
Pipelines.Add("books",
ReadFiles(@"books\**\*.{*,!xsd,!meta}"),
FrontMatter(Yaml()),
Sidecar(Yaml()),
DirectoryMeta()
.WithMetadataFile(".inherited",true),
/// ID for later reference in Replace ///
Meta("ID",(@doc, @ctx)=>
{
var path = (Wyam.Common.IO.FilePath)@doc["RelativeFilePath"];
if(path.Directory.Name == path.FileNameWithoutExtension.ToString())
return path.Directory.ToString();
path = path.ChangeExtension("");
return path.Directory.CombineFile(path.FileNameWithoutExtension).ToString();
}),
/// Neded for git modules and history ///
Meta("OriginalSource", @doc.Source),
/// XLSX ///
If(@doc.Source.Extension==".xlsx",
ExcelToCsv(),
CsvToMarkdown()
.WithHeader(),
Helper.ChangeExtension(".md")
),
/// XSLT ///
If(@doc.Source.Extension==".xslt",
Meta("src", @doc.Source),
If(@doc.Metadata.ContainsKey("data"),
Content(System.IO.File.ReadAllText((string)@doc["data"])),
Xslt2(@doc["src"])
).ElseIf(!@doc.Metadata.ContainsKey("data"),
Trace("Faild data Metadata on"+ @doc.Source)
),
Helper.ChangeExtension(".md")
),
Execute(context=> {currentContext = context;}),
/// TODO: Replace (including md files into another) ///
If((@doc["RelativeFilePath"] as FilePath).Extension==".md",
Replace("§\"(?<id>[^\"]+)\"", match =>
{
var id = match.Groups["id"].Value;
// var p = currentContext["books"];
//System.Linq.Enumerable.FirstOrDefault();
var referencedDocument = currentContext.Documents.FromPipeline("books").FirstOrDefault(d=> d.Metadata.String("ID", null) == id);
// var test = currentContext.Documents.FromPipeline("books").Select(d=> d.Metadata.String("ID", null));
return referencedDocument?.Content ?? "[Error refference not found]";
}
),
Helper.FixSkillChecks(),
Prepend(ReadFiles(@"template\markdownPrämable.md"))
),
/// TODO: Filter Content that will not be shown (already included) ///
/// BOOKS ///
If( @doc.Metadata.ContainsKey("BookType"),
Meta("IsBook", true)
),
/// Adding Tree ///
If(@doc.Metadata.Bool("hide", false)),
Tree()
.WithRoots(@doc.Get<bool>("IsBook"))
.WithTreePath(((string)@doc["ID"]).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries))
.WithSort((x1,x2)=> x1.Get<int>("Order",int.MaxValue).CompareTo(x2.Get<int>("Order",int.MaxValue)))
);
Pipelines.Add("WriteMarkDown",
Documents("books"),
WriteFiles( new DirectoryPath("MarkDown",PathKind.Relative).CombineFile((FilePath)@doc["RelativeFilePath"]))
);
/// TODO: HTML Pieplines ///
Pipelines.Add("MainMenue",
ReadFiles(@"render\**\*.{*,!xsd,!meta}"),
FrontMatter(Yaml()),
Sidecar(Yaml()),
DirectoryMeta()
.WithMetadataFile(".inherited",true),
Meta("RelativeFilePath", (@doc, @ctx)=>
{
var path = ((Wyam.Common.IO.DirectoryPath)"render").GetRelativePath((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]);
return path;
}),
OrderBy(@doc.Metadata.Get<int>("Order",-1))
);
Pipelines.Add("htmlBooksPrepare",
Documents("books"),
If(@doc.Source != null,
GitContributors()
.ForEachInputDocument(),
// Meta("RelativeFilePath", (@doc, @ctx)=>
// {
// var path = (Wyam.Common.IO.FilePath)@doc["RelativeFilePath"];
// if(path.Directory.Name == path.FileNameWithoutExtension.ToString())
// path = path.Directory.CombineFile("index" + path.Extension);
// return path;
// }),
Meta("ReposetoryUrl", (@doc, @ctx)=>
{
//https://github.com/LokiMidgard/nota/edit/master/input/render/Downloads.md
var url = $"{Constants.GitUrl}/edit/{Constants.GitBranch}/input/"+ ((Wyam.Common.IO.FilePath)@doc.Source).FullPath;
return url;
})
)
);
Pipelines.Add("htmlBootstrap",
ReadFiles(@"Scripts\**\*.*"),
Concat(
ReadFiles(@"Content\**\*.*")
),
Concat(
ReadFiles(@"fonts\**\*.*")
)
);
Pipelines.Add("htmlStatic",
ReadFiles(@"static\**\*.*"),
Meta("RelativeFilePath", (@doc, @ctx)=>
{
var path = ((Wyam.Common.IO.DirectoryPath)"static").GetRelativePath((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]);
return path;
}),
Where(@doc.Source.Extension != ".xmp"),
Xmp(errorsOnDoubleKeys:false)
.WithMetadata("cc:license", "Copyright")
.WithMetadata("xmpRights:UsageTerms", "Copyright")
.WithMetadata("dc:rights", "Copyright")
.WithMetadata("dc:creator", "Creator")
.WithMetadata("cc:attributionName", "Creator")
.WithMetadata("xmpRights:Marked", "RightsReserved"),
If(((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).Extension != ".css"
&& ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).Extension != ".js"
&& ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).Extension != ".xsd"
&& ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).Extension != ".xml"
&& ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).Extension != ".config",
If(@doc.Get<string>("RightsReserved")!= "False",
If((!@doc.ContainsKey("Copyright"))
|| !@doc.ContainsKey("Creator"),
Trace($"Missing License Information {@doc.Source}"),
Where((@doc,@ctx)=> false)
)
)
),
If(@doc.Source.Extension == ".xsd",
Replace("http://nota.org/", $"http://{Constants.SiteURL}/"),
Replace("schemaLocation=\"(\\.\\./)+", $"schemaLocation=\"").IsRegex(System.Text.RegularExpressions.RegexOptions.Multiline),
Replace("schemaLocation=\"", $"schemaLocation=\"http://{Constants.SiteURL}/schema/")
),
If(@doc.Source.Extension == ".xml",
Replace("http://nota.org/", $"http://{Constants.SiteURL}/"),
Replace("(?<=schemaLocation=\"[^\"]*)(\\.\\./)+", $"").IsRegex(System.Text.RegularExpressions.RegexOptions.Singleline),
Replace("(?<=schemaLocation=\"[^\"]*) (?<location>schema/[^\" ]*)", $@" http://{Constants.SiteURL}/${{location}}").IsRegex(System.Text.RegularExpressions.RegexOptions.Singleline)
)
);
Pipelines.Add("authorPages",
GitContributors(),
Meta("RelativeFilePath", @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).GetRelativePath( @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).Combine( new Wyam.Common.IO.DirectoryPath("author")).CombineFile((string)@doc["ContributorEmail"]+".html").ChangeExtension(".cshtml"))),
Meta("Title", @doc["ContributorName"]),
Meta("Layout", @"twoColumns.cshtml"),
Content(
ReadFiles(@"template\author.cshtml")
),
ConcatBranch(
Execute((@doc, @ctx)=>{
var information = @doc["Commits"] as IEnumerable<IDocument>;
var fileCommits = information
.SelectMany(x=> (x["Entries"] as IReadOnlyDictionary<Wyam.Common.IO.FilePath, string>)
.Select(entry => new { Entry = entry, Commit = x}))
.GroupBy(x=>x.Entry.Key);
return (IEnumerable<IDocument>) fileCommits.Select(x=>
{
var autherFolder = @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).Combine( new Wyam.Common.IO.DirectoryPath("author"));
var emailFolder = autherFolder.Combine(new Wyam.Common.IO.DirectoryPath((string)@doc["ContributorEmail"]));
var commitetFile = emailFolder.CombineFile(x.Key);
var targetFile = commitetFile.AppendExtension(".cshtml");
targetFile = @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).GetRelativePath( targetFile );
var commits = x.ToDictionary(y=> y.Commit, y=>y.Entry.Value).ToArray();
return @ctx.GetDocument(new KeyValuePair<string,object>[]
{
new KeyValuePair<string,object>("Title", x.Key.ToString()),
new KeyValuePair<string,object>("ContributorName", @doc["ContributorName"]),
new KeyValuePair<string,object>("ContributorEmail", @doc["ContributorEmail"]),
new KeyValuePair<string,object>("ContributorSite", @doc["RelativeFilePath"]),
new KeyValuePair<string,object>("RelativeFilePath", targetFile),
new KeyValuePair<string,object>("Commits", commits),
new KeyValuePair<string,object>("Path", x.Key),
});
});
}),
Content(
ReadFiles(@"template\CommitFile.cshtml")
)
),
Execute(new IDocument[]{ @ctx.GetDocument(doc,@ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).CombineFile( ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).ChangeExtension( ".cshtml")), @ctx.GetContentStream(@doc.Content))})
);
Pipelines.Add("convertAIFiles",
ReadFiles(@"misc\documents\source\**\*.ai"),
Meta("RelativeFilePath", ((DirectoryPath) @"downloads").CombineFile(((DirectoryPath) @"misc\documents\source").GetRelativePath( (FilePath)@doc["RelativeFilePath"]).ChangeExtension(".pdf")))
);
Pipelines.Add("beforeHtmlWrite",
Documents("htmlBooksPrepare"),
Concat(
Documents("htmlBootstrap")
),
Concat(
Documents("convertAIFiles")
),
Concat(
Documents("MainMenue")
),
Concat(
Documents("htmlStatic")
),
If(@doc.Source != null,
GitContributors()
.ForEachInputDocument(),
Meta("ReposetoryUrl", (@doc, @ctx)=>
{
//https://github.com/LokiMidgard/nota/edit/master/input/render/Downloads.md
var relativPath = @ctx.FileSystem.RootPath.Combine("input").GetRelativePath((Wyam.Common.IO.FilePath)@doc.Source);
var url = $"{Constants.GitUrl}/edit/{Constants.GitBranch}/input/"+ relativPath.FullPath;
return url;
}),
Meta("ReposetoryHistoryUrl", (@doc, @ctx)=>
{
//https://github.com/LokiMidgard/nota/commits/master/input/books/Regelwerke/Grundregeln/Grundregeln.md
var relativPath = @ctx.FileSystem.RootPath.Combine("input").GetRelativePath((Wyam.Common.IO.FilePath)@doc.Source);
var url = $"{Constants.GitUrl}/commits/{Constants.GitBranch}/input/"+ relativPath.FullPath;
return url;
})
),
Concat(
Documents("authorPages")
)
);
Pipelines.Add("htmlWrite",
Documents("beforeHtmlWrite"),
Where(!@doc.Metadata.Bool("hide", false)),
Where(@doc.Source != null),
If(Helper.IsExtension(@doc, ".md"),
Markdown()
// .UseConfiguration("mathematics")
// .UseConfiguration("DisableHtml")
.UseExtensions(),
Helper.ChangeExtension(".cshtml")
),
If(Helper.IsExtension(@doc, ".cshtml"),
Razor().WithViewStart(@"layout/viewstart.cshtml"),
Helper.ChangeExtension(".html")
),
If(Helper.IsExtension(@doc, ".html"),
// Execute(AutoLinkHelper.AddImageMetadata),
Execute(AutoLinkHelper.AddClassToTable),
Execute(AutoLinkHelper.FixLink),
HtmlEscape().WithEscapedChar('ä','ö','ü','Ä','Ö','Ü','ß'),
Execute((IExecutionContext xtf)=> AutoLinkHelper.ClearLookups()),
Execute(AutoLinkHelper.DownloadExternaResourcs, parallel: false) // this must be the last. It creates additional Image documenttes we may not manipulate those.
),
// Trace(@doc["RelativeFilePath"]),
WriteFiles()
);
// If(@doc.Source.Extension==".md"
// || @doc.Source.Extension==".cshtml"
// || @doc.Source.Extension==".xslt"
// || @doc.Source.Extension==".xlsx"
// || @doc.Source.Extension==".xml",
// Razor().WithViewStart(@"layout/viewstart.cshtml"),
// Execute(AutoLinkHelper.AddClassToTable)
// ),
// AutoLink((IDictionary<string,string>)AutoLinkHelper.ToLookup(@ctx) // Use our new ToLookup extension
// .ToDictionary(x => x.Key,
// x => (string)x.OrderBy(y=>y.ContainsKey("IsDisambigiusPage") ? 0 : 1).First()["TargetUrl"]) )
// .WithMatchOnlyWholeWord(),
// If(((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension==".html",
// Execute(AutoLinkHelper.AddImageMetadata),
// HtmlEscape().WithEscapedChar('ä','ö','ü','Ä','Ö','Ü','ß')
// ),
// Concat(
// Documents("staticOutput")
// ),
// // Trace(@doc["TargetFile"]),
// WriteFiles( @doc["TargetFile"])
// );
/// TODO: PDF Pieplines ///
/// OLD
// Pipelines.Add("renderInput",
// ReadFiles(@"render\**\*.{*,!xsd,!meta}"),
// FrontMatter(Yaml()),
// Sidecar(Yaml()),
// GitContributors()
// .ForEachInputDocument(),
// DirectoryMeta()
// .WithMetadataFile(".inherited",true),
// Meta("TargetFile", (@doc, @ctx)=>
// {
// var path = ((Wyam.Common.IO.DirectoryPath)"render").GetRelativePath((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]);
// if(path.Directory.Name == path.FileNameWithoutExtension.ToString())
// path = path.Directory.CombineFile("index" + path.Extension);
// if(path.Extension == ".md"
// || path.Extension == ".cshtml"
// || path.Extension == ".xslt"
// || path.Extension == ".xlsx"
// || path.Extension == ".xml")
// path= path.ChangeExtension(".html");
// return path;
// }),
// Helper.TargetUrlModule(),
// Meta("ReposetoryUrl", (@doc, @ctx)=>
// {
// //https://github.com/LokiMidgard/nota/edit/master/input/render/Downloads.md
// var url = $"{Constants.GitUrl}/edit/{Constants.GitBranch}/input/"+ ((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]).FullPath;
// return url;
// })
// );
// Pipelines.Add("staticInput",
// ReadFiles(@"static\**\*.*"),
// Meta("TargetFile", (@doc, @ctx)=>
// {
// var path = ((Wyam.Common.IO.DirectoryPath)"static").GetRelativePath((Wyam.Common.IO.FilePath)@doc["RelativeFilePath"]);
// return path;
// }),
// Helper.TargetUrlModule(),
// Where(@doc.Source.Extension != ".xmp"),
// Xmp(errorsOnDoubleKeys:false)
// .WithMetadata("cc:license", "Copyright")
// .WithMetadata("xmpRights:UsageTerms", "Copyright")
// .WithMetadata("dc:rights", "Copyright")
// .WithMetadata("dc:creator", "Creator")
// .WithMetadata("cc:attributionName", "Creator")
// .WithMetadata("xmpRights:Marked", "RightsReserved"),
// If(((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension != ".css"
// && ((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension != ".js"
// && ((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension != ".xsd"
// && ((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension != ".xml"
// && ((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension != ".config",
// If(@doc.Get<string>("RightsReserved")!= "False",
// If((!@doc.ContainsKey("Copyright"))
// || !@doc.ContainsKey("Creator"),
// Trace($"Missing License Information {@doc.Source}"),
// Where((@doc,@ctx)=> false)
// )
// )
// ),
// Replace("http://nota.org/", $"http://{Constants.SiteURL}/")
// );
// // 888888888888 ad88
// // 88 d8"
// // 88 88
// // 88 8b,dPPYba, ,adPPYYba, 8b,dPPYba, ,adPPYba, MM88MMM ,adPPYba, 8b,dPPYba, 88,dPYba,,adPYba,
// // 88 88P' "Y8 "" `Y8 88P' `"8a I8[ "" 88 a8" "8a 88P' "Y8 88P' "88" "8a
// // 88 88 ,adPPPPP88 88 88 `"Y8ba, 88 8b d8 88 88 88 88
// // 88 88 88, ,88 88 88 aa ]8I 88 "8a, ,a8" 88 88 88 88
// // 88 88 `"8bbdP"Y8 88 88 `"YbbdP"' 88 `"YbbdP"' 88 88 88 88
// Pipelines.Add("bootstrapOutput",
// ReadFiles(@"Scripts\**\*.*"),
// Concat(
// ReadFiles(@"Content\**\*.*")
// ),
// Concat(
// ReadFiles(@"fonts\**\*.*")
// ),
// Meta("TargetFile", (@doc, @ctx)=>
// {
// return @doc["RelativeFilePath"];
// })
// );
// Pipelines.Add("authorOutput",
// GitContributors(),
// Meta("TargetFile", @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).GetRelativePath( @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).Combine( new Wyam.Common.IO.DirectoryPath("author")).CombineFile((string)@doc["ContributorEmail"]+".html").ChangeExtension(".html"))),
// Meta("Title", @doc["ContributorName"]),
// Meta("Layout", @"book.cshtml"),
// Content(
// ReadFiles(@"template\author.cshtml")
// ),
// ConcatBranch(
// Execute((@doc, @ctx)=>{
// var information = @doc["Commits"] as IEnumerable<IDocument>;
// var fileCommits = information
// .SelectMany(x=> (x["Entries"] as IReadOnlyDictionary<Wyam.Common.IO.FilePath, string>)
// .Select(entry => new { Entry = entry, Commit = x}))
// .GroupBy(x=>x.Entry.Key);
// return (IEnumerable<IDocument>) fileCommits.Select(x=>
// {
// var autherFolder = @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).Combine( new Wyam.Common.IO.DirectoryPath("author"));
// var emailFolder = autherFolder.Combine(new Wyam.Common.IO.DirectoryPath((string)@doc["ContributorEmail"]));
// var commitetFile = emailFolder.CombineFile(x.Key);
// var targetFile = commitetFile.AppendExtension(".html");
// targetFile = @ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).GetRelativePath( targetFile );
// var commits = x.ToDictionary(y=> y.Commit, y=>y.Entry.Value).ToArray();
// return @ctx.GetDocument(new KeyValuePair<string,object>[]
// {
// new KeyValuePair<string,object>("Title", x.Key.ToString()),
// new KeyValuePair<string,object>("ContributorName", @doc["ContributorName"]),
// new KeyValuePair<string,object>("ContributorEmail", @doc["ContributorEmail"]),
// new KeyValuePair<string,object>("ContributorSite", @doc["TargetFile"]),
// new KeyValuePair<string,object>("TargetFile", targetFile),
// new KeyValuePair<string,object>("Commits", commits),
// new KeyValuePair<string,object>("Path", x.Key),
// });
// });
// }),
// Content(
// ReadFiles(@"template\CommitFile.cshtml")
// )
// ),
// Helper.TargetUrlModule(),
// Execute(new IDocument[]{ @ctx.GetDocument(doc,@ctx.FileSystem.RootPath.Combine(@ctx.FileSystem.OutputPath).CombineFile( ((Wyam.Common.IO.FilePath)@doc["TargetFile"]).ChangeExtension( ".cshtml")),@doc.Content)})
// );
// Pipelines.Add("renderOutput",
// Documents("renderInput"),
// Concat(
// Execute((@ctx)=>
// {
// var ambigiusElements = AutoLinkHelper.ToLookup(@ctx).Where(x=> x.Skip(1).Any());
// var list = new List<IDocument>();
// foreach (var a in ambigiusElements)
// {
// list.Add(@ctx.GetDocument(
// @"\ambiguis\"+a.Key + ".cshtml",
// "",
// new KeyValuePair<string,object>[]{
// new KeyValuePair<string,object>("DisambigiusData", a),
// new KeyValuePair<string,object>("Keyword", a.Key),
// new KeyValuePair<string,object>("Alias", a.Key),
// new KeyValuePair<string,object>("Documents", a),
// new KeyValuePair<string,object>("IsDisambigiusPage", true),
// }));
// }
// return list;
// }),
// Meta("TargetFile", new Wyam.Common.IO.DirectoryPath("ambiguis").CombineFile(@doc["Keyword"]+".html")),
// Meta("Title", "begriffsklärung "+ @doc["Keyword"]),
// Helper.TargetUrlModule(),
// Content(
// ReadFiles(@"template\ambiguis.cshtml")
// )
// ),
// /// XLSX ///
// If(@doc.Source.Extension==".xlsx",
// ExcelToCsv(),
// CsvToHtml()
// .WithHeader()
// ),
// /// XSLT ///
// If(@doc.Source.Extension==".xslt",
// Meta("src", @doc.Source),
// If(@doc.Metadata.ContainsKey("data"),
// Content(System.IO.File.ReadAllText((string)@doc["data"])),
// Xslt2(@doc["src"])
// ).ElseIf(!@doc.Metadata.ContainsKey("data"),
// Trace("Faild data Metadata on"+ @doc.Source)
// )
// ),
// /// BOOKS ///
// If( @doc.Metadata.ContainsKey("BookType"),
// Meta("IsBook", true)
// ),
// /// Adding Tree ///
// Tree()
// .WithRoots(@doc.Get<bool>("IsBook"))
// .WithTreePath(((string)@doc["TargetUrl"]).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries))
// .WithSort((x1,x2)=> x1.Get<int>("Order",int.MaxValue).CompareTo(x2.Get<int>("Order",int.MaxValue))),
// Where(@doc.Source != null), // Removing generated Documents...
// Execute((ctx)=>{ // append to previous document
// var list = new List<IDocument>(ctx.Documents.FromPipeline("renderOutput"));
// bool foundAppend;
// do
// {
// foundAppend=false;
// for (int i = list.Count - 1; i >= 0 ; i--)
// {
// var doc = list[i];
// if(doc.Metadata.ContainsKey("append")
// && bool.Parse(doc["append"].ToString()))
// {
// foundAppend=true;
// var nextDoc = doc;
// var docToAppend = nextDoc;
// do{
// docToAppend = nextDoc;
// nextDoc = docToAppend.Metadata.Get<IDocument>("Next");
// }while(nextDoc!=null
// && nextDoc.Metadata.ContainsKey("append")
// && bool.Parse(nextDoc["append"].ToString()));
// do{
// var docToAppendTo = docToAppend.Metadata.Get<IDocument>("Previous");
// if(docToAppendTo== null)
// break;
// var index = list.IndexOf(docToAppendTo);
// var newDoc = list[index] = ctx.GetDocument(docToAppendTo,docToAppendTo.Source, docToAppendTo.Content + "\n" + docToAppend.Content);
// list.Remove(docToAppend);
// docToAppend =newDoc;
// }while(docToAppend.Metadata.ContainsKey("append")
// && bool.Parse(docToAppend["append"].ToString()));
// break;
// }
// }
// }while(foundAppend);
// return list;
// }),
// /// Adding Tree Againe ...///
// Tree()
// .WithRoots(@doc.Get<bool>("IsBook"))
// .WithTreePath(((string)@doc["TargetUrl"]).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries))
// .WithSort((x1,x2)=> x1.Get<int>("Order",int.MaxValue).CompareTo(x2.Get<int>("Order",int.MaxValue))),
// /// Chapters ///
// If(@doc.Metadata.ContainsKey("Parent"),
// Meta("ParentBook", (@doc, @ctx)=>{
// var parent = @doc;
// while (parent.Get<IDocument>("Parent")!=null)
// {
// parent = parent.Get<IDocument>("Parent");
// }
// return parent;
// })
// )
// );
// Pipelines.Add("staticOutput",
// Documents("staticInput")
// );
// Pipelines.Add("output",
// Documents("renderOutput"),
// Concat(
// Documents("bootstrapOutput")
// ),
// Concat(
// Documents("authorOutput")
// )
// );
// // 88 88
// // 88 88
// // 88 88
// // 88 ,adPPYba, ,adPPYba, 88 ,d8 88 88 8b,dPPYba, ,adPPYba,
// // 88 a8" "8a a8" "8a 88 ,a8" 88 88 88P' "8a I8[ ""
// // 88 8b d8 8b d8 8888[ 88 88 88 d8 `"Y8ba,
// // 88 "8a, ,a8" "8a, ,a8" 88`"Yba, "8a, ,a88 88b, ,a8" aa ]8I
// // 88888888888 `"YbbdP"' `"YbbdP"' 88 `Y8a `"YbbdP'Y8 88`YbbdP"' `"YbbdP"'
// // 88
// // 88
// Pipelines.Add("Books",
// Documents("renderOutput").Where(@doc.Get<bool>("IsBook") )
// );
// Pipelines.Add("MainMenue",
// Documents("output").Where( (@doc, @ctx)=>
// {
// return @doc.Metadata.ContainsKey("MainMenueOrder");
// }),
// OrderBy(@doc["MainMenueOrder"])
// );
// // I8, 8 ,8I 88
// // `8b d8b d8' "" ,d
// // "8, ,8"8, ,8" 88
// // Y8 8P Y8 8P 8b,dPPYba, 88 MM88MMM ,adPPYba,
// // `8b d8' `8b d8' 88P' "Y8 88 88 a8P_____88
// // `8a a8' `8a a8' 88 88 88 8PP"""""""
// // `8a8' `8a8' 88 88 88, "8b, ,aa
// // `8' `8' 88 88 "Y888 `"Ybbd8"'
// Pipelines.Add("Write",
// Documents("output"),
// Where(@doc.Source != null),
// If(@doc.Source.Extension==".md",
// Markdown()
// .UseExtensions()
// // .UseConfiguration("DisableHtml")
// ),
// If(@doc.Source.Extension==".md"
// || @doc.Source.Extension==".cshtml"
// || @doc.Source.Extension==".xslt"
// || @doc.Source.Extension==".xlsx"
// || @doc.Source.Extension==".xml",
// Razor().WithViewStart(@"layout/viewstart.cshtml"),
// Execute(AutoLinkHelper.AddClassToTable)
// ),
// AutoLink((IDictionary<string,string>)AutoLinkHelper.ToLookup(@ctx) // Use our new ToLookup extension
// .ToDictionary(x => x.Key,
// x => (string)x.OrderBy(y=>y.ContainsKey("IsDisambigiusPage") ? 0 : 1).First()["TargetUrl"]) )
// .WithMatchOnlyWholeWord(),
// If(((Wyam.Common.IO.FilePath)@doc["TargetFile"]).Extension==".html",
// Execute(AutoLinkHelper.AddImageMetadata),
// HtmlEscape().WithEscapedChar('ä','ö','ü','Ä','Ö','Ü','ß')
// ),
// Concat(
// Documents("staticOutput")
// ),
// // Trace(@doc["TargetFile"]),
// WriteFiles( @doc["TargetFile"])
// );