import "../../dialect-helpers-DRI5pyY3.mjs";
import "../../after-B1IIdH3Y.mjs";
import "../../object-cache-Bok5j2ae.mjs";
import "../../base64-CmWvODNW.mjs";
import "../../types-CuW0zWDA.mjs";
import "../../media-BrXIaMFN.mjs";
import "../../options-DTTML-Tx.mjs";
import "../../request-cache-KCNHp_RJ.mjs";
import "../../loader-CB6YHeul.mjs";
import { a as getSiteSettingsWithDb } from "../../settings-zhmdKyJQ.mjs";
import { n as getPublicOrigin } from "../../public-url-Danv47cS.mjs";

//#region src/astro/routes/robots.txt.ts
const prerender = false;
const TRAILING_SLASH_RE = /\/$/;
const GET = async ({ locals, url }) => {
	const { emdash } = locals;
	if (!emdash?.db) return new Response("User-agent: *\nAllow: /\n", {
		status: 200,
		headers: { "Content-Type": "text/plain; charset=utf-8" }
	});
	try {
		const settings = await getSiteSettingsWithDb(emdash.db);
		const sitemapUrl = `${(settings.url || getPublicOrigin(url, emdash?.config)).replace(TRAILING_SLASH_RE, "")}/sitemap.xml`;
		if (settings.seo?.robotsTxt) {
			let content = settings.seo.robotsTxt;
			if (!content.toLowerCase().includes("sitemap:")) content = `${content.trimEnd()}\n\nSitemap: ${sitemapUrl}\n`;
			return new Response(content, {
				status: 200,
				headers: {
					"Content-Type": "text/plain; charset=utf-8",
					"Cache-Control": "public, max-age=86400"
				}
			});
		}
		const defaultRobots = [
			"User-agent: *",
			"Allow: /",
			"",
			"# Disallow admin and API routes",
			"Disallow: /_emdash/",
			"",
			`Sitemap: ${sitemapUrl}`,
			""
		].join("\n");
		return new Response(defaultRobots, {
			status: 200,
			headers: {
				"Content-Type": "text/plain; charset=utf-8",
				"Cache-Control": "public, max-age=86400"
			}
		});
	} catch {
		return new Response("User-agent: *\nAllow: /\n", {
			status: 200,
			headers: { "Content-Type": "text/plain; charset=utf-8" }
		});
	}
};

//#endregion
export { GET, prerender };
//# sourceMappingURL=robots.txt.mjs.map