Automatically create shortlinks for your Astro site

feat: multi shortlinker

ovyerus.com 159a485f c103f38b

verified
+31
+31
src/multi-shortlinker.ts
··· 1 + import type { Shortlinker } from "./types.js"; 2 + 3 + export const multiShortlinker = (shortlinkers: Shortlinker[]): Shortlinker => { 4 + return { 5 + name: "multi-shortlinker", 6 + async run(mappings, logger) { 7 + logger.info(`Creating shortlinks on ${shortlinkers.length} services`); 8 + 9 + for (const shortlinker of shortlinkers) { 10 + logger.info(`Running ${shortlinker.name}`); 11 + const shortlinkerLogger = logger.fork( 12 + `astro-shortlinks/${shortlinker.name}` 13 + ); 14 + 15 + try { 16 + const succeeded = await shortlinker.run(mappings, shortlinkerLogger); 17 + 18 + if (succeeded !== false) { 19 + logger.info( 20 + `Successfully created shortlinks with ${shortlinker.name}` 21 + ); 22 + } 23 + } catch (err) { 24 + logger.error( 25 + `Error while creating shortlinks with ${shortlinker.name}: ${err}` 26 + ); 27 + } 28 + } 29 + }, 30 + }; 31 + };