|
1 | 1 | using FluentValidation;
|
2 | 2 | using FluentValidation.AspNetCore;
|
3 |
| -using Ganss.XSS; |
| 3 | +using Ganss.Xss; |
4 | 4 | using HtmlBuilders;
|
5 | 5 | using LiteDB;
|
6 | 6 | using Markdig;
|
@@ -272,7 +272,7 @@ static string RenderMarkdown(string str)
|
272 | 272 |
|
273 | 273 | static string RenderDeletePageButton(Page page, AntiforgeryTokenSet antiForgery)
|
274 | 274 | {
|
275 |
| - var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken); |
| 275 | + var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken!); |
276 | 276 | HtmlTag id = Input.Hidden.Name("Id").Value(page.Id.ToString());
|
277 | 277 | var submit = Div.Style("margin-top", "20px").Append(Button.Class("uk-button uk-button-danger").Append("Delete Page"));
|
278 | 278 |
|
@@ -306,7 +306,7 @@ HtmlTag CreateEditorHelper(Attachment attachment) =>
|
306 | 306 |
|
307 | 307 | static HtmlTag CreateDelete(int pageId, string attachmentId, AntiforgeryTokenSet antiForgery)
|
308 | 308 | {
|
309 |
| - var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken); |
| 309 | + var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken!); |
310 | 310 | var id = Input.Hidden.Name("Id").Value(attachmentId.ToString());
|
311 | 311 | var name = Input.Hidden.Name("PageId").Value(pageId.ToString());
|
312 | 312 |
|
@@ -353,7 +353,7 @@ static string BuildForm(PageInput input, string path, AntiforgeryTokenSet antiFo
|
353 | 353 | {
|
354 | 354 | bool IsFieldOK(string key) => modelState!.ContainsKey(key) && modelState[key]!.ValidationState == ModelValidationState.Invalid;
|
355 | 355 |
|
356 |
| - var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken); |
| 356 | + var antiForgeryField = Input.Hidden.Name(antiForgery.FormFieldName).Value(antiForgery.RequestToken!); |
357 | 357 |
|
358 | 358 | var nameField = Div
|
359 | 359 | .Append(Label.Class("uk-form-label").Append(nameof(input.Name)))
|
@@ -405,9 +405,9 @@ static string BuildForm(PageInput input, string path, AntiforgeryTokenSet antiFo
|
405 | 405 | .Append(contentField)
|
406 | 406 | .Append(attachmentField);
|
407 | 407 |
|
408 |
| - if (input.Id.HasValue) |
| 408 | + if (input.Id is object) |
409 | 409 | {
|
410 |
| - HtmlTag id = Input.Hidden.Name("Id").Value(input.Id.ToString()); |
| 410 | + HtmlTag id = Input.Hidden.Name("Id").Value(input.Id.ToString()!); |
411 | 411 | form = form.Append(id);
|
412 | 412 | }
|
413 | 413 |
|
@@ -443,71 +443,73 @@ function copyMarkdownLink(element) {
|
443 | 443 | };
|
444 | 444 |
|
445 | 445 | (Template head, Template body, Template layout) _templates = (
|
446 |
| - head: Scriban.Template.Parse(@" |
447 |
| - <meta charset=""utf-8""> |
448 |
| - <meta name=""viewport"" content=""width=device-width, initial-scale=1""> |
449 |
| - <title>{{ title }}</title> |
450 |
| - <link rel=""stylesheet"" href=""https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css"" /> |
451 |
| - {{ header }} |
452 |
| - <style> |
453 |
| - .last-modified { font-size: small; } |
454 |
| - a:visited { color: blue; } |
455 |
| - a:link { color: red; } |
456 |
| - </style> |
457 |
| - "), |
458 |
| - body: Scriban.Template.Parse(@" |
459 |
| - <nav class=""uk-navbar-container""> |
460 |
| - <div class=""uk-container""> |
461 |
| - <div class=""uk-navbar""> |
462 |
| - <div class=""uk-navbar-left""> |
463 |
| - <ul class=""uk-navbar-nav""> |
464 |
| - <li class=""uk-active""><a href=""/""><span uk-icon=""home""></span></a></li> |
465 |
| - </ul> |
466 |
| - </div> |
467 |
| - <div class=""uk-navbar-center""> |
468 |
| - <div class=""uk-navbar-item""> |
469 |
| - <form action=""/new-page""> |
470 |
| - <input class=""uk-input uk-form-width-large"" type=""text"" name=""pageName"" placeholder=""Type desired page title here""></input> |
471 |
| - <input type=""submit"" class=""uk-button uk-button-default"" value=""Add New Page""> |
472 |
| - </form> |
473 |
| - </div> |
474 |
| - </div> |
475 |
| - </div> |
476 |
| - </div> |
477 |
| - </nav> |
478 |
| - {{ if at_side_panel != """" }} |
479 |
| - <div class=""uk-container""> |
480 |
| - <div uk-grid> |
481 |
| - <div class=""uk-width-4-5""> |
482 |
| - <h1>{{ page_name }}</h1> |
483 |
| - {{ content }} |
484 |
| - </div> |
485 |
| - <div class=""uk-width-1-5""> |
486 |
| - {{ at_side_panel }} |
487 |
| - </div> |
488 |
| - </div> |
489 |
| - </div> |
490 |
| - {{ else }} |
491 |
| - <div class=""uk-container""> |
492 |
| - <h1>{{ page_name }}</h1> |
493 |
| - {{ content }} |
494 |
| - </div> |
495 |
| - {{ end }} |
496 |
| - |
497 |
| - <script src=""https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js""></script> |
498 |
| - <script src=""https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js""></script> |
499 |
| - {{ at_foot }} |
500 |
| - "), |
501 |
| - layout: Scriban.Template.Parse(@" |
502 |
| - <!DOCTYPE html> |
503 |
| - <head> |
504 |
| - {{ head }} |
505 |
| - </head> |
506 |
| - <body> |
507 |
| - {{ body }} |
508 |
| - </body> |
509 |
| - </html> |
510 |
| - ") |
| 446 | + head: Scriban.Template.Parse( |
| 447 | + """ |
| 448 | + <meta charset="utf-8"> |
| 449 | + <meta name="viewport" content="width=device-width, initial-scale=1"> |
| 450 | + <title>{{ title }}</title> |
| 451 | + <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/uikit.min.css" /> |
| 452 | + {{ header }} |
| 453 | + <style> |
| 454 | + .last-modified { font-size: small; } |
| 455 | + a:visited { color: blue; } |
| 456 | + a:link { color: red; } |
| 457 | + </style> |
| 458 | + """), |
| 459 | + body: Scriban.Template.Parse(""" |
| 460 | + <nav class="uk-navbar-container"> |
| 461 | + <div class="uk-container"> |
| 462 | + <div class="uk-navbar"> |
| 463 | + <div class="uk-navbar-left"> |
| 464 | + <ul class="uk-navbar-nav"> |
| 465 | + <li class="uk-active"><a href="/"><span uk-icon="home"></span></a></li> |
| 466 | + </ul> |
| 467 | + </div> |
| 468 | + <div class="uk-navbar-center"> |
| 469 | + <div class="uk-navbar-item"> |
| 470 | + <form action="/new-page"> |
| 471 | + <input class="uk-input uk-form-width-large" type="text" name="pageName" placeholder="Type desired page title here"></input> |
| 472 | + <input type="submit" class="uk-button uk-button-default" value="Add New Page"> |
| 473 | + </form> |
| 474 | + </div> |
| 475 | + </div> |
| 476 | + </div> |
| 477 | + </div> |
| 478 | + </nav> |
| 479 | + {{ if at_side_panel != "" }} |
| 480 | + <div class="uk-container"> |
| 481 | + <div uk-grid> |
| 482 | + <div class="uk-width-4-5"> |
| 483 | + <h1>{{ page_name }}</h1> |
| 484 | + {{ content }} |
| 485 | + </div> |
| 486 | + <div class="uk-width-1-5"> |
| 487 | + {{ at_side_panel }} |
| 488 | + </div> |
| 489 | + </div> |
| 490 | + </div> |
| 491 | + {{ else }} |
| 492 | + <div class="uk-container"> |
| 493 | + <h1>{{ page_name }}</h1> |
| 494 | + {{ content }} |
| 495 | + </div> |
| 496 | + {{ end }} |
| 497 | + |
| 498 | + <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit.min.js"></script> |
| 499 | + <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/uikit-icons.min.js"></script> |
| 500 | + {{ at_foot }} |
| 501 | + |
| 502 | + """), |
| 503 | + layout: Scriban.Template.Parse(""" |
| 504 | + <!DOCTYPE html> |
| 505 | + <head> |
| 506 | + {{ head }} |
| 507 | + </head> |
| 508 | + <body> |
| 509 | + {{ body }} |
| 510 | + </body> |
| 511 | + </html> |
| 512 | + """) |
511 | 513 | );
|
512 | 514 |
|
513 | 515 | // Use only when the page requires editor
|
@@ -793,7 +795,7 @@ public static PageInput From(IFormCollection form)
|
793 | 795 |
|
794 | 796 | IFormFile? file = form.Files["Attachment"];
|
795 | 797 |
|
796 |
| - return new PageInput(pageId, name, content, file); |
| 798 | + return new PageInput(pageId, name!, content!, file); |
797 | 799 | }
|
798 | 800 | }
|
799 | 801 |
|
|
0 commit comments