View Single Post
Old 06-04-2023, 07:14 AM   #632
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,052
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by chaley View Post
It is hard to understand what you are trying to do. What you say the code does and what the code actually does are different.

Reading what you say and the code, it appears that:
  • if a tag contains the item "Cultures & Regions" then you want the last item.
  • otherwise you want all items split into individual tags.
However, the examples don't agree with this. Your code will include both the "Fiction" and "Historical Fiction" of "Fiction.Historical Fiction" while your example output does not. Which is right?
That's because I left out part of the template and forgot to account for it in the examples.

Code:
program:

	if 
		'^(Fiction|Nonfiction|Magazines & Publications)' in $#booktype 
	then 
## Remove 'Culture & Regions' items as they're processed differently
		split_tags = list_re_group($tags, ',', '.', '(^.*Cultures & Regions.*$)', '');
## Split tags or return an empty
		split_tags = re(split_tags, '\.', ',') 
	else
		split_tags = ''
	fi;

## Cultures & Regions - list_item with a '.' separator to get the lastmost item
	cultures_tags = list_re($tags, ',', 'Cultures & Regions', '');
	cultures_tags = list_item(cultures_tags, -1, '.');
## Re-merge this with split_tags
	split_tags = list_union(split_tags, cultures_tags, ',');

## Removing a few unwanteds and sorting
	cleaned_tags = list_sort(list_difference(
		split_tags,
		'[Cleanup], Fiction, Nonfiction, Magazines & Publications, Topics',
		','), 0, ',');

## Add 'Omnibus' if applicable
	if 
		'omnibus' 
	in 
		$#admintags 
	then 
		cleaned_tags  = 'Omnibus' & if cleaned_tags then ', ' & cleaned_tags fi
	fi;

	cleaned_tags
ownedbycats is offline   Reply With Quote