/** @type {import('next').NextConfig} */

// Allow next/image to load Ghost feature images from the configured CMS host.
const ghostHost = (() => {
  try {
    return process.env.GHOST_URL ? new URL(process.env.GHOST_URL).hostname : null;
  } catch {
    return null;
  }
})();

const nextConfig = {
  images: {
    remotePatterns: [
      { protocol: "https", hostname: "images.unsplash.com" },
      // Ghost may serve feature images over either http or https, so allow both.
      ...(ghostHost
        ? [
            { protocol: "https", hostname: ghostHost },
            { protocol: "http", hostname: ghostHost },
          ]
        : []),
    ],
  },
};

export default nextConfig;
