Add <first tag[...]>

This commit is contained in:
Jo-Be-Co
2026-04-03 03:41:01 +02:00
parent a9cb560f95
commit 3e3da2298e
5 changed files with 17 additions and 7 deletions

View File

@@ -45,4 +45,5 @@ public class LibraryBookDto : BookDto
public string? Account { get; set; }
public string? AccountNickname { get; set; }
public IEnumerable<StringDto>? Tags { get; set; }
public string? FirstTag => Tags?.FirstOrDefault()?.Value;
}

View File

@@ -44,6 +44,7 @@ public sealed class TemplateTags : ITemplateTag
public static TemplateTags Account { get; } = new("account", "Audible account of this book");
public static TemplateTags AccountNickname { get; } = new("account nickname", "Audible account nickname of this book");
public static TemplateTags Tag { get; } = new("tag", "Tag(s)");
public static TemplateTags FirstTag { get; } = new("first tag", "First tag");
public static TemplateTags Locale { get; } = new("locale", "Region/country");
public static TemplateTags YearPublished { get; } = new("year", "Year published");
public static TemplateTags Language { get; } = new("language", "Book's language");

View File

@@ -289,6 +289,7 @@ public abstract class Templates
{ TemplateTags.DateAdded, lb => lb.DateAdded },
{ TemplateTags.FileDate, lb => lb.FileDate },
{ TemplateTags.Tag, lb => lb.Tags, StringListFormat.Formatter, StringListFormat.Finalizer },
{ TemplateTags.FirstTag, lb => lb.FirstTag },
};
private static readonly PropertyTagCollection<LibraryBookDto> audioFilePropertyTags =

View File

@@ -524,6 +524,9 @@ namespace TemplatesTests
[DataRow("<has file date->true<-has>", "true")]
[DataRow("<has pub date->true<-has>", "true")]
[DataRow("<has date added->true<-has>", "true")]
[DataRow("<has tag->true<-has>", "true")]
[DataRow("<has first tag->true<-has>", "true")]
[DataRow("<!has first tag->false<-has>", "")]
[DataRow("<has ch count->true<-has>", "true")]
[DataRow("<has ch title->true<-has>", "true")]
[DataRow("<has ch#->true<-has>", "true")]
@@ -719,9 +722,9 @@ namespace TemplatesTests
[DataRow("<audibletitle [u]>", "İ", "tr-TR", "i")]
[DataRow(@"<minutes[D,DDD.DDE-0\-H,HHH.HH\-#,##M.##]>", "8.573,30E1-0.021,00-9", "es-ES", "any")]
[DataRow(@"<minutes[D,DDD.DDE-0\-H,HHH.HH\-#,##M.##]>", "8,573.30E1-0,021.00-9", "en-AU", "any")]
[DataRow(@"<samplerate[#,##0'Hz ']>", "44,100Hz ", "en-CA", "any")]
[DataRow(@"<samplerate[#,##0'Hz ']>", "44100Hz ", "de-CH", "any")]
[DataRow(@"<samplerate[#,##0'Hz ']>", "44\u00A0100Hz ", "fr-CA", "any")] // non-breaking-space
[DataRow("<samplerate[#,##0'Hz ']>", "44,100Hz ", "en-CA", "any")]
[DataRow("<samplerate[#,##0'Hz ']>", "44100Hz ", "de-CH", "any")]
[DataRow("<samplerate[#,##0'Hz ']>", "44\u00A0100Hz ", "fr-CA", "any")] // non-breaking-space
public void Tag_culture_test(string template, string expected, string cultureName, string title)
{
var bookDto = Shared.GetLibraryBook();
@@ -740,11 +743,14 @@ namespace TemplatesTests
[DataRow("<tag>", "Tag1, Tag2, Tag3")]
[DataRow("<tag [separator( - )]>", "Tag1 - Tag2 - Tag3")]
[DataRow("<tag [format({S:u})]>", "TAG1, TAG2, TAG3")]
[DataRow("<tag [format({S:l})]>", "tag1, tag2, tag3")]
[DataRow("<tag [format(Tag: {S})]>", "Tag: Tag1, Tag: Tag2, Tag: Tag3")]
[DataRow("<tag[format({S:l})]>", "tag1, tag2, tag3")]
[DataRow("<tag[format(Tag: {S})]>", "Tag: Tag1, Tag: Tag2, Tag: Tag3")]
[DataRow("<tag [max(1)]>", "Tag1")]
[DataRow("<tag [slice(2..)]>", "Tag2, Tag3")]
[DataRow("<tag [sort(s)]>", "Tag3, Tag2, Tag1")]
[DataRow("<tag[sort(s)]>", "Tag3, Tag2, Tag1")]
[DataRow("<first tag>", "Tag1")]
[DataRow("<first tag[]>", "Tag1")]
[DataRow("<first tag[l]>", "tag1")]
public void Tag_test(string template, string expected)
{
var bookDto = Shared.GetLibraryBook();

View File

@@ -36,6 +36,7 @@ These tags will be replaced in the template with the audiobook's values.
| \<account\> | Audible account of this book | [Text](#text-formatters) |
| \<account nickname\> | Audible account nickname of this book | [Text](#text-formatters) |
| \<tag\> | Tag(s) | [Text List](#text-list-formatters) |
| \<first tag\> | First tag | [Text](#text-formatters) |
| \<locale\> | Region/country | [Text](#text-formatters) |
| \<year\> | Year published | [Number](#number-formatters) |
| \<language\> | Book's language | [Text](#text-formatters) |
@@ -178,7 +179,7 @@ For more custom formatters and examples, [see this guide from Microsoft](https:/
| \\ | The escape character. | \<minutes[d\\d h\\h m\\m]\> | 2d 14h 42m |
These formatters have been enhanced to allow the display of days, hours or months beyond their usual limits. For example, the total number of hours, even if it exceeds 23.
Here, a number format is inserted for the desired part in accordance with [Microsofts instructions](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings). Im Unterschied zu den originären Zahlenformaten werden aber anstelle der Nullen die Buchstaben D, H oder M (Großbuchstaben) verwendet.
Here, a number format is inserted for the desired part in accordance with [Microsofts instructions](https://learn.microsoft.com/en-us/dotnet/standard/base-types/custom-numeric-format-strings). Unlike standard number formats, however, the letters D, H or M (uppercase) are used instead of zeros.
| Formatter | Description | Example Usage | Example Result |
|-----------|-----------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------|-------------------|