View Single Post
Old 05-08-2023, 12:36 PM   #621
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,510
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
This template seems to do what you want and will be faster because only one line of one switch_if() is executed. It works by concatenating generated URLs in the order according to the publisher. If the publisher isn't one of interest then it generates 'a03' first. Missing identifiers are ignored.

Another important point: list_join() strips out empty list values, so there isn't a problem with build_url() generating a trailing comma.

Code:
program:
	def build_url(id):
		return identifier_in_list($identifiers, id, 
				urls_from_identifiers(id & ':' & select($identifiers, id), 1) & ',', '')
	fed;

	list_join(
		 ', ',

## trimmed out other lines for length

		switch_if(
			$publisher=='Archive of Our Own', build_url('ao3') & build_url('ffnet'),
			$publisher=='FanFiction.net', build_url('ffnet') & build_url('ao3'),
			build_url('ao3') & build_url('ffnet')
		), ',',
	)
chaley is offline   Reply With Quote