program:
## Short ship — anthology-aware version
## ─────────────────────────────────────────
## Column settings:
##   Column heading : Cover ship tags
##   Lookup name    : short_ships
##   Column type    : Column built from other columns, behaves like tags
##
## Reads the saved #all_slashes list, removes repeated relationships,
## and uses the first two different ships for the cover.
##
## If an older fic has no #all_slashes value, tries #ship instead.
## Calibre may have alphabetised that older column.
##
## To add a ship: copy an elif block in both translation sections.
## Put specific relationships before overlapping shorter ones.

## Read the saved ship list, remove repeats, and take the first two.
ordered_unique = list_remove_duplicates(field('#all_slashes'), ',');
s0 = re(list_item(ordered_unique, 0, ','), '^\s+|\s+$', '');
s1 = re(list_item(ordered_unique, 1, ','), '^\s+|\s+$', '');
result = '';

## ── For older fics without an #all_slashes value ──────────────────
if !s0 && !s1 then
    ships_raw = field('#ship');
    if contains(ships_raw, '/', '1', '') then
        fallback = re(ships_raw, '^(?:[^/,]+,\s*)*([^,]+/[^,]+)(?:,.*)?$', '\1');
        if contains(fallback, '/', '1', '') && !contains(fallback, ',', '1', '') then
            s0 = fallback
        fi
    fi
fi;

## ── Translate first ship ───────────────────────────────────────────
t1 = '';
if s0 then
    s1_lc = lowercase(s0);
    if contains(s1_lc, 'sherlock holmes/john watson|john/sherlock|sherlock/john', '1', '') then
        t1 = 'Johnlock'
    elif contains(s1_lc, 'shane hollander/ilya rozanov', '1', '') then
        t1 = 'Hollanov'
    ## Add your ships above this line.
    else
        t1 = re(s0, '(?i)([^/]+)/([^/]+)', '\1/\2')
    fi
fi;

## ── Translate second ship ──────────────────────────────────────────
t2 = '';
if s1 then
    s2_lc = lowercase(s1);
    if contains(s2_lc, 'sherlock holmes/john watson|john/sherlock|sherlock/john', '1', '') then
        t2 = 'Johnlock'
    elif contains(s2_lc, 'shane hollander/ilya rozanov', '1', '') then
        t2 = 'Hollanov'
    ## Add your ships above this line.
    else
        t2 = re(s1, '(?i)([^/]+)/([^/]+)', '\1/\2')
    fi
fi;

## ── Put the names together without showing one twice ──────────────
if t1 then result = t1 fi;
if t2 then
    if !result then
        result = t2
    elif lowercase(t2) != lowercase(result) then
        result = result & ', ' & t2
    fi
fi;

if !result then return 'Gen' else return result fi
