Improve the templates a bit

pull/66/head
Alexey Golub 7 years ago
parent 4fbec95208
commit 25207c5093

@ -2,208 +2,214 @@
<html lang="en"> <html lang="en">
<head> <head>
<title>{{ Guild.Name | HtmlEncode }} - {{ Channel.Name | HtmlEncode }}</title> <title>{{ Guild.Name | html.escape }} - {{ Channel.Name | html.escape }}</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<style>{{ StyleSheet }}</style> <style>
{{ StyleSheet }}
</style>
</head> </head>
<body> <body>
{{~ # Info }} {{~ # Info ~}}
<div class="info"> <div class="info">
<div class="info__guild-icon-container"> <div class="info__guild-icon-container">
<img class="info__guild-icon" src="{{ Guild.IconUrl }}" /> <img class="info__guild-icon" src="{{ Guild.IconUrl }}" />
</div> </div>
<div class="info__metadata"> <div class="info__metadata">
<div class="info__guild-name">{{ Guild.Name | HtmlEncode }}</div> <div class="info__guild-name">{{ Guild.Name | html.escape }}</div>
<div class="info__channel-name">{{ Channel.Name | HtmlEncode }}</div> <div class="info__channel-name">{{ Channel.Name | html.escape }}</div>
{{ if Channel.Topic }} {{~ if Channel.Topic ~}}
<div class="info__channel-topic">{{ Channel.Topic | HtmlEncode }}</div> <div class="info__channel-topic">{{ Channel.Topic | html.escape }}</div>
{{ end }} {{~ end ~}}
<div class="info__channel-message-count">{{ TotalMessageCount | Format "N0" }} messages</div> <div class="info__channel-message-count">{{ TotalMessageCount | Format "N0" }} messages</div>
{{ if From || To }} {{~ if From || To ~}}
<div class="info__channel-date-range"> <div class="info__channel-date-range">
{{ if From && To }} {{~ if From && To ~}}
Between {{ From | FormatDate | HtmlEncode }} and {{ To | FormatDate | HtmlEncode }} Between {{ From | FormatDate | html.escape }} and {{ To | FormatDate | html.escape }}
{{ else if From }} {{~ else if From ~}}
After {{ From | FormatDate | HtmlEncode }} After {{ From | FormatDate | html.escape }}
{{ else if To }} {{~ else if To ~}}
Before {{ To | FormatDate | HtmlEncode }} Before {{ To | FormatDate | html.escape }}
{{ end }} {{~ end ~}}
</div> </div>
{{ end }} {{~ end ~}}
</div> </div>
</div> </div>
{{~ # Log }} {{~ # Log ~}}
<div class="chatlog"> <div class="chatlog">
{{ for group in MessageGroups }} {{~ for group in MessageGroups ~}}
<div class="chatlog__message-group"> <div class="chatlog__message-group">
{{~ # Avatar }} {{~ # Avatar ~}}
<div class="chatlog__author-avatar-container"> <div class="chatlog__author-avatar-container">
<img class="chatlog__author-avatar" src="{{ group.Author.AvatarUrl }}" /> <img class="chatlog__author-avatar" src="{{ group.Author.AvatarUrl }}" />
</div> </div>
<div class="chatlog__messages"> <div class="chatlog__messages">
{{~ # Author name and timestamp }} {{~ # Author name and timestamp ~}}
<span class="chatlog__author-name" title="{{ group.Author.FullName | HtmlEncode }}">{{ group.Author.Name | HtmlEncode }}</span> <span class="chatlog__author-name" title="{{ group.Author.FullName | html.escape }}">{{ group.Author.Name | html.escape }}</span>
<span class="chatlog__timestamp">{{ group.Timestamp | FormatDate | HtmlEncode }}</span> <span class="chatlog__timestamp">{{ group.Timestamp | FormatDate | html.escape }}</span>
{{~ # Messages }} {{~ # Messages ~}}
{{ for message in group.Messages }} {{~ for message in group.Messages ~}}
{{~ # Content }} {{~ # Content ~}}
{{ if message.Content }} {{~ if message.Content ~}}
<div class="chatlog__content"> <div class="chatlog__content">
{{ message.Content | FormatContent }} {{ message.Content | FormatContent }}
{{~ # Edited timestamp }} {{~ # Edited timestamp ~}}
{{ if message.EditedTimestamp }} {{~ if message.EditedTimestamp ~}}
<span class="chatlog__edited-timestamp" title="{{ message.EditedTimestamp | FormatDate | HtmlEncode }}">(edited)</span> <span class="chatlog__edited-timestamp" title="{{ message.EditedTimestamp | FormatDate | html.escape }}">(edited)</span>
{{ end }} {{~ end ~}}
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Attachments }} {{~ # Attachments ~}}
{{ for attachment in message.Attachments }} {{~ for attachment in message.Attachments ~}}
<div class="chatlog__attachment"> <div class="chatlog__attachment">
<a href="{{ attachment.Url }}"> <a href="{{ attachment.Url }}">
{{~ # Image }} {{ # Image }}
{{ if attachment.IsImage }} {{~ if attachment.IsImage ~}}
<img class="chatlog__attachment-thumbnail" src="{{ attachment.Url }}" /> <img class="chatlog__attachment-thumbnail" src="{{ attachment.Url }}" />
{{~ # Non-image }} {{~ # Non-image ~}}
{{ else }} {{~ else ~}}
Attachment: {{ attachment.FileName }} ({{ attachment.FileSize | FormatFileSize }}) Attachment: {{ attachment.FileName }} ({{ attachment.FileSize | FormatFileSize }})
{{ end }} {{~ end ~}}
</a> </a>
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Embeds }} {{~ # Embeds ~}}
{{ for embed in message.Embeds }} {{~ for embed in message.Embeds ~}}
<div class="chatlog__embed"> <div class="chatlog__embed">
<div class="chatlog__embed-color-pill" style="background-color: rgba({{ embed.Color | FormatColor }})"></div> <div class="chatlog__embed-color-pill" style="background-color: rgba({{ embed.Color | FormatColor }})"></div>
<div class="chatlog__embed-content-container"> <div class="chatlog__embed-content-container">
<div class="chatlog__embed-content"> <div class="chatlog__embed-content">
<div class="chatlog__embed-text"> <div class="chatlog__embed-text">
{{~ # Author }} {{~ # Author ~}}
{{ if embed.Author }} {{~ if embed.Author ~}}
<div class="chatlog__embed-author"> <div class="chatlog__embed-author">
{{ if embed.Author.IconUrl }} {{~ if embed.Author.IconUrl ~}}
<img class="chatlog__embed-author-icon" src="{{ embed.Author.IconUrl }}" /> <img class="chatlog__embed-author-icon" src="{{ embed.Author.IconUrl }}" />
{{ end }} {{~ end ~}}
{{ if embed.Author.Name }} {{~ if embed.Author.Name ~}}
<span class="chatlog__embed-author-name"> <span class="chatlog__embed-author-name">
{{ if embed.Author.Url }} {{~ if embed.Author.Url ~}}
<a class="chatlog__embed-author-name-link" href="{{ embed.Author.Url }}">{{ embed.Author.Name | HtmlEncode }}</a> <a class="chatlog__embed-author-name-link" href="{{ embed.Author.Url }}">{{ embed.Author.Name | html.escape }}</a>
{{ else }} {{~ else ~}}
{{ embed.Author.Name | HtmlEncode }} {{ embed.Author.Name | html.escape }}
{{ end }} {{~ end ~}}
</span> </span>
{{ end }} {{~ end ~}}
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Title }} {{~ # Title ~}}
{{ if embed.Title }} {{~ if embed.Title ~}}
<div class="chatlog__embed-title"> <div class="chatlog__embed-title">
{{ if embed.Url }} {{~ if embed.Url ~}}
<a class="chatlog__embed-title-link" href="{{ embed.Url }}">{{ embed.Title | FormatContent }}</a> <a class="chatlog__embed-title-link" href="{{ embed.Url }}">{{ embed.Title | FormatContent }}</a>
{{ else }} {{~ else ~}}
{{ embed.Title | FormatContent }} {{ embed.Title | FormatContent }}
{{ end }} {{~ end ~}}
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Description }} {{~ # Description ~}}
{{ if embed.Description }} {{~ if embed.Description ~}}
<div class="chatlog__embed-description">{{ embed.Description | FormatContent true }}</div> <div class="chatlog__embed-description">{{ embed.Description | FormatContent true }}</div>
{{ end }} {{~ end ~}}
{{~ # Fields }} {{~ # Fields ~}}
<div class="chatlog__embed-fields"> {{~ if embed.Fields | array.size > 0 ~}}
{{ for field in embed.Fields }} <div class="chatlog__embed-fields">
<div class="chatlog__embed-field {{ if field.IsInline }} chatlog__embed-field--inline {{ end }}"> {{~ for field in embed.Fields ~}}
{{ if field.Name }} <div class="chatlog__embed-field {{ if field.IsInline }} chatlog__embed-field--inline {{ end }}">
<div class="chatlog__embed-field-name">{{ field.Name | FormatContent }}</div> {{~ if field.Name ~}}
{{ end }} <div class="chatlog__embed-field-name">{{ field.Name | FormatContent }}</div>
{{ if field.Value }} {{~ end ~}}
<div class="chatlog__embed-field-value">{{ field.Value | FormatContent true }}</div> {{~ if field.Value ~}}
{{ end }} <div class="chatlog__embed-field-value">{{ field.Value | FormatContent true }}</div>
</div> {{~ end ~}}
{{ end }} </div>
</div> {{~ end ~}}
</div>
{{~ end ~}}
</div> </div>
{{~ # Thumbnail }} {{~ # Thumbnail ~}}
{{ if embed.Thumbnail }} {{~ if embed.Thumbnail ~}}
<div class="chatlog__embed-thumbnail-container"> <div class="chatlog__embed-thumbnail-container">
<a class="chatlog__embed-thumbnail-link" href="{{ embed.Thumbnail.Url }}"> <a class="chatlog__embed-thumbnail-link" href="{{ embed.Thumbnail.Url }}">
<img class="chatlog__embed-thumbnail" src="{{ embed.Thumbnail.Url }}" /> <img class="chatlog__embed-thumbnail" src="{{ embed.Thumbnail.Url }}" />
</a> </a>
</div> </div>
{{ end }} {{~ end ~}}
</div> </div>
{{~ # Image }} {{~ # Image ~}}
{{ if embed.Image }} {{~ if embed.Image ~}}
<div class="chatlog__embed-image-container"> <div class="chatlog__embed-image-container">
<a class="chatlog__embed-image-link" href="{{ embed.Image.Url }}"> <a class="chatlog__embed-image-link" href="{{ embed.Image.Url }}">
<img class="chatlog__embed-image" src="{{ embed.Image.Url }}" /> <img class="chatlog__embed-image" src="{{ embed.Image.Url }}" />
</a> </a>
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Footer }} {{~ # Footer ~}}
{{ if embed.Footer || embed.Timestamp }} {{~ if embed.Footer || embed.Timestamp ~}}
<div class="chatlog__embed-footer"> <div class="chatlog__embed-footer">
{{ if embed.Footer }} {{~ if embed.Footer ~}}
{{ if embed.Footer.Text && embed.Footer.IconUrl }} {{~ if embed.Footer.Text && embed.Footer.IconUrl ~}}
<img class="chatlog__embed-footer-icon" src="{{ embed.Footer.IconUrl }}" /> <img class="chatlog__embed-footer-icon" src="{{ embed.Footer.IconUrl }}" />
{{ end }} {{~ end ~}}
{{ end }} {{~ end ~}}
<span class="chatlog__embed-footer-text"> <span class="chatlog__embed-footer-text">
{{ if embed.Footer }} {{~ if embed.Footer ~}}
{{ if embed.Footer.Text }} {{~ if embed.Footer.Text ~}}
{{ embed.Footer.Text | HtmlEncode }} {{ embed.Footer.Text | html.escape }}
{{ if embed.Timestamp }} • {{ end }} {{ if embed.Timestamp }} • {{ end }}
{{ end }} {{~ end ~}}
{{ end }} {{~ end ~}}
{{ if embed.Timestamp }} {{~ if embed.Timestamp ~}}
{{ embed.Timestamp | FormatDate | HtmlEncode }} {{ embed.Timestamp | FormatDate | html.escape }}
{{ end }} {{~ end ~}}
</span> </span>
</div> </div>
{{ end }} {{~ end ~}}
</div> </div>
</div> </div>
{{ end }} {{~ end ~}}
{{~ # Reactions }} {{~ # Reactions ~}}
<div class="chatlog__reactions"> {{~ if message.Reactions | array.size > 0 ~}}
{{ for reaction in message.Reactions }} <div class="chatlog__reactions">
<div class="chatlog__reaction"> {{~ for reaction in message.Reactions ~}}
<span class="chatlog__reaction-emoji"> <div class="chatlog__reaction">
{{~ # Custom emoji }} <span class="chatlog__reaction-emoji">
{{ if reaction.EmojiId }} {{~ # Custom emoji ~}}
<img class="emoji emoji--small" title="{{ reaction.EmojiName }}" src="https://cdn.discordapp.com/emojis/{{ reaction.EmojiId }}.png" /> {{~ if reaction.EmojiId ~}}
{{~ # Default emoji }} <img class="emoji emoji--small" title="{{ reaction.EmojiName }}" src="https://cdn.discordapp.com/emojis/{{ reaction.EmojiId }}.png" />
{{ else }} {{~ # Default emoji ~}}
{{ reaction.EmojiName }} {{~ else ~}}
{{ end }} {{ reaction.EmojiName }}
</span> {{~ end ~}}
<span class="chatlog__reaction-count">{{ reaction.Count }}</span> </span>
</div> <span class="chatlog__reaction-count">{{ reaction.Count }}</span>
{{ end }} </div>
</div> {{~ end ~}}
{{ end }} </div>
{{~ end ~}}
{{~ end ~}}
</div> </div>
</div> </div>
{{ end }} {{~ end ~}}
</div> </div>
</body> </body>

@ -1,4 +1,5 @@
============================================================== {{~ # Info ~}}
==============================================================
Guild: {{ Guild.Name }} Guild: {{ Guild.Name }}
Channel: {{ Channel.Name }} Channel: {{ Channel.Name }}
Topic: {{ Channel.Topic }} Topic: {{ Channel.Topic }}
@ -6,13 +7,19 @@ Messages: {{ TotalMessageCount | Format "N0" }}
Range: {{ if From }}{{ From | FormatDate }} {{ end }}{{ if From || To }}->{{ end }}{{ if To }} {{ To | FormatDate }}{{ end }} Range: {{ if From }}{{ From | FormatDate }} {{ end }}{{ if From || To }}->{{ end }}{{ if To }} {{ To | FormatDate }}{{ end }}
============================================================== ==============================================================
{{~ # Log ~}}
{{~ for group in MessageGroups ~}} {{~ for group in MessageGroups ~}}
{{~ group.Author.FullName }} [{{ group.Timestamp | FormatDate }}] {{~ # Author name and timestamp ~}}
{{~ }}[{{ group.Timestamp | FormatDate }}] {{ group.Author.FullName }}
{{~ # Messages ~}}
{{~ for message in group.Messages ~}} {{~ for message in group.Messages ~}}
{{~ # Content ~}}
{{~ message.Content | FormatContent }} {{~ message.Content | FormatContent }}
{{~ # Attachments ~}}
{{~ for attachment in message.Attachments ~}} {{~ for attachment in message.Attachments ~}}
{{~ attachment.Url }} {{~ attachment.Url }}
{{~ end ~}} {{~ end ~}}
{{~ end ~}} {{~ end ~}}
{{~ end ~}} {{~ end ~}}

@ -28,8 +28,6 @@ namespace DiscordChatExporter.Core.Services
private string HtmlEncode(string str) => WebUtility.HtmlEncode(str); private string HtmlEncode(string str) => WebUtility.HtmlEncode(str);
private string HtmlDecode(string str) => WebUtility.HtmlDecode(str);
private string Format(IFormattable obj, string format) => private string Format(IFormattable obj, string format) =>
obj.ToString(format, CultureInfo.InvariantCulture); obj.ToString(format, CultureInfo.InvariantCulture);
@ -312,8 +310,6 @@ namespace DiscordChatExporter.Core.Services
scriptObject.Import(_log, TemplateMemberFilter, TemplateMemberRenamer); scriptObject.Import(_log, TemplateMemberFilter, TemplateMemberRenamer);
// Import functions // Import functions
scriptObject.Import(nameof(HtmlEncode), new Func<string, string>(HtmlEncode));
scriptObject.Import(nameof(HtmlDecode), new Func<string, string>(HtmlDecode));
scriptObject.Import(nameof(Format), new Func<IFormattable, string, string>(Format)); scriptObject.Import(nameof(Format), new Func<IFormattable, string, string>(Format));
scriptObject.Import(nameof(FormatDate), new Func<DateTime, string>(FormatDate)); scriptObject.Import(nameof(FormatDate), new Func<DateTime, string>(FormatDate));
scriptObject.Import(nameof(FormatFileSize), new Func<long, string>(FormatFileSize)); scriptObject.Import(nameof(FormatFileSize), new Func<long, string>(FormatFileSize));

Loading…
Cancel
Save